forked from AY2324S2-CS2103T-T08-1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 AY2324S2-CS2103T-T08-1#234 from jovantanyk/fix-add…
…visitcommand Fix AddVisitCommand and Storage bug. Init Visit TestUtils and Test Cases
- Loading branch information
Showing
19 changed files
with
1,076 additions
and
64 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
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
48 changes: 48 additions & 0 deletions
48
src/test/java/seedu/address/logic/commands/AddVisitCommandIntegrationTest.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,48 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
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.person.Person; | ||
import seedu.address.testutil.PersonBuilder; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code AddCommand}. | ||
*/ | ||
public class AddVisitCommandIntegrationTest { | ||
|
||
private Model model; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
} | ||
|
||
@Test | ||
public void execute_newVisit_success() { | ||
Person validPerson = new PersonBuilder().build(); | ||
|
||
Model expectedModel = new ModelManager(model.getImmuniMate(), new UserPrefs()); | ||
expectedModel.addPerson(validPerson); | ||
|
||
assertCommandSuccess(new CreateCommand(validPerson), model, | ||
String.format(CreateCommand.MESSAGE_SUCCESS, Messages.format(validPerson)), | ||
expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_duplicatePerson_throwsCommandException() { | ||
Person personInList = model.getImmuniMate().getPersonList().get(0); | ||
assertCommandFailure(new CreateCommand(personInList), model, | ||
CreateCommand.MESSAGE_DUPLICATE_PERSON); | ||
} | ||
|
||
} |
238 changes: 238 additions & 0 deletions
238
src/test/java/seedu/address/logic/commands/AddVisitCommandTest.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,238 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
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.testutil.Assert.assertThrows; | ||
import static seedu.address.testutil.TypicalPersons.ALICE; | ||
|
||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import javafx.collections.ObservableList; | ||
import seedu.address.commons.core.GuiSettings; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.ImmuniMate; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ReadOnlyImmuniMate; | ||
import seedu.address.model.ReadOnlyUserPrefs; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.visit.Visit; | ||
import seedu.address.testutil.PersonBuilder; | ||
|
||
|
||
// TODO Adjust Test Cases | ||
public class AddVisitCommandTest { | ||
|
||
@Test | ||
public void constructor_nullPerson_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new CreateCommand(null)); | ||
} | ||
|
||
@Test | ||
public void execute_personAcceptedByModel_addSuccessful() throws Exception { | ||
ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded(); | ||
Person validPerson = new PersonBuilder().build(); | ||
|
||
CommandResult commandResult = new CreateCommand(validPerson).execute(modelStub); | ||
|
||
assertEquals(String.format(CreateCommand.MESSAGE_SUCCESS, Messages.format(validPerson)), | ||
commandResult.getFeedbackToUser()); | ||
assertEquals(Arrays.asList(validPerson), modelStub.personsAdded); | ||
} | ||
|
||
@Test | ||
public void execute_duplicatePerson_throwsCommandException() { | ||
Person validPerson = new PersonBuilder().build(); | ||
CreateCommand createCommand = new CreateCommand(validPerson); | ||
ModelStub modelStub = new ModelStubWithPerson(validPerson); | ||
|
||
assertThrows(CommandException.class, | ||
CreateCommand.MESSAGE_DUPLICATE_PERSON, () -> createCommand.execute(modelStub)); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
Person alice = new PersonBuilder().withName("Alice").build(); | ||
Person bob = new PersonBuilder().withName("Bob").build(); | ||
CreateCommand addAliceCommand = new CreateCommand(alice); | ||
CreateCommand addBobCommand = new CreateCommand(bob); | ||
|
||
// same object -> returns true | ||
assertTrue(addAliceCommand.equals(addAliceCommand)); | ||
|
||
// same values -> returns true | ||
CreateCommand addAliceCommandCopy = new CreateCommand(alice); | ||
assertTrue(addAliceCommand.equals(addAliceCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(addAliceCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(addAliceCommand.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(addAliceCommand.equals(addBobCommand)); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
CreateCommand createCommand = new CreateCommand(ALICE); | ||
String expected = CreateCommand.class.getCanonicalName() + "{toAdd=" + ALICE + "}"; | ||
assertEquals(expected, createCommand.toString()); | ||
} | ||
|
||
/** | ||
* A default model stub that have all the methods failing. | ||
*/ | ||
private class ModelStub implements Model { | ||
@Override | ||
public void setUserPrefs(ReadOnlyUserPrefs userPrefs) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public ReadOnlyUserPrefs getUserPrefs() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public GuiSettings getGuiSettings() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void setGuiSettings(GuiSettings guiSettings) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public Path getImmunimateFilePath() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void setImmunimateFilePath(Path immuniMateFilePath) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void addPerson(Person person) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void addVisit(Visit visit) { | ||
|
||
} | ||
|
||
@Override | ||
public void setImmuniMate(ReadOnlyImmuniMate immuniMate) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public ReadOnlyImmuniMate getImmuniMate() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public boolean hasPerson(Person person) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public boolean hasVisit(Visit visit) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void deletePerson(Person target) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void deleteVisit(Visit target) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void setPerson(Person target, Person editedPerson) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void setVisit(Visit target, Visit editedVisit) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public ObservableList<Person> getFilteredPersonList() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public ObservableList<Visit> getFilteredVisitList() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void updateFilteredPersonList(Predicate<Person> predicate) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void updateFilteredVisitList(Predicate<Visit> predicate) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
} | ||
|
||
/** | ||
* A Model stub that contains a single person. | ||
*/ | ||
private class ModelStubWithPerson extends ModelStub { | ||
private final Person person; | ||
|
||
ModelStubWithPerson(Person person) { | ||
requireNonNull(person); | ||
this.person = person; | ||
} | ||
|
||
@Override | ||
public boolean hasPerson(Person person) { | ||
requireNonNull(person); | ||
return this.person.isSamePerson(person); | ||
} | ||
} | ||
|
||
/** | ||
* A Model stub that always accept the person being added. | ||
*/ | ||
private class ModelStubAcceptingPersonAdded extends ModelStub { | ||
final ArrayList<Person> personsAdded = new ArrayList<>(); | ||
|
||
@Override | ||
public boolean hasPerson(Person person) { | ||
requireNonNull(person); | ||
return personsAdded.stream().anyMatch(person::isSamePerson); | ||
} | ||
|
||
@Override | ||
public void addPerson(Person person) { | ||
requireNonNull(person); | ||
personsAdded.add(person); | ||
} | ||
|
||
@Override | ||
public ReadOnlyImmuniMate getImmuniMate() { | ||
return new ImmuniMate(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.