Class Tracker<T>

java.lang.Object
ru.vyarus.dropwizard.guice.test.track.Tracker<T>
Type Parameters:
T - bean type

public class Tracker<T> extends Object
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 Details

    • Tracker

      public Tracker(Class<T> type, TrackerConfig config, com.codahale.metrics.MetricRegistry metrics)
      Create tracker.
      Parameters:
      type - service type
      config - config
      metrics - metrics
  • Method Details

    • getType

      public Class<T> 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

      public List<MethodTrack> getTracks()
      Tracks sorted by start time.
      Returns:
      all tracked method calls
    • getLastTrack

      public MethodTrack getLastTrack()
      Returns:
      last tracked method call
      Throws:
      IllegalStateException - if no calls tracked (error thrown to simplify usage - no additional checks required in test)
    • getLastTracks

      public List<MethodTrack> getLastTracks(int count)
      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

      public TrackerStats 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

      public List<MethodTrack> findTracks(Function<T,org.mockito.stubbing.OngoingStubbing<?>> where)
      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.