예제 #1
0
  @Test
  public void constructorFactoryMethodsValid() {

    TimeInstant ts = TimeInstantBuilder.fromNanos(999123456789L);

    Assert.assertEquals(456789L, ts.getFractalMillisInNanos());
    Assert.assertEquals(123456789L, ts.getFractalSecondsInNanos());
    Assert.assertEquals(999123456789L, ts.getNanos());
    Assert.assertEquals(999123L, ts.getMillis());
    Assert.assertEquals(999L, ts.getSeconds());

    ts = TimeInstantBuilder.fromMillis(999123L);

    Assert.assertEquals(0L, ts.getFractalMillisInNanos());
    Assert.assertEquals(123000000L, ts.getFractalSecondsInNanos());
    Assert.assertEquals(999123000000L, ts.getNanos());
    Assert.assertEquals(999123L, ts.getMillis());
    Assert.assertEquals(999L, ts.getSeconds());

    ts = TimeInstantBuilder.fromSeconds(999L);

    Assert.assertEquals(0L, ts.getFractalMillisInNanos());
    Assert.assertEquals(0L, ts.getFractalSecondsInNanos());
    Assert.assertEquals(999000000000L, ts.getNanos());
    Assert.assertEquals(999000L, ts.getMillis());
    Assert.assertEquals(999L, ts.getSeconds());
  }
예제 #2
0
  @Test
  public void minusSecondsTest() {
    TimeInstant t = TimeInstantBuilder.fromSeconds(222L);
    TimeInstant result = t.minusSeconds(200L);
    Assert.assertTrue(result.getSeconds() == 22L);

    t = TimeInstantBuilder.fromNanos(5123456789L);
    result = t.minusSeconds(5L);
    Assert.assertTrue(result.getSeconds() == 0L);
    Assert.assertTrue(result.getFractalSecondsInNanos() == 123456789L);
  }
예제 #3
0
  @Test
  public void testPlusDuration() {
    final TimeInstant ti = TimeInstantBuilder.fromMillis(0L);
    TimeInstant plusTi = ti.plusDuration(Duration.ZERO);
    Assert.assertEquals(ti, plusTi);

    plusTi = ti.plusDuration(Duration.standardSeconds(1L));
    Assert.assertEquals(TimeInstantBuilder.fromSeconds(1L), plusTi);

    plusTi = ti.plusDuration(Duration.standardHours(1L)).plusNanosPerSecond(123L);

    Assert.assertEquals(TimeInstantBuilder.fromNanos(3600000000123L), plusTi);
  }
예제 #4
0
  @Test
  public void constructorFactoryMethodsValidZero() {

    TimeInstant ts = TimeInstantBuilder.fromNanos(0L);

    Assert.assertEquals(ts.getFractalMillisInNanos(), 0L);
    Assert.assertEquals(ts.getMillis(), 0L);
    Assert.assertEquals(ts.getSeconds(), 0L);

    ts = TimeInstantBuilder.fromMillis(0L);

    Assert.assertEquals(ts.getFractalMillisInNanos(), 0L);
    Assert.assertEquals(ts.getMillis(), 0L);
    Assert.assertEquals(ts.getSeconds(), 0L);

    ts = TimeInstantBuilder.fromSeconds(0L);

    Assert.assertEquals(ts.getFractalMillisInNanos(), 0L);
    Assert.assertEquals(ts.getMillis(), 0L);
    Assert.assertEquals(ts.getSeconds(), 0L);
  }
예제 #5
0
 @Test(expected = IllegalArgumentException.class)
 public void constructorFactoryMethodFromTooManySeconds() {
   TimeInstantBuilder.fromSeconds(TimeInstant.MAX_SECONDS + 1);
 }
예제 #6
0
 @Test(expected = IllegalArgumentException.class)
 public void constructorFactoryMethodFromSecondsNegative() {
   TimeInstantBuilder.fromSeconds(-1L);
 }
예제 #7
0
 @Test(expected = IllegalArgumentException.class)
 public void invalidMinusSecondsTest() {
   final TimeInstant t1 = TimeInstantBuilder.fromSeconds(10L);
   t1.minusSeconds(12L);
 }