nfstime4 implements XdrAble { public long toMillis() throws ChimeraNFSException { if (nseconds < 0 || nseconds > MAX_VALID_NSECONDS ) { throw new InvalException("Invalid value for nseconds"); } return TimeUnit.MILLISECONDS.convert(seconds, TimeUnit.SECONDS) + TimeUnit.MILLISECONDS.convert(nseconds, TimeUnit.NANOSECONDS); } nfstime4();  nfstime4(long millis);  nfstime4(XdrDecodingStream xdr); void xdrEncode(XdrEncodingStream xdr); void xdrDecode(XdrDecodingStream xdr); long toMillis(); String toString(DateTimeFormatter formatter); @Override String toString(); public long seconds; public int nseconds; }
@Test(expected = InvalException.class) public void testInvalidNseconds() throws Exception { nfstime4 time = new nfstime4(); time.seconds = 1; time.nseconds = 1000000000; time.toMillis(); }
@SuppressWarnings("deprecation") @Test public void testValidTime() throws Exception { nfstime4 time = new nfstime4(); time.seconds = 1; time.nseconds = (int)TimeUnit.MILLISECONDS.toNanos(5); long date = LocalDateTime.of(1970, 1, 1, 0, 0, 1, 0).toInstant(ZoneOffset.UTC).toEpochMilli(); assertEquals("invalid date", date + 5, time.toMillis()); }