sebbASF commented on code in PR #408:
URL: https://github.com/apache/commons-validator/pull/408#discussion_r3474907307


##########
src/test/java/org/apache/commons/validator/routines/CalendarValidatorTest.java:
##########
@@ -232,6 +232,27 @@ void testCompare() {
         assertEquals("Invalid field: -1", e.getMessage(), "check message");
     }
 
+    /**
+     * Test compareWeeks() at the week-year boundary, where WEEK_OF_YEAR is 
relative to a
+     * week-year that differs from the calendar year.
+     */
+    @Test
+    @DefaultLocale(country = "US", language = "en")
+    void testCompareWeeksAcrossYearBoundary() {
+        final int noon = 120000;
+        // 31 Dec 2018 (Monday) is in week 1 of week-year 2019 (US: first day 
Sunday, minimal days 1)
+        final Calendar dec31y2018 = createCalendar(TimeZones.GMT, 20181231, 
noon);
+        final Calendar jan01y2018 = createCalendar(TimeZones.GMT, 20180101, 
noon);
+        final Calendar jan01y2019 = createCalendar(TimeZones.GMT, 20190101, 
noon);
+
+        // both are calendar year 2018 and week-of-year 1, but lie ~52 weeks 
apart
+        assertEquals(1, calValidator.compareWeeks(dec31y2018, jan01y2018), 
"Dec 31 2018 is weeks after Jan 1 2018");
+        assertEquals(-1, calValidator.compareWeeks(jan01y2018, dec31y2018), 
"Jan 1 2018 is weeks before Dec 31 2018");
+
+        // 31 Dec 2018 and 1 Jan 2019 share week 1 of week-year 2019, so they 
are the same week
+        assertEquals(0, calValidator.compareWeeks(dec31y2018, jan01y2019), 
"Dec 31 2018 is the same week as Jan 1 2019");
+    }
+

Review Comment:
   I think there needs to be a test with a calendar that returns false for 
isWeekDateSupported().
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to