diff --git a/src/unittests/java/MakeItFit/activities/types/RepetitionsTest.java b/src/unittests/java/MakeItFit/activities/types/RepetitionsTest.java index e0947b0..5961707 100644 --- a/src/unittests/java/MakeItFit/activities/types/RepetitionsTest.java +++ b/src/unittests/java/MakeItFit/activities/types/RepetitionsTest.java @@ -2,14 +2,14 @@ import java.util.UUID; +import MakeItFit.utils.MakeItFitDate; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import MakeItFit.utils.MakeItFitDate; public class RepetitionsTest { private TestRepetitions activity; diff --git a/src/unittests/java/MakeItFit/time/TimeManagerTest.java b/src/unittests/java/MakeItFit/time/TimeManagerTest.java new file mode 100644 index 0000000..26110b2 --- /dev/null +++ b/src/unittests/java/MakeItFit/time/TimeManagerTest.java @@ -0,0 +1,64 @@ +package MakeItFit.time; + +import MakeItFit.utils.MakeItFitDate; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class TimeManagerTest { + + private MakeItFitDate date; + + @BeforeEach + void setup() { + date = MakeItFitDate.of(2024, 5, 10); + } + + @Test + void testDefaultConstructorInitializesWithCurrentDate() { + TimeManager manager = new TimeManager(); + assertNotNull(manager.getCurrentDate()); + } + + @Test + void testConstructorWithCustomDate() { + TimeManager manager = new TimeManager(date); + assertEquals(date, manager.getCurrentDate()); + } + + @Test + void testGetCurrentDateReturnsCorrectDate() { + TimeManager manager = new TimeManager(date); + MakeItFitDate current = manager.getCurrentDate(); + assertEquals(date, current); + } + + @Test + void testAdvanceTimeWithPositiveDays() { + TimeManager manager = new TimeManager(date); + MakeItFitDate advancedDate = manager.advanceTime(5); + + MakeItFitDate expectedDate = date.plusDays(5); + assertEquals(expectedDate, advancedDate); + assertEquals(expectedDate, manager.getCurrentDate()); + } + + @Test + void testAdvanceTimeWithZeroDays() { + TimeManager manager = new TimeManager(date); + MakeItFitDate advancedDate = manager.advanceTime(0); + + assertEquals(date, advancedDate); + } + + @Test + void testAdvanceTimeWithNegativeDaysThrowsException() { + TimeManager manager = new TimeManager(date); + IllegalArgumentException exception = + assertThrows(IllegalArgumentException.class, () -> { manager.advanceTime(-1); }); + assertEquals("Days must be a positive number.", exception.getMessage()); + } +}