Skip to content

Commit

Permalink
Add JUnit for PreviousDayCommand
Browse files Browse the repository at this point in the history
Fixes #286
  • Loading branch information
Cazh1 committed Nov 7, 2023
1 parent 24bb96a commit 53e7a09
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/seedu/cafectrl/data/CurrentDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class CurrentDate {
public CurrentDate() {
currentDay = 0;
}
public CurrentDate(int day) {
currentDay = day - 1;
}
public CurrentDate(Sales sales) {
setDate(sales);
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/seedu/cafectrl/command/PreviousDayCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.cafectrl.command;

import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.CurrentDate;
import seedu.cafectrl.ui.Ui;

import static org.junit.jupiter.api.Assertions.*;

class PreviousDayCommandTest {
@Test
public void execute_setTwoDayOneRun_expectDayOne() {
Ui ui = new Ui();
CurrentDate currentDate = new CurrentDate(2);
Command previousDayCommand = new PreviousDayCommand(ui, currentDate);
previousDayCommand.execute();
int actualDay = currentDate.getCurrentDay() + 1;
int expectedDay = 1;
assert actualDay == expectedDay;
}

@Test
public void execute_setTenDayNineRun_expectDayOne() {
Ui ui = new Ui();
CurrentDate currentDate = new CurrentDate(10);
for (int i = 0; i < 9; i++) {
Command previousDayCommand = new PreviousDayCommand(ui, currentDate);
previousDayCommand.execute();
}
int actualDay = currentDate.getCurrentDay() + 1;
int expectedDay = 1;
assert actualDay == expectedDay;
}
}

0 comments on commit 53e7a09

Please sign in to comment.