Class Tracker<T>
java.lang.Object
ru.vyarus.dropwizard.guice.test.track.Tracker<T>
- Type Parameters:
T- bean type
Tracker object used for bean calls registration (together with
TrackBean or
TrackersHook).
Use metrics timer to aggregate method calls statistics. Use getStats() for report building.
Tracked methods filtering implemented with mockito: findTracks(java.util.function.Function).
By default, recorded tracks cleared after each test.
- Since:
- 11.02.2025
-
Constructor Summary
ConstructorsConstructorDescriptionTracker(Class<T> type, TrackerConfig config, com.codahale.metrics.MetricRegistry metrics) Create tracker. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Cleanup recorded tracks.findTracks(Function<T, org.mockito.stubbing.OngoingStubbing<?>> where) Tracked methods filtering using mockito.getLastTracks(int count) Returns last (count) tracks in execution order.getStats()NOTE: This is just an example usage - you can create a stats object with filtered methods (or with methods from multiple trackers).Tracks sorted by start time.getType()booleanisEmpty()intsize()
-
Constructor Details
-
Tracker
Create tracker.- Parameters:
type- service typeconfig- configmetrics- metrics
-
-
Method Details
-
getType
- Returns:
- type of tracked bean
-
isEmpty
public boolean isEmpty()- Returns:
- true if no method calls registered, false otherwise
-
size
public int size()- Returns:
- count of tracked methods
-
getTracks
Tracks sorted by start time.- Returns:
- all tracked method calls
-
getLastTrack
- Returns:
- last tracked method call
- Throws:
IllegalStateException- if no calls tracked (error thrown to simplify usage - no additional checks required in test)
-
getLastTracks
Returns last (count) tracks in execution order.- Parameters:
count- last tracks count- Returns:
- last tracks (count)
- Throws:
IllegalStateException- if there is not enough recorded tracks
-
getStats
NOTE: This is just an example usage - you can create a stats object with filtered methods (or with methods from multiple trackers).- Returns:
- stats for all tracked methods (for reporting)
-
findTracks
Tracked methods filtering using mockito. Useful because mockito provides type-safe syntax. For example, search by method:find(mock -> when(mock.something()). Search by method with exact argument == 1:find(mock -> when(mock.something(intThat(argument -> argument == 1))).- Parameters:
where- search condition definition- Returns:
- list of matched tracks
-
clear
public void clear()Cleanup recorded tracks. By default, called automatically after each test method.
-