Class DatesTestHelper

java.lang.Object
com.persequor.saga.componenttest.DatesTestHelper

public class DatesTestHelper extends Object
Setup like this:
 
 @Mock
 Dates dates;
 DatesTestHelper datesTestHelper;

 @Before
 public void before() {
     datesTestHelper = new DatesTestHelper(dates);
 }
  
Then use like this:
 
 datesTestHelper.setNow(Instant.now().minus(5, ChronoUnit.DAYS));
 ... do something ...
 datesTestHelper.setOffset(Duration.ofMinutes(43));
 ... do something ...
 datesTestHelper.addToOffset(Duration.ofMinutes(5));
 ... etc ...
  
  • Field Details

    • realDates

      protected final Dates realDates
    • nowOverride

      protected Instant nowOverride
    • offset

      protected Duration offset
    • step

      protected Duration step
  • Constructor Details

    • DatesTestHelper

      public DatesTestHelper(Dates mockDates)
      Parameters:
      mockDates - the mock of the Dates class that will be manipulated
  • Method Details

    • setNow

      public void setNow(Instant newNow)
      Parameters:
      newNow - all "now" methods will return this value (possibly truncated)
    • setOffset

      public void setOffset(Duration offsetFromRealNow)
      Parameters:
      offsetFromRealNow - all "now" methods will return the real now plus this offset
    • addToOffset

      public void addToOffset(Duration changeOfOffsetFromRealNow)
      Parameters:
      changeOfOffsetFromRealNow - all "now" methods will return the real now plus an offset that is incremented by this amount
    • setStep

      public void setStep(Duration step)
      Parameters:
      step - before every "now" call, the override/offset will be increased by this amount
    • step

      protected void step()
    • now

      protected ZonedDateTime now(org.mockito.invocation.InvocationOnMock invocation)
    • nowTruncatedToSeconds

      protected ZonedDateTime nowTruncatedToSeconds(org.mockito.invocation.InvocationOnMock invocation)
    • nowInstant

      protected Instant nowInstant(org.mockito.invocation.InvocationOnMock invocation)
    • nowDate

      protected Date nowDate(org.mockito.invocation.InvocationOnMock invocation)
    • currentTimeMillis

      protected long currentTimeMillis(org.mockito.invocation.InvocationOnMock invocation)