示例#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 minusMillisTest() {
    TimeInstant t = TimeInstantBuilder.fromMillis(222L);
    TimeInstant result = t.minusMillis(200L);
    Assert.assertTrue(result.getMillis() == 22L);

    t = TimeInstantBuilder.fromNanos(123456789L);
    result = t.minusMillis(123L);
    Assert.assertTrue(result.getMillis() == 0L);
    Assert.assertTrue(result.getFractalSecondsInNanos() == 456789L);
  }
示例#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 testFormats() {
    final TimeInstant now = TimeInstantBuilder.fromNow();

    final String date = now.formatted(TimeInstant.STD_DATE_FMT);
    Assert.assertTrue(Pattern.matches("\\d\\d\\d\\d-\\d\\d-\\d\\d", date));

    final String time = now.formatted(TimeInstant.STD_TIME_FMT);
    Assert.assertTrue(Pattern.matches("\\d\\d:\\d\\d:\\d\\d", time));

    final String timeFS = now.formatted(TimeInstant.STD_TIME_FMT_FOR_FS);
    Assert.assertTrue(Pattern.matches("\\d\\d_\\d\\d_\\d\\d", timeFS));

    final String dateTime = now.formatted(TimeInstant.STD_DATETIME_FMT);
    Assert.assertTrue(
        Pattern.matches("\\d\\d\\d\\d-\\d\\d-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d", dateTime));

    final String dateTimeWithMS = now.formatted(TimeInstant.STD_DATETIME_FMT_WITH_MILLIS);
    Assert.assertTrue(
        Pattern.matches(
            "\\d\\d\\d\\d-\\d\\d-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d\\.\\d\\d\\d", dateTimeWithMS));

    final String dateTimeFS = now.formatted(TimeInstant.STD_DATETIME_FMT_FOR_FS);
    Assert.assertTrue(
        Pattern.matches("\\d\\d\\d\\d-\\d\\d-\\d\\d_\\d\\dh\\d\\dm\\d\\ds", dateTimeFS));
  }
示例#5
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);
  }
示例#6
0
  @Test
  public void plusTest() {
    final TimeInstant t1 = TimeInstantBuilder.fromNanos(0L);
    final TimeInstant t2 = t1.plusMillis(0L);
    Assert.assertTrue(t1.equals(t2));

    final TimeInstant t3 = t1.plusMillis(1L);
    Assert.assertTrue(t3.isAfter(t2));
    Assert.assertEquals(1L, t3.getMillis());

    final TimeInstant t4 = t3.plusNanosPerSecond(999000000);
    Assert.assertTrue(t4.isAfter(t3));
    Assert.assertEquals(1000L, t4.getMillis());

    final TimeInstant t5 = t1.plusNanosPerSecond(1L);
    Assert.assertTrue(t4.isAfter(t1));
    Assert.assertEquals(TimeInstantBuilder.fromNanos(1L), t5);

    final TimeInstant t6 = t1.plusMillis(123L).plusNanosPerSecond(456789L);
    Assert.assertEquals(TimeInstantBuilder.fromNanos(123456789L), t6);
    Assert.assertEquals(TimeInstantBuilder.fromNanos(123000000L).plusNanosPerSecond(456789L), t6);
  }
示例#7
0
  @Test
  public void compareTimeTest() {
    final TimeInstant first = TimeInstantBuilder.fromMillis(0L);
    final TimeInstant now = TimeInstantBuilder.fromNow();

    Assert.assertEquals(0, first.compareTo(first));
    Assert.assertEquals(-1, first.compareTo(now));
    Assert.assertEquals(1, now.compareTo(first));
    Assert.assertFalse(first.equals(now));
    Assert.assertFalse(first.equals(now));
    Assert.assertFalse(first.getInstant().equals(now.getInstant()));

    final TimeInstant t1 = TimeInstantBuilder.fromMillis(123456L);
    final TimeInstant t2 = TimeInstantBuilder.fromMillis(123456L);
    Assert.assertEquals(0, t1.compareTo(t2));
    Assert.assertEquals(0, t2.compareTo(t1));
    Assert.assertTrue(t1.equals(t2));
    Assert.assertTrue(t2.equals(t1));
    Assert.assertTrue(t1.getInstant().equals(t2.getInstant()));
    Assert.assertFalse(t1.isAfter(t2));
    Assert.assertFalse(t2.isAfter(t1));
    Assert.assertFalse(t1.isBefore(t2));
    Assert.assertFalse(t2.isBefore(t1));

    final TimeInstant t3 = TimeInstantBuilder.fromNanos(123456000000L);
    final TimeInstant t4 = TimeInstantBuilder.fromNanos(123456000001L);
    Assert.assertEquals(-1, t3.compareTo(t4));
    Assert.assertEquals(1, t4.compareTo(t3));
    Assert.assertFalse(t3.equals(t4));
    Assert.assertFalse(t4.equals(t3));
    Assert.assertTrue(t3.getInstant().equals(t4.getInstant()));
    Assert.assertFalse(t3.isAfter(t4));
    Assert.assertTrue(t4.isAfter(t3));
    Assert.assertTrue(t3.isBefore(t4));
    Assert.assertFalse(t4.isBefore(t3));
  }
示例#8
0
 @Test(expected = IllegalArgumentException.class)
 public void constructorFactoryMethodFromTooManySeconds() {
   TimeInstantBuilder.fromSeconds(TimeInstant.MAX_SECONDS + 1);
 }
示例#9
0
 @Test(expected = IllegalArgumentException.class)
 public void constructorFactoryMethodFromSecondsNegative() {
   TimeInstantBuilder.fromSeconds(-1L);
 }
示例#10
0
 @Test(expected = IllegalArgumentException.class)
 public void invalidPlusTest2() {
   final TimeInstant t1 = TimeInstantBuilder.fromNanos(0L);
   t1.plusNanosPerSecond(-1L);
 }
示例#11
0
 @Test(expected = IllegalArgumentException.class)
 public void invalidMinusMillisTest() {
   final TimeInstant t1 = TimeInstantBuilder.fromNanos(1L);
   t1.minusMillis(2L);
 }
示例#12
0
 @Test(expected = IllegalArgumentException.class)
 public void invalidMinusSecondsTest() {
   final TimeInstant t1 = TimeInstantBuilder.fromSeconds(10L);
   t1.minusSeconds(12L);
 }