forked from nus-cs2103-AY2324S1/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 #227 from chonguschonguschongus/branch-updateDocs
Add test cases for DeleteAppointment and FindAppointment and changed Ui to allow for text wrapping
- Loading branch information
Showing
8 changed files
with
233 additions
and
35 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
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
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
88 changes: 88 additions & 0 deletions
88
src/test/java/seedu/address/logic/commands/DeleteAppointmentCommandTest.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,88 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.model.util.SampleDataUtil.getSampleAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.appointment.Appointment; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for | ||
* {@code DeleteAppointmentCommand}. | ||
*/ | ||
public class DeleteAppointmentCommandTest { | ||
|
||
private Model model = new ModelManager(getSampleAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_validIndexUnfilteredList_success() { | ||
Appointment appointmentToDelete = model.getFilteredAppointmentList().get(0); | ||
int appointmentToDeleteIndex = 1; | ||
DeleteAppointmentCommand deleteAppointmentCommand = new DeleteAppointmentCommand(appointmentToDeleteIndex); | ||
|
||
String expectedMessage = String.format(deleteAppointmentCommand.MESSAGE_DELETE_APPOINTMENT_SUCCESS, | ||
Messages.format(appointmentToDelete)); | ||
|
||
ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); | ||
expectedModel.deleteAppointment(appointmentToDelete); | ||
|
||
assertCommandSuccess(deleteAppointmentCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_invalidIndexUnfilteredList_throwsCommandException() { | ||
DeleteAppointmentCommand deleteAppointmentCommand = new DeleteAppointmentCommand(4); | ||
DeleteAppointmentCommand deleteAppointmentCommand2 = new DeleteAppointmentCommand(-1); | ||
|
||
assertCommandFailure(deleteAppointmentCommand, model, Messages.MESSAGE_APPOINTMENT_NOT_FOUND); | ||
assertCommandFailure(deleteAppointmentCommand2, model, Messages.MESSAGE_APPOINTMENT_NOT_FOUND); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
DeleteAppointmentCommand deleteFirstCommand = new DeleteAppointmentCommand(1); | ||
DeleteAppointmentCommand deleteSecondCommand = new DeleteAppointmentCommand(2); | ||
|
||
// same object -> returns true | ||
assertTrue(deleteFirstCommand.equals(deleteFirstCommand)); | ||
|
||
// same values -> returns true | ||
DeleteAppointmentCommand deleteFirstCommandCopy = new DeleteAppointmentCommand(1); | ||
assertTrue(deleteFirstCommand.equals(deleteFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(deleteFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(deleteFirstCommand.equals(null)); | ||
|
||
// different Appointment -> returns false | ||
assertFalse(deleteFirstCommand.equals(deleteSecondCommand)); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
DeleteAppointmentCommand deleteAppointmentCommand = new DeleteAppointmentCommand(1); | ||
String expected = DeleteAppointmentCommand.class.getCanonicalName() + "{targetIc=" + 1 + "}"; | ||
assertEquals(expected, deleteAppointmentCommand.toString()); | ||
} | ||
|
||
/** | ||
* Updates {@code model}'s filtered list to show no one. | ||
*/ | ||
private void showNoAppointment(Model model) { | ||
model.updateFilteredAppointmentList(p -> false); | ||
|
||
assertTrue(model.getFilteredAppointmentList().isEmpty()); | ||
} | ||
} | ||
|
100 changes: 100 additions & 0 deletions
100
src/test/java/seedu/address/logic/commands/FindAppointmentCommandTest.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,100 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.Messages.MESSAGE_APPOINTMENTS_FOUND_OVERVIEW; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.model.util.SampleDataUtil.APPOINTMENT_1; | ||
import static seedu.address.model.util.SampleDataUtil.APPOINTMENT_2; | ||
import static seedu.address.model.util.SampleDataUtil.getSampleAddressBook; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.appointment.Appointment; | ||
import seedu.address.model.appointment.AppointmentIcPredicate; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code FindAppointmentCommand}. | ||
*/ | ||
public class FindAppointmentCommandTest { | ||
private Model model = new ModelManager(getSampleAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getSampleAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void constructor_nullField_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new FindAppointmentCommand(null)); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
AppointmentIcPredicate icPredicate1 = new AppointmentIcPredicate("T1234567Z"); | ||
AppointmentIcPredicate icPredicate2 = new AppointmentIcPredicate("T7654321Z"); | ||
|
||
FindAppointmentCommand findFirstCommand = new FindAppointmentCommand(icPredicate1); | ||
FindAppointmentCommand findSecondCommand = new FindAppointmentCommand(icPredicate2); | ||
|
||
// same object -> returns true | ||
assertTrue(findFirstCommand.equals(findFirstCommand)); | ||
|
||
// same values -> returns true | ||
FindAppointmentCommand findFirstCommandCopy = new FindAppointmentCommand(icPredicate1); | ||
assertTrue(findFirstCommand.equals(findFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(findFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(findFirstCommand.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(findFirstCommand.equals(findSecondCommand)); | ||
} | ||
|
||
|
||
@Test | ||
public void execute_findPatientNric_appointmentFound() throws ParseException { | ||
String expectedMessage = String.format(MESSAGE_APPOINTMENTS_FOUND_OVERVIEW, 2); | ||
Predicate<Appointment> predicate = preparePredicate("S1111111Z"); | ||
FindAppointmentCommand command = new FindAppointmentCommand(predicate); | ||
expectedModel.updateFilteredAppointmentList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Arrays.asList(APPOINTMENT_1, APPOINTMENT_2), | ||
model.getFilteredAppointmentList()); | ||
} | ||
|
||
@Test | ||
public void execute_findDoctorNric_appointmentFound() throws ParseException { | ||
String expectedMessage = String.format(MESSAGE_APPOINTMENTS_FOUND_OVERVIEW, 1); | ||
Predicate<Appointment> predicate = preparePredicate("S8811111Z"); | ||
FindAppointmentCommand command = new FindAppointmentCommand(predicate); | ||
expectedModel.updateFilteredAppointmentList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Arrays.asList(APPOINTMENT_1), | ||
model.getFilteredAppointmentList()); | ||
} | ||
|
||
|
||
@Test | ||
public void toStringMethod() { | ||
AppointmentIcPredicate predicate = new AppointmentIcPredicate("keyword"); | ||
FindAppointmentCommand findAppointmentCommand = new FindAppointmentCommand(predicate); | ||
String expected = FindAppointmentCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; | ||
assertEquals(expected, findAppointmentCommand.toString()); | ||
} | ||
|
||
/** | ||
* Parses {@code userInput} into a {@code Predicate<Person>}. | ||
*/ | ||
private Predicate<Appointment> preparePredicate(String userInput) throws ParseException { | ||
return new AppointmentIcPredicate(userInput); | ||
} | ||
} |
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
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
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