forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from bryancheny/makeup-test
Add tests for makeup lesson
- Loading branch information
Showing
5 changed files
with
373 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/test/java/keycontacts/logic/commands/MakeupLessonCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package keycontacts.logic.commands; | ||
|
||
import static keycontacts.logic.commands.CommandTestUtil.VALID_DATE; | ||
import static keycontacts.logic.commands.CommandTestUtil.VALID_END_TIME; | ||
import static keycontacts.logic.commands.CommandTestUtil.VALID_START_TIME; | ||
import static keycontacts.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static keycontacts.testutil.Assert.assertThrows; | ||
import static keycontacts.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
import static keycontacts.testutil.TypicalStudents.getTypicalStudentDirectory; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import keycontacts.commons.core.index.Index; | ||
import keycontacts.logic.Messages; | ||
import keycontacts.logic.commands.exceptions.CommandException; | ||
import keycontacts.model.Model; | ||
import keycontacts.model.ModelManager; | ||
import keycontacts.model.StudentDirectory; | ||
import keycontacts.model.UserPrefs; | ||
import keycontacts.model.lesson.Date; | ||
import keycontacts.model.lesson.MakeupLesson; | ||
import keycontacts.model.lesson.Time; | ||
import keycontacts.model.student.Student; | ||
|
||
public class MakeupLessonCommandTest { | ||
|
||
private Model model; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
model = new ModelManager(getTypicalStudentDirectory(), new UserPrefs()); | ||
} | ||
|
||
@Test | ||
public void constructor_nullIndex_throwsNullPointerException() { | ||
MakeupLesson makeupLesson = new MakeupLesson(new Date(VALID_DATE), new Time(VALID_START_TIME), | ||
new Time(VALID_END_TIME)); | ||
assertThrows(NullPointerException.class, () -> new MakeupLessonCommand(null, makeupLesson)); | ||
} | ||
|
||
@Test | ||
public void constructor_nullMakeupLesson_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new MakeupLessonCommand(INDEX_FIRST_STUDENT, null)); | ||
} | ||
|
||
@Test | ||
public void execute_indexOutOfBounds_throwsCommandException() { | ||
Index outOfBoundsIndex = Index.fromOneBased(model.getStudentList().size() + 1); | ||
MakeupLesson makeupLesson = new MakeupLesson(new Date(VALID_DATE), new Time(VALID_START_TIME), | ||
new Time(VALID_END_TIME)); | ||
MakeupLessonCommand command = new MakeupLessonCommand(outOfBoundsIndex, makeupLesson); | ||
|
||
assertThrows(CommandException.class, | ||
Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX, () -> command.execute(model)); | ||
} | ||
|
||
@Test | ||
public void execute_duplicateMakeupLesson_throwsCommandException() { | ||
Student studentToUpdate = model.getStudentList().get(INDEX_FIRST_STUDENT.getZeroBased()); | ||
MakeupLesson makeupLesson = new MakeupLesson(new Date(VALID_DATE), new Time(VALID_START_TIME), | ||
new Time(VALID_END_TIME)); | ||
|
||
Student studentWithMakeupLesson = studentToUpdate.withAddedMakeupLesson(makeupLesson); | ||
model.setStudent(studentToUpdate, studentWithMakeupLesson); | ||
|
||
MakeupLessonCommand command = new MakeupLessonCommand(INDEX_FIRST_STUDENT, makeupLesson); | ||
|
||
assertThrows(CommandException.class, | ||
MakeupLessonCommand.MESSAGE_DUPLICATE_MAKEUP_LESSON, () -> command.execute(model)); | ||
} | ||
|
||
@Test | ||
public void execute_validInputs_success() { | ||
MakeupLesson makeupLesson = new MakeupLesson(new Date(VALID_DATE), new Time(VALID_START_TIME), | ||
new Time(VALID_END_TIME)); | ||
MakeupLessonCommand command = new MakeupLessonCommand(INDEX_FIRST_STUDENT, makeupLesson); | ||
Student studentToUpdate = model.getStudentList().get(INDEX_FIRST_STUDENT.getZeroBased()); | ||
Student expectedUpdatedStudent = studentToUpdate.withAddedMakeupLesson(makeupLesson); | ||
|
||
Model expectedModel = new ModelManager(new StudentDirectory(model.getStudentDirectory()), new UserPrefs()); | ||
expectedModel.setStudent(studentToUpdate, expectedUpdatedStudent); | ||
|
||
CommandResult expectedCommandResult = new CommandResult( | ||
String.format(MakeupLessonCommand.MESSAGE_SUCCESS, makeupLesson.toDisplay(), | ||
Messages.format(expectedUpdatedStudent))); | ||
|
||
assertCommandSuccess(command, model, expectedCommandResult, expectedModel); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
MakeupLesson makeupLesson = new MakeupLesson(new Date(VALID_DATE), new Time(VALID_START_TIME), | ||
new Time(VALID_END_TIME)); | ||
MakeupLesson differentMakeupLesson = new MakeupLesson(new Date("01-01-2025"), new Time("10:00"), | ||
new Time("11:00")); | ||
MakeupLessonCommand command = new MakeupLessonCommand(INDEX_FIRST_STUDENT, makeupLesson); | ||
MakeupLessonCommand commandDuplicate = new MakeupLessonCommand(INDEX_FIRST_STUDENT, makeupLesson); | ||
MakeupLessonCommand differentLessonCommand = new MakeupLessonCommand( | ||
INDEX_FIRST_STUDENT, differentMakeupLesson); | ||
MakeupLessonCommand differentIndexCommand = new MakeupLessonCommand(Index.fromOneBased(2), makeupLesson); | ||
|
||
assertTrue(command.equals(command)); | ||
assertTrue(command.equals(commandDuplicate)); | ||
assertFalse(command.equals(differentLessonCommand)); | ||
assertTrue(command.equals(differentIndexCommand)); | ||
assertFalse(command.equals(null)); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/test/java/keycontacts/logic/parser/MakeupCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package keycontacts.logic.parser; | ||
|
||
import static keycontacts.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static keycontacts.logic.parser.CliSyntax.PREFIX_DATE; | ||
import static keycontacts.logic.parser.CliSyntax.PREFIX_END_TIME; | ||
import static keycontacts.logic.parser.CliSyntax.PREFIX_START_TIME; | ||
import static keycontacts.testutil.Assert.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import keycontacts.commons.core.index.Index; | ||
import keycontacts.logic.commands.MakeupLessonCommand; | ||
import keycontacts.logic.parser.exceptions.ParseException; | ||
import keycontacts.model.lesson.Date; | ||
import keycontacts.model.lesson.Lesson; | ||
import keycontacts.model.lesson.MakeupLesson; | ||
import keycontacts.model.lesson.Time; | ||
|
||
public class MakeupCommandParserTest { | ||
|
||
private MakeupCommandParser parser = new MakeupCommandParser(); | ||
|
||
@Test | ||
public void parse_validArgs_returnsMakeupLessonCommand() throws Exception { | ||
String userInput = "1 " + PREFIX_DATE + "08-01-2025 " | ||
+ PREFIX_START_TIME + "14:00 " + PREFIX_END_TIME + "15:00"; | ||
MakeupLessonCommand command = parser.parse(userInput); | ||
|
||
Index expectedIndex = Index.fromOneBased(1); | ||
Date expectedDate = new Date("08-01-2025"); | ||
Time expectedStartTime = new Time("14:00"); | ||
Time expectedEndTime = new Time("15:00"); | ||
MakeupLesson expectedMakeupLesson = new MakeupLesson(expectedDate, expectedStartTime, expectedEndTime); | ||
MakeupLessonCommand expectedCommand = new MakeupLessonCommand(expectedIndex, expectedMakeupLesson); | ||
|
||
assertEquals(expectedCommand, command); | ||
} | ||
|
||
@Test | ||
public void parse_missingIndex_throwsParseException() { | ||
String userInput = PREFIX_DATE + "08-01-2025 " | ||
+ PREFIX_START_TIME + "14:00 " + PREFIX_END_TIME + "15:00"; | ||
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MakeupLessonCommand.MESSAGE_USAGE), () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_missingDatePrefix_throwsParseException() { | ||
String userInput = "1 " + PREFIX_START_TIME + "14:00 " + PREFIX_END_TIME + "15:00"; | ||
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MakeupLessonCommand.MESSAGE_USAGE), () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_missingStartTimePrefix_throwsParseException() { | ||
String userInput = "1 " + PREFIX_DATE + "08-01-2025 " + PREFIX_END_TIME + "15:00"; | ||
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MakeupLessonCommand.MESSAGE_USAGE), () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_missingEndTimePrefix_throwsParseException() { | ||
String userInput = "1 " + PREFIX_DATE + "08-01-2025 " + PREFIX_START_TIME + "14:00"; | ||
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MakeupLessonCommand.MESSAGE_USAGE), () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidIndex_throwsParseException() { | ||
String userInput = "a " + PREFIX_DATE + "08-01-2025 " | ||
+ PREFIX_START_TIME + "14:00 " + PREFIX_END_TIME + "15:00"; | ||
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MakeupLessonCommand.MESSAGE_USAGE), () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidDate_throwsParseException() { | ||
String userInput = "1 " + PREFIX_DATE + "invalid-date " | ||
+ PREFIX_START_TIME + "14:00 " + PREFIX_END_TIME + "15:00"; | ||
assertThrows(ParseException.class, Date.MESSAGE_CONSTRAINTS, () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidStartTime_throwsParseException() { | ||
String userInput = "1 " + PREFIX_DATE + "08-01-2025 " | ||
+ PREFIX_START_TIME + "invalid-time " + PREFIX_END_TIME + "15:00"; | ||
assertThrows(ParseException.class, Time.MESSAGE_CONSTRAINTS, () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidEndTime_throwsParseException() { | ||
String userInput = "1 " + PREFIX_DATE + "08-01-2025 " | ||
+ PREFIX_START_TIME + "14:00 " + PREFIX_END_TIME + "invalid-time"; | ||
assertThrows(ParseException.class, Time.MESSAGE_CONSTRAINTS, () -> parser.parse(userInput)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidTimePair_throwsParseException() { | ||
String userInput = "1 " + PREFIX_DATE + "08-01-2025 " | ||
+ PREFIX_START_TIME + "15:00 " + PREFIX_END_TIME + "14:00"; | ||
assertThrows(ParseException.class, Lesson.MESSAGE_CONSTRAINTS, () -> parser.parse(userInput)); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/keycontacts/model/lesson/MakeupLessonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package keycontacts.model.lesson; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class MakeupLessonTest { | ||
private String datestr = "08-01-2025"; | ||
private String startTimeStr = "14:00"; | ||
private String endTimeStr = "15:00"; | ||
private Date date = new Date(datestr); | ||
|
||
private Time startTime = new Time(startTimeStr); | ||
private Time endTime = new Time(endTimeStr); | ||
private MakeupLesson makeupLesson = new MakeupLesson(date, startTime, endTime); | ||
|
||
@Test | ||
public void getLessonTest() { | ||
assertEquals(date, makeupLesson.getLessonDate()); | ||
assertEquals(startTime, makeupLesson.getStartTime()); | ||
assertEquals(endTime, makeupLesson.getEndTime()); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
MakeupLesson sameMakeupLesson = new MakeupLesson(new Date("08-01-2025"), new Time("14:00"), new Time("15:00")); | ||
|
||
assertEquals(sameMakeupLesson, makeupLesson); | ||
assertTrue(makeupLesson.equals(makeupLesson)); | ||
assertNotEquals(makeupLesson, null); | ||
assertNotEquals(makeupLesson, new Object()); | ||
assertNotEquals(new MakeupLesson(date, startTime, new Time("16:00")), makeupLesson); | ||
assertNotEquals(new MakeupLesson(date, new Time("03:00"), endTime), makeupLesson); | ||
assertNotEquals(new MakeupLesson(new Date("08-02-2025"), startTime, endTime), makeupLesson); | ||
} | ||
|
||
@Test | ||
public void toDisplayTest() { | ||
String expected = date.toDisplay() + ", " + startTime.toString() + " - " + endTime.toString(); | ||
assertEquals(expected, makeupLesson.toDisplay()); | ||
} | ||
|
||
@Test | ||
public void getMakeupLessonSetTest() { | ||
String datestr2 = "09-10-2035"; | ||
String startTimeStr2 = "19:00"; | ||
String endTimeStr2 = "20:00"; | ||
Time startTime2 = new Time(startTimeStr2); | ||
Time endTime2 = new Time(endTimeStr2); | ||
MakeupLesson makeupLesson2 = new MakeupLesson(new Date(datestr2), startTime2, endTime2); | ||
Set<MakeupLesson> makeupLessons = new HashSet<>(); | ||
makeupLessons.add(makeupLesson); | ||
makeupLessons.add(makeupLesson2); | ||
String[] array1 = {datestr, datestr2}; | ||
String[] array2 = {startTimeStr, startTimeStr2}; | ||
String[] array3 = {endTimeStr, endTimeStr2}; | ||
|
||
assertTrue(makeupLessons.equals(MakeupLesson.getMakeupLessonSet(array1, array2, array3))); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/test/java/keycontacts/storage/JsonAdaptedMakeupLessonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package keycontacts.storage; | ||
|
||
import static keycontacts.testutil.Assert.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import keycontacts.commons.exceptions.IllegalValueException; | ||
import keycontacts.model.lesson.Date; | ||
import keycontacts.model.lesson.Lesson; | ||
import keycontacts.model.lesson.MakeupLesson; | ||
import keycontacts.model.lesson.Time; | ||
|
||
public class JsonAdaptedMakeupLessonTest { | ||
|
||
@Test | ||
public void toModelType_nullLessonDate_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson(null, "14:00", "15:00"); | ||
String expectedMessage = String.format(JsonAdaptedMakeupLesson.MISSING_FIELD_MESSAGE_FORMAT, | ||
Date.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_emptyLessonDate_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson(" ", "14:00", "15:00"); | ||
String expectedMessage = String.format(JsonAdaptedMakeupLesson.MISSING_FIELD_MESSAGE_FORMAT, | ||
Date.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidLessonDate_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson invalidMakeupLesson = new JsonAdaptedMakeupLesson("Test", "15:00", "16:00"); | ||
assertThrows(IllegalValueException.class, Date.MESSAGE_CONSTRAINTS, invalidMakeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullStartTime_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", null, "15:00"); | ||
String expectedMessage = String.format(JsonAdaptedMakeupLesson.MISSING_FIELD_MESSAGE_FORMAT, | ||
Time.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullEndTime_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", "14:00", null); | ||
String expectedMessage = String.format(JsonAdaptedMakeupLesson.MISSING_FIELD_MESSAGE_FORMAT, | ||
Time.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_emptyStartTime_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", " ", "15:00"); | ||
assertThrows(IllegalValueException.class, Time.MESSAGE_CONSTRAINTS, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_emptyEndTime_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", "14:00", " "); | ||
assertThrows(IllegalValueException.class, Time.MESSAGE_CONSTRAINTS, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidStartTime_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", "invalid", "15:00"); | ||
assertThrows(IllegalValueException.class, Time.MESSAGE_CONSTRAINTS, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidEndTime_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", "14:00", "invalid"); | ||
assertThrows(IllegalValueException.class, Time.MESSAGE_CONSTRAINTS, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidTimePair_throwsIllegalValueException() { | ||
JsonAdaptedMakeupLesson makeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", "16:00", "15:00"); | ||
assertThrows(IllegalValueException.class, Lesson.MESSAGE_CONSTRAINTS, makeupLesson::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_validMakeupLesson_success() throws IllegalValueException { | ||
JsonAdaptedMakeupLesson validMakeupLesson = new JsonAdaptedMakeupLesson("09-10-2025", "14:00", "15:00"); | ||
assertEquals(new MakeupLesson(new Date("09-10-2025"), | ||
new Time("14:00"), new Time("15:00")), validMakeupLesson.toModelType()); | ||
} | ||
} |