From 984151bf87da614dff1f8f98bbd695bfb83873b1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 4 Jul 2026 15:54:19 +0000 Subject: [PATCH] =?UTF-8?q?test:=20document=20addBusinessDays=20bug=20?= =?UTF-8?q?=E2=80=94=20pin=20current=20and=20correct=20behaviour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DateUtils.addBusinessDays skips day-of-week 6 (FRIDAY) and 7 (SATURDAY) instead of 7 (SATURDAY) and 1 (SUNDAY). This means: • Friday is wrongly treated as a non-business day • Sunday is wrongly treated as a business day Adds 7 tests: • 3 tests for cases where buggy and correct implementations agree (Mon+0, Mon+1, Mon+3, Mon+5) • 3 "_BUG" tests that pin the current wrong output so the bug cannot regress silently: Thu+1→SUN (correct=FRI), Fri+1→SUN (correct=MON), Mon+4→SUN (correct=FRI) When the bug is fixed the _BUG assertions should be updated to the correct day-of-week values noted in the test comments. Pre-existing failures unchanged: DateUtilsTest.testGetQuarter (Issue #6), TaskServiceTest.testGetTaskStatistics (Issue #3). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../java/com/taskflow/util/DateUtilsTest.java | 109 +++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/taskflow/util/DateUtilsTest.java b/src/test/java/com/taskflow/util/DateUtilsTest.java index 31ffcd4..f4fcc46 100644 --- a/src/test/java/com/taskflow/util/DateUtilsTest.java +++ b/src/test/java/com/taskflow/util/DateUtilsTest.java @@ -86,7 +86,114 @@ public void testStartOfDay() { // Missing tests: // - isOverdue - // - addBusinessDays // - isWithinRange // - edge cases (null inputs, boundary dates) + + // ----------------------------------------------------------------------- + // addBusinessDays tests + // + // KNOWN BUG: The implementation checks for day-of-week 6 (FRIDAY) and 7 + // (SATURDAY) when it should skip 7 (SATURDAY) and 1 (SUNDAY). + // As a result, Friday is wrongly treated as a weekend day and Sunday is + // wrongly treated as a business day. + // + // Tests labelled "_BUG" assert the current (incorrect) behaviour so they + // act as regression pins. When the bug is fixed the assertions in those + // tests must be updated to the correct expected day-of-week. + // See the companion bug issue filed alongside this PR. + // ----------------------------------------------------------------------- + + /** Helper: build a Date for a specific calendar date at noon to avoid DST edge cases. */ + private Date dateOf(int year, int month, int day) { + Calendar c = Calendar.getInstance(); + c.set(year, month, day, 12, 0, 0); + c.set(Calendar.MILLISECOND, 0); + return c.getTime(); + } + + @Test + public void testAddBusinessDays_zeroDays_returnsSameDay() { + // Monday 8 Jan 2024 + Date monday = dateOf(2024, Calendar.JANUARY, 8); + Date result = DateUtils.addBusinessDays(monday, 0); + Calendar cal = Calendar.getInstance(); + cal.setTime(result); + assertEquals(Calendar.MONDAY, cal.get(Calendar.DAY_OF_WEEK), + "Adding zero business days should return the same day"); + } + + @Test + public void testAddBusinessDays_mondayPlusOne_returnsTuesday() { + // Monday 8 Jan 2024 + 1 business day = Tuesday 9 Jan 2024 + Date monday = dateOf(2024, Calendar.JANUARY, 8); + Date result = DateUtils.addBusinessDays(monday, 1); + Calendar cal = Calendar.getInstance(); + cal.setTime(result); + assertEquals(Calendar.TUESDAY, cal.get(Calendar.DAY_OF_WEEK)); + } + + @Test + public void testAddBusinessDays_mondayPlusThree_returnsThursday() { + // Monday 8 Jan 2024 + 3 business days = Thursday 11 Jan 2024 + Date monday = dateOf(2024, Calendar.JANUARY, 8); + Date result = DateUtils.addBusinessDays(monday, 3); + Calendar cal = Calendar.getInstance(); + cal.setTime(result); + assertEquals(Calendar.THURSDAY, cal.get(Calendar.DAY_OF_WEEK)); + } + + @Test + public void testAddBusinessDays_thursdayPlusOne_BUG() { + // Thursday 11 Jan 2024 + 1 business day should be Friday 12 Jan 2024. + // BUG: implementation skips FRIDAY (day 6) and SATURDAY (day 7) instead + // of SATURDAY and SUNDAY, so it lands on SUNDAY instead. + // When the bug is fixed change the assertion to Calendar.FRIDAY. + Date thursday = dateOf(2024, Calendar.JANUARY, 11); + Date result = DateUtils.addBusinessDays(thursday, 1); + Calendar cal = Calendar.getInstance(); + cal.setTime(result); + // BUG: actual=SUNDAY; correct=FRIDAY + assertEquals(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK), + "BUG pin: should be FRIDAY once addBusinessDays skips SAT/SUN instead of FRI/SAT"); + } + + @Test + public void testAddBusinessDays_fridayPlusOne_BUG() { + // Friday 12 Jan 2024 + 1 business day should be Monday 15 Jan 2024. + // BUG: Friday is treated as a non-business day so the result is Sunday. + // When the bug is fixed change the assertion to Calendar.MONDAY. + Date friday = dateOf(2024, Calendar.JANUARY, 12); + Date result = DateUtils.addBusinessDays(friday, 1); + Calendar cal = Calendar.getInstance(); + cal.setTime(result); + // BUG: actual=SUNDAY; correct=MONDAY + assertEquals(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK), + "BUG pin: should be MONDAY once addBusinessDays skips SAT/SUN instead of FRI/SAT"); + } + + @Test + public void testAddBusinessDays_mondayPlusFour_BUG() { + // Monday 8 Jan 2024 + 4 business days should be Friday 12 Jan 2024. + // BUG: Friday counts as a weekend, so the result jumps to Sunday 14 Jan. + // When the bug is fixed change the assertion to Calendar.FRIDAY. + Date monday = dateOf(2024, Calendar.JANUARY, 8); + Date result = DateUtils.addBusinessDays(monday, 4); + Calendar cal = Calendar.getInstance(); + cal.setTime(result); + // BUG: actual=SUNDAY; correct=FRIDAY + assertEquals(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK), + "BUG pin: should be FRIDAY once addBusinessDays skips SAT/SUN instead of FRI/SAT"); + } + + @Test + public void testAddBusinessDays_mondayPlusFive_returnsMonday() { + // Monday 8 Jan 2024 + 5 business days = Monday 15 Jan 2024. + // Both buggy and correct implementations reach Monday here (via different + // intermediate days), so this test verifies week-spanning logic works. + Date monday = dateOf(2024, Calendar.JANUARY, 8); + Date result = DateUtils.addBusinessDays(monday, 5); + Calendar cal = Calendar.getInstance(); + cal.setTime(result); + assertEquals(Calendar.MONDAY, cal.get(Calendar.DAY_OF_WEEK)); + } }