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 #69 from kohkakohla/fixTests
Add addTuteeCommand, Tutor, Tutee tests
- Loading branch information
Showing
10 changed files
with
547 additions
and
13 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
52 changes: 52 additions & 0 deletions
52
src/test/java/seedu/address/logic/commands/AddTuteeCommandIntegrationTest.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,52 @@ | ||
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.CommandHistory; | ||
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.Tutee; | ||
import seedu.address.testutil.TuteeBuilder; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code AddTuteeCommand}. | ||
*/ | ||
public class AddTuteeCommandIntegrationTest { | ||
|
||
private Model model; | ||
private CommandHistory commandHistory = new CommandHistory(); | ||
|
||
|
||
@BeforeEach | ||
public void setUp() { | ||
model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
} | ||
|
||
@Test | ||
public void execute_newPerson_success() { | ||
Tutee validTutee = new TuteeBuilder().build(); | ||
|
||
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); | ||
expectedModel.addPerson(validTutee); | ||
expectedModel.commitAddressBook(); | ||
|
||
assertCommandSuccess(new AddTuteeCommand(validTutee), model, commandHistory, | ||
String.format(AddTuteeCommand.MESSAGE_SUCCESS, Messages.format(validTutee)), | ||
expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_duplicatePerson_throwsCommandException() { | ||
Tutee tuteeInList = (Tutee) model.getAddressBook().getPersonList().get(4); | ||
assertCommandFailure(new AddTuteeCommand(tuteeInList), model, commandHistory, | ||
AddTuteeCommand.MESSAGE_DUPLICATE_PERSON); | ||
} | ||
|
||
} |
242 changes: 242 additions & 0 deletions
242
src/test/java/seedu/address/logic/commands/AddTuteeCommandTest.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,242 @@ | ||
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.DANIEL; | ||
|
||
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.CommandHistory; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.AddressBook; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ReadOnlyAddressBook; | ||
import seedu.address.model.ReadOnlyUserPrefs; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Tutee; | ||
import seedu.address.testutil.TuteeBuilder; | ||
|
||
public class AddTuteeCommandTest { | ||
|
||
private static final CommandHistory EMPTY_COMMAND_HISTORY = new CommandHistory(); | ||
|
||
private CommandHistory commandHistory = new CommandHistory(); | ||
|
||
@Test | ||
public void constructor_nullPerson_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new AddTuteeCommand(null)); | ||
} | ||
|
||
@Test | ||
public void execute_personAcceptedByModel_addSuccessful() throws Exception { | ||
ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded(); | ||
Tutee validTutee = new TuteeBuilder().build(); | ||
|
||
CommandResult commandResult = new AddTuteeCommand(validTutee).execute(modelStub, commandHistory); | ||
|
||
assertEquals(String.format(AddTuteeCommand.MESSAGE_SUCCESS, Messages.format(validTutee)), | ||
commandResult.getFeedbackToUser()); | ||
assertEquals(Arrays.asList(validTutee), modelStub.personsAdded); | ||
assertEquals(EMPTY_COMMAND_HISTORY, commandHistory); | ||
} | ||
|
||
@Test | ||
public void execute_duplicatePerson_throwsCommandException() { | ||
Tutee validTutee = new TuteeBuilder().build(); | ||
AddTuteeCommand addTuteeCommand = new AddTuteeCommand(validTutee); | ||
ModelStub modelStub = new ModelStubWithPerson(validTutee); | ||
|
||
assertThrows(CommandException.class, AddTuteeCommand.MESSAGE_DUPLICATE_PERSON, () -> | ||
addTuteeCommand.execute(modelStub, commandHistory)); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
Tutee alice = new TuteeBuilder().withName("Alice").build(); | ||
Tutee bob = new TuteeBuilder().withName("Bob").build(); | ||
AddTuteeCommand addAliceCommand = new AddTuteeCommand(alice); | ||
AddTuteeCommand addBobCommand = new AddTuteeCommand(bob); | ||
|
||
// same object -> returns true | ||
assertTrue(addAliceCommand.equals(addAliceCommand)); | ||
|
||
// same values -> returns true | ||
AddTuteeCommand addAliceCommandCopy = new AddTuteeCommand(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() { | ||
AddTuteeCommand addTuteeCommand = new AddTuteeCommand(DANIEL); | ||
String expected = AddTuteeCommand.class.getCanonicalName() + "{toAddTutee=" + DANIEL + "}"; | ||
assertEquals(expected, addTuteeCommand.toString()); | ||
} | ||
|
||
/** | ||
* A default model stub that have all of 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 getAddressBookFilePath() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void setAddressBookFilePath(Path addressBookFilePath) { | ||
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 setAddressBook(ReadOnlyAddressBook newData) { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public ReadOnlyAddressBook getAddressBook() { | ||
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 void deletePerson(Person 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 ObservableList<Person> getFilteredPersonList() { | ||
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 boolean canUndoAddressBook() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public boolean canRedoAddressBook() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void undoAddressBook() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void redoAddressBook() { | ||
throw new AssertionError("This method should not be called."); | ||
} | ||
|
||
@Override | ||
public void commitAddressBook() { | ||
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 void commitAddressBook() { | ||
// called by {@code AddCommand#execute()} | ||
} | ||
|
||
@Override | ||
public ReadOnlyAddressBook getAddressBook() { | ||
return new AddressBook(); | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -40,9 +40,22 @@ public class CommandTestUtil { | |
public static final String VALID_HOURS_BOB = "10"; | ||
public static final String VALID_TAG_HUSBAND = "husband"; | ||
public static final String VALID_TAG_FRIEND = "friend"; | ||
public static final String VALID_NAME_CLARA = "Clara Doe"; | ||
public static final String VALID_NAME_DEACON = "Deacon Smith"; | ||
public static final String VALID_PHONE_CLARA = "33333333"; | ||
public static final String VALID_PHONE_DEACON = "44444444"; | ||
public static final String VALID_EMAIL_CLARA = "[email protected]"; | ||
public static final String VALID_EMAIL_DEACON = "[email protected]"; | ||
public static final String VALID_ADDRESS_CLARA = "Block 456, Clara Street 5"; | ||
public static final String VALID_ADDRESS_DEACON = "Block 789, Deacon Avenue 8"; | ||
public static final String VALID_HOURS_CLARA = "15"; | ||
public static final String VALID_HOURS_DEACON = "25"; | ||
public static final String VALID_TAG_COLLEAGUE = "colleague"; | ||
public static final String VALID_TAG_MENTOR = "mentor"; | ||
public static final String VALID_SUBJECT_MATH = "math"; | ||
public static final String VALID_SUBJECT_SCIENCE = "science"; | ||
|
||
|
||
public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY; | ||
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB; | ||
public static final String PHONE_DESC_AMY = " " + PREFIX_PHONE + VALID_PHONE_AMY; | ||
|
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
Oops, something went wrong.