### Question:
DateUtils { public static int compareAtSamePrecision(Date date1, Date date2) { return compareAtSamePrecision(date1.toInstant(), date2.toInstant()); } private  DateUtils(); static boolean isAlmostNow(Date date); static boolean isInRangeMinutes(Date date1, Date date2, int rangeInMinutes); static long differenceInMinutes(Date date1, Date date2); static SimpleDateFormat getDateFormatterWithGMTZone(); static int compareAtSamePrecision(Date date1, Date date2);  }### Answer:
@Test public void testDatesWithSecondPrecisionAreEqual() { Instant instant = Instant.ofEpochSecond(123_456_789L); Assert.assertEquals(0L, instant.getNano()); Assert.assertEquals(0, DateUtils.compareAtSamePrecision(Date.from(instant), Date.from(instant))); }
@Test public void testDatesWithMillisecondPrecisionAreEqual() { Instant instant = Instant.ofEpochMilli(123_456_789_123L); Assert.assertEquals(123_000_000L, instant.getNano()); Assert.assertEquals(0, DateUtils.compareAtSamePrecision(Date.from(instant), Date.from(instant))); }
@Test public void testDatesWithSecondPrecisionAreNotEqual() { Instant instant1 = Instant.ofEpochSecond(123_001L); Instant instant2 = Instant.ofEpochSecond(123_002L); Assert.assertTrue(DateUtils.compareAtSamePrecision(Date.from(instant1), Date.from(instant2)) < 0); }
@Test public void testDatesWithMillisecondPrecisionAreNotEqualIfSecondsDiffer() { Instant instant1 = Instant.ofEpochMilli(123_001_999L); Instant instant2 = Instant.ofEpochMilli(123_002_999L); Assert.assertTrue(DateUtils.compareAtSamePrecision(Date.from(instant1), Date.from(instant2)) < 0); }
@Test public void testDatesWithMillisecondPrecisionAreNotEqualIfMillisecondsDiffer() { Instant instant1 = Instant.ofEpochMilli(123_000_002L); Instant instant2 = Instant.ofEpochMilli(123_000_001L); Assert.assertTrue(DateUtils.compareAtSamePrecision(Date.from(instant1), Date.from(instant2)) > 0); }
@Test public void testDatesWithSecondAndMillisecondPrecisionAreEqualIfEverythingUpToSecondPrecisionIsEqual() { Instant instant1 = Instant.ofEpochSecond(123_456_789L); Instant instant2 = Instant.ofEpochSecond(123_456_789L, 999_999_999L); Assert.assertEquals(0, DateUtils.compareAtSamePrecision(Date.from(instant1), Date.from(instant2))); }