Ejemplo n.º 1
0
 @Test
 public void shouldBeAbleToAdvanceClockTimeOnEachQuery() throws Exception {
   Date startOfTheCentury = ymdDateFormat.parse("2000-01-01");
   new DateAlteringClock(startOfTheCentury).advanceMillisOnEachQuery();
   assertThat(Clock.currentTimeInMillis(), is(startOfTheCentury.getTime() + 1));
   assertThat(Clock.currentTimeInMillis(), is(startOfTheCentury.getTime() + 2));
   assertThat(Clock.currentTimeInMillis(), is(startOfTheCentury.getTime() + 3));
 }
Ejemplo n.º 2
0
 @Test
 public void currentClockTimeInMillisShouldTickOnFromZero() throws Exception {
   Date endOfTheDecade = ymdDateFormat.parse("2010-12-31");
   new DateAlteringClock(endOfTheDecade);
   long before = 0, after = 0;
   while (after == before) {
     after = Clock.currentTimeInMillis();
     if (before == 0) {
       before = after;
     }
   }
   assertTrue(Clock.currentTimeInMillis() - endOfTheDecade.getTime() < 1000);
 }
Ejemplo n.º 3
0
 @Test
 public void shouldBeAbleToFreezeClockTime() throws Exception {
   SystemClock systemClock = new SystemClock();
   long before = 0, after = 0;
   new DateAlteringClock(systemClock.currentClockDate()).freeze();
   long frozenTime = Clock.currentTimeInMillis();
   while (after == before) {
     after = systemClock.currentClockTimeInMillis();
     if (before == 0) {
       before = after;
     }
   }
   assertThat(Clock.currentTimeInMillis(), is(frozenTime));
 }
Ejemplo n.º 4
0
 @Test
 public void shouldBeAbleToDefineElapsedTime() throws Exception {
   Date startOfTheCentury = ymdDateFormat.parse("2000-01-01");
   new DateAlteringClock(startOfTheCentury).freeze().elapse(39);
   assertThat(Clock.currentTimeInMillis(), is(startOfTheCentury.getTime() + 39));
 }
Ejemplo n.º 5
0
 @Test
 public void currentClockTimeInMillisShouldBeRebasedToConstructorArg() throws Exception {
   Date startOfTheDecade = ymdDateFormat.parse("2010-01-01");
   new DateAlteringClock(startOfTheDecade);
   assertThat(ymdDateFormat.format(new Date(Clock.currentTimeInMillis())), is("2010-01-01"));
 }