From 11cef2b0cbbe4bc867616e893c6643a75ab21961 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 17:04:03 +0000 Subject: [PATCH] test: add missing tests for DateUtils and StringUtils.padRight Add tests for previously untested DateUtils methods: - isOverdue (past, future, null, invalid date string) - isWithinRange (middle, before-start, after-end) - daysBetween (exact week, same instant) Add padRight tests to StringUtils: - Happy paths (shorter, equal, null input) - Document known NegativeArraySizeException bug (Issue #7) via assertThrows so the bug is not silently ignored Pre-existing failures unrelated to these changes: - DateUtilsTest.testGetQuarter: off-by-one bug (Issue #6) - TaskServiceTest.testGetTaskStatistics: division by zero (Issue #3) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../java/com/taskflow/util/DateUtilsTest.java | 69 +++++++++++++++++-- .../com/taskflow/util/StringUtilsTest.java | 29 +++++++- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/taskflow/util/DateUtilsTest.java b/src/test/java/com/taskflow/util/DateUtilsTest.java index 31ffcd4..399a6b8 100644 --- a/src/test/java/com/taskflow/util/DateUtilsTest.java +++ b/src/test/java/com/taskflow/util/DateUtilsTest.java @@ -84,9 +84,68 @@ public void testStartOfDay() { // BUG: milliseconds not reset, but we don't test for it } - // Missing tests: - // - isOverdue - // - addBusinessDays - // - isWithinRange - // - edge cases (null inputs, boundary dates) + // --- isOverdue --- + + @Test + public void testIsOverdue_pastDate() { + assertTrue(DateUtils.isOverdue("2020-01-01")); + } + + @Test + public void testIsOverdue_futureDate() { + assertFalse(DateUtils.isOverdue("2099-12-31")); + } + + @Test + public void testIsOverdue_null() { + // Null treated as not overdue (cannot distinguish from "no due date set") + assertFalse(DateUtils.isOverdue(null)); + } + + @Test + public void testIsOverdue_invalidDateString() { + // Unparseable date treated as not overdue (silent failure in parseDate) + assertFalse(DateUtils.isOverdue("not-a-date")); + } + + // --- isWithinRange --- + + @Test + public void testIsWithinRange_dateInMiddle() { + Date start = new Date(1_000_000L); + Date middle = new Date(2_000_000L); + Date end = new Date(3_000_000L); + assertTrue(DateUtils.isWithinRange(middle, start, end)); + } + + @Test + public void testIsWithinRange_dateBeforeStart() { + Date before = new Date(1_000_000L); + Date start = new Date(2_000_000L); + Date end = new Date(3_000_000L); + assertFalse(DateUtils.isWithinRange(before, start, end)); + } + + @Test + public void testIsWithinRange_dateAfterEnd() { + Date start = new Date(1_000_000L); + Date end = new Date(2_000_000L); + Date after = new Date(3_000_000L); + assertFalse(DateUtils.isWithinRange(after, start, end)); + } + + // --- daysBetween (additional cases) --- + + @Test + public void testDaysBetween_exactlyOneWeek() { + Date start = new Date(0L); + Date end = new Date(7L * 24 * 60 * 60 * 1000); + assertEquals(7, DateUtils.daysBetween(start, end)); + } + + @Test + public void testDaysBetween_sameInstant() { + Date d = new Date(12_345_678L); + assertEquals(0, DateUtils.daysBetween(d, d)); + } } diff --git a/src/test/java/com/taskflow/util/StringUtilsTest.java b/src/test/java/com/taskflow/util/StringUtilsTest.java index 32788ba..905f73a 100644 --- a/src/test/java/com/taskflow/util/StringUtilsTest.java +++ b/src/test/java/com/taskflow/util/StringUtilsTest.java @@ -89,6 +89,31 @@ public void testJoin() { assertEquals("", StringUtils.join(null, ",")); assertEquals("", StringUtils.join(new String[]{}, ",")); } - - // No test for padRight - it has a known StringIndexOutOfBoundsException bug + + // --- padRight --- + + @Test + public void testPadRight_stringShorterThanWidth() { + assertEquals("hi ", StringUtils.padRight("hi", 5)); + } + + @Test + public void testPadRight_stringEqualsWidth() { + assertEquals("hello", StringUtils.padRight("hello", 5)); + } + + @Test + public void testPadRight_nullString() { + // null is treated as empty string, result is all-spaces padding + assertEquals(" ", StringUtils.padRight(null, 5)); + } + + @Test + public void testPadRight_stringLongerThanWidth_throwsBug() { + // Known bug (Issue #7): throws NegativeArraySizeException when str.length() > width + // Correct behavior should handle this gracefully (truncate or return as-is). + // When fixed, replace assertThrows with the expected output. + assertThrows(NegativeArraySizeException.class, + () -> StringUtils.padRight("hello world", 3)); + } }