forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79eb85d
commit f8d616a
Showing
3 changed files
with
166 additions
and
0 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
93 changes: 93 additions & 0 deletions
93
src/test/java/seedu/address/logic/commands/ShowCommandTest.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,93 @@ | ||
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.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalPersons.ALICE; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.IdentityCardNumber; | ||
import seedu.address.model.person.IdentityCardNumberMatchesPredicate; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code ShowCommand}. | ||
*/ | ||
public class ShowCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void equals() { | ||
IdentityCardNumberMatchesPredicate firstPredicate = | ||
new IdentityCardNumberMatchesPredicate(new IdentityCardNumber("S1234567A")); | ||
IdentityCardNumberMatchesPredicate secondPredicate = | ||
new IdentityCardNumberMatchesPredicate(new IdentityCardNumber("S9876543B")); | ||
|
||
ShowCommand showFirstCommand = ShowCommand.createShowCommand(firstPredicate); | ||
ShowCommand showSecondCommand = ShowCommand.createShowCommand(secondPredicate); | ||
|
||
// same object -> returns true | ||
assertTrue(showFirstCommand.equals(showFirstCommand)); | ||
|
||
// same values -> returns true | ||
ShowCommand showFirstCommandCopy = ShowCommand.createShowCommand(firstPredicate); | ||
assertTrue(showFirstCommand.equals(showFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(showFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(showFirstCommand.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(showFirstCommand.equals(showSecondCommand)); | ||
|
||
// different isClear -> returns false | ||
ShowCommand showFirstCommandClear = ShowCommand.createClearCommand(); | ||
assertFalse(showFirstCommand.equals(showFirstCommandClear)); | ||
|
||
// same isClear -> returns true | ||
ShowCommand showSecondCommandClear = ShowCommand.createClearCommand(); | ||
assertTrue(showFirstCommandClear.equals(showSecondCommandClear)); | ||
} | ||
|
||
@Test | ||
public void execute_validIC_singlePersonFound() { | ||
String testNumber = ALICE.getIdentityCardNumber().value; | ||
String expectedMessage = String.format(ShowCommand.MESSAGE_SHOW_NOTE_SUCCESS, testNumber); | ||
IdentityCardNumberMatchesPredicate predicate = preparePredicate(testNumber); | ||
ShowCommand command = ShowCommand.createShowCommand(predicate); | ||
expectedModel.setDisplayNote(ALICE); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_noIC_clearNote() { | ||
String expectedMessage = ShowCommand.MESSAGE_CLEAR_NOTE_SUCCESS; | ||
ShowCommand command = ShowCommand.createClearCommand(); | ||
expectedModel.clearDisplayNote(); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
IdentityCardNumberMatchesPredicate predicate = new IdentityCardNumberMatchesPredicate( | ||
new IdentityCardNumber("S1234567A")); | ||
ShowCommand showCommand = ShowCommand.createShowCommand(predicate); | ||
String expected = ShowCommand.class.getCanonicalName() + "{predicate=" + predicate + ", isClear=" + "false}"; | ||
assertEquals(expected, showCommand.toString()); | ||
} | ||
|
||
/** | ||
* Parses {@code userInput} into a {@code IdentityCardNumberMatchesPredicate}. | ||
*/ | ||
private IdentityCardNumberMatchesPredicate preparePredicate(String userInput) { | ||
return new IdentityCardNumberMatchesPredicate(new IdentityCardNumber(userInput)); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/seedu/address/logic/parser/ShowCommandParserTest.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,54 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.ShowCommand; | ||
import seedu.address.model.person.IdentityCardNumber; | ||
import seedu.address.model.person.IdentityCardNumberMatchesPredicate; | ||
|
||
public class ShowCommandParserTest { | ||
|
||
private ShowCommandParser parser = new ShowCommandParser(); | ||
|
||
@Test | ||
public void parse_emptyArg_returnsShowCommand() { | ||
ShowCommand expectedShowCommand = ShowCommand.createClearCommand(); | ||
assertParseSuccess(parser, "", expectedShowCommand); | ||
assertParseSuccess(parser, " ", expectedShowCommand); | ||
assertParseSuccess(parser, " \n \t \t", expectedShowCommand); | ||
} | ||
|
||
@Test | ||
public void parse_validArgs_returnsShowCommand() { | ||
ShowCommand expectedShowCommand = ShowCommand.createShowCommand(new IdentityCardNumberMatchesPredicate( | ||
new IdentityCardNumber("S1234567A"))); | ||
assertParseSuccess(parser, "S1234567A", expectedShowCommand); | ||
|
||
// multiple whitespaces between keywords | ||
assertParseSuccess(parser, " \n" | ||
+ " S1234567A \n" | ||
+ " \t \t", expectedShowCommand); | ||
} | ||
|
||
@Test | ||
public void parse_invalidArgs_throwsParseException() { | ||
// IC with incorrect format | ||
assertParseFailure(parser, "S1234", IdentityCardNumber.MESSAGE_CONSTRAINTS); | ||
|
||
// IC with incorrect format and additional arguments | ||
assertParseFailure(parser, "S1234 extra", IdentityCardNumber.MESSAGE_CONSTRAINTS); | ||
|
||
// IC with correct format but contains non-alphanumeric characters | ||
assertParseFailure(parser, "S1234$%^", IdentityCardNumber.MESSAGE_CONSTRAINTS); | ||
} | ||
|
||
@Test | ||
public void parse_nullArgs_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> parser.parse(null)); | ||
} | ||
|
||
} |