Skip to content

Commit ab3acd2

Browse files
authored
Merge pull request AY2324S2-CS2103T-T08-1#97 from NatLeong/add-read-tests
Add all tests for ReadCommand and ReadCommandParser
2 parents 28386bb + 0482579 commit ab3acd2

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/test/java/seedu/address/logic/commands/ReadCommandTest.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,49 @@
44
import static org.junit.jupiter.api.Assertions.assertFalse;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66
import static seedu.address.logic.commands.CommandTestUtil.NON_EXISTENT_NRIC;
7-
import static seedu.address.testutil.TypicalPersons.BOB;
7+
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
8+
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
9+
import static seedu.address.logic.commands.ReadCommand.MESSAGE_READ_PERSON_SUCCESS;
10+
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
11+
import static seedu.address.testutil.TypicalPersons.ALICE;
812
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
913

1014
import org.junit.jupiter.api.Test;
1115

16+
import seedu.address.logic.Messages;
1217
import seedu.address.model.Model;
1318
import seedu.address.model.ModelManager;
1419
import seedu.address.model.UserPrefs;
1520
import seedu.address.model.person.Nric;
1621

1722
public class ReadCommandTest {
1823

19-
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
20-
21-
/*@Test
24+
private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
25+
private final Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
26+
@Test
2227
void execute_validNric_success() {
23-
28+
String expectedMessage = String.format(MESSAGE_READ_PERSON_SUCCESS, Messages.formatRead(ALICE));
29+
ReadCommand command = new ReadCommand(ALICE.getNric());
30+
expectedModel.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
31+
assertCommandSuccess(command, model, expectedMessage, expectedModel);
2432
}
2533

2634
@Test
27-
void execute_invalidNric_failure() {
28-
29-
}*/
35+
void execute_nonExistentNric_failure() {
36+
Nric nonexistentNric = new Nric("S1234567A");
37+
assertCommandFailure(new ReadCommand(nonexistentNric), model, Messages.MESSAGE_PERSON_NOT_FOUND);
38+
}
3039

3140
@Test
3241
void equals() {
33-
ReadCommand readFirstCommand = new ReadCommand(BOB.getNric());
42+
ReadCommand readFirstCommand = new ReadCommand(ALICE.getNric());
3443
ReadCommand readSecondCommand = new ReadCommand(new Nric(NON_EXISTENT_NRIC));
3544

3645
// same object -> returns true
3746
assertTrue(readFirstCommand.equals(readFirstCommand));
3847

3948
// same values -> returns true
40-
ReadCommand readFirstCommandCopy = new ReadCommand(BOB.getNric());
49+
ReadCommand readFirstCommandCopy = new ReadCommand(ALICE.getNric());
4150
assertTrue(readFirstCommand.equals(readFirstCommandCopy));
4251

4352
// different types -> returns false
@@ -52,8 +61,8 @@ void equals() {
5261

5362
@Test
5463
void testToString() {
55-
ReadCommand readCommand = new ReadCommand(BOB.getNric());
56-
String expected = ReadCommand.class.getCanonicalName() + "{nric=" + BOB.getNric() + "}";
64+
ReadCommand readCommand = new ReadCommand(ALICE.getNric());
65+
String expected = ReadCommand.class.getCanonicalName() + "{nric=" + ALICE.getNric() + "}";
5766
assertEquals(expected, readCommand.toString());
5867
}
5968

src/test/java/seedu/address/logic/parser/ReadCommandParserTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
44
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
5+
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
6+
import static seedu.address.testutil.TypicalPersons.ALICE;
57

68
import org.junit.jupiter.api.Test;
79

@@ -14,9 +16,12 @@ public void parse_emptyArg_throwsParseException() {
1416
assertParseFailure(parser, " ",
1517
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReadCommand.MESSAGE_NOT_READ));
1618
}
17-
/*@Test
18-
public void parse_validArgs_returnsReadCommand() {
1919

20-
}*/
20+
@Test
21+
public void parse_validArgs_returnsReadCommand() {
22+
ReadCommand expectedReadCommand =
23+
new ReadCommand(ALICE.getNric());
24+
assertParseSuccess(parser, "T0139571B", expectedReadCommand);
25+
}
2126

2227
}

0 commit comments

Comments
 (0)