Skip to content

Commit 7bdcb71

Browse files
Increase code coverage for view related classes + fix UG trailing whitespaces
1 parent f67488c commit 7bdcb71

6 files changed

Lines changed: 131 additions & 6 deletions

File tree

docs/UserGuide.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ Address | String | a/
8282
<div markdown="block" class="alert alert-info">
8383

8484
**:information_source: Notes about the command format:**<br>
85-
85+
8686
* When `<attribute>` is given, it means that the any *attribute tag* can be used, with the exception of *client id* in some cases
87-
8887
* In the format for the commands provided, words which are in `UPPERCASE` refers to the `input` that the user must key in
89-
9088
* If the inputs are wrapped in curly brackets `{}`, they are inputs that are related to the preceeding argument tag
9189

9290
* Inputs in square brackets are optional input:<br>
@@ -138,7 +136,7 @@ Examples:
138136

139137
### Delete particular contact : `delete`
140138

141-
Deletes an existing client from the address book using their either client id or email address identify the client.
139+
Deletes an existing client from the address book using their either client id or email address identify the client.
142140
Both attributes can be given together.
143141

144142
Format: `delete <client id>/{CLIENT'S ID} <email>/{EMAIL}`
@@ -163,7 +161,7 @@ Sorts clients in order based off the inputted attribute
163161

164162
Format: `sort <attribute>/{ASC/DSC}`
165163

166-
* The asc and dsc tag dictates whether filtered client list is sorted in ascending or descending order.
164+
* The asc and dsc tag dictates whether filtered client list is sorted in ascending or descending order.
167165
* The tags are case-insensitive. (ASC are asc both okay.)
168166

169167
Examples:

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public ObservableList<Person> getPersonToView() {
176176

177177
@Override
178178
public boolean isPersonExistToView() {
179-
return personToView.size() == 1 && personToView.get(0) != null;
179+
return personToView.size() == 1;
180180
}
181181

182182
@Override

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import seedu.address.logic.commands.HelpCommand;
3434
import seedu.address.logic.commands.ListCommand;
3535
import seedu.address.logic.commands.SearchCommand;
36+
import seedu.address.logic.commands.ViewCommand;
3637
import seedu.address.logic.parser.exceptions.ParseException;
3738
import seedu.address.model.ModelManager;
3839
import seedu.address.model.UserPrefs;
@@ -124,6 +125,15 @@ public void parseCommand_filter() throws Exception {
124125
assertEquals(new FilterCommand(new PersonContainsKeywordsPredicate(aMM)), command);
125126
}
126127

128+
@Test
129+
public void parseCommand_view() throws Exception {
130+
String input = "1";
131+
ClientId clientId = new ClientId(input);
132+
ViewCommand command = (ViewCommand) parser.parseCommand(
133+
ViewCommand.COMMAND_WORD + " " + input);
134+
assertEquals(new ViewCommand(clientId, new PersonHasId(clientId)), command);
135+
}
136+
127137
@Test
128138
public void parseCommand_help() throws Exception {
129139
assertTrue(parser.parseCommand(HelpCommand.COMMAND_WORD) instanceof HelpCommand);

src/test/java/seedu/address/model/ModelManagerTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException
9696
assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredPersonList().remove(0));
9797
}
9898

99+
@Test
100+
public void test_isPersonExistToView() {
101+
// predicate returns empty list -> false
102+
AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build();
103+
UserPrefs userPrefs = new UserPrefs();
104+
modelManager = new ModelManager(addressBook, userPrefs);
105+
modelManager.updatePersonToView(new PersonHasId(CARL.getClientId()));
106+
assertFalse(modelManager.isPersonExistToView());
107+
108+
// predicate returns 1 person in list -> true
109+
modelManager.updatePersonToView(new PersonHasId(ALICE.getClientId()));
110+
assertTrue(modelManager.isPersonExistToView());
111+
}
112+
99113
@Test
100114
public void getPersonToView_viewFirstClient_returnsTrue() {
101115
AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package seedu.address.model.person;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
import static seedu.address.testutil.Assert.assertThrows;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
public class ClientIdTest {
10+
11+
@Test
12+
public void constructor_null_throwsNullPointerException() {
13+
assertThrows(NullPointerException.class, () -> new ClientId(null));
14+
}
15+
16+
@Test
17+
public void constructor_invalidCurrentPlan_throwsIllegalArgumentException() {
18+
String invalidClientId = " ";
19+
assertThrows(IllegalArgumentException.class, () -> new ClientId(invalidClientId));
20+
}
21+
22+
@Test
23+
public void isClientId() {
24+
// null input
25+
assertThrows(NullPointerException.class, () -> ClientId.isValidClientId(null));
26+
27+
// invalid client id
28+
assertFalse(ClientId.isValidClientId(" ")); // spaces only
29+
assertFalse(ClientId.isValidClientId("-1")); // negative int
30+
31+
// valid client id
32+
assertTrue(ClientId.isValidClientId("0")); // zero
33+
assertTrue(ClientId.isValidClientId("12345")); // any positive int
34+
}
35+
36+
@Test
37+
public void isEqual() {
38+
String input1 = "1";
39+
String input2 = "2";
40+
ClientId clientA = new ClientId(input1);
41+
ClientId clientB = new ClientId(input2);
42+
ClientId clientC = new ClientId(input1);
43+
44+
// same value
45+
assertTrue(clientA.equals(clientA));
46+
assertTrue(clientA.equals(clientC));
47+
48+
// different value
49+
assertFalse(clientA.equals(clientB));
50+
}
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package seedu.address.model.person;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import seedu.address.testutil.PersonBuilder;
9+
10+
public class PersonHasIdTest {
11+
12+
@Test
13+
public void equals() {
14+
String input1 = "1";
15+
String input2 = "2";
16+
ClientId clientA = new ClientId(input1);
17+
ClientId clientB = new ClientId(input2);
18+
19+
PersonHasId firstPredicate = new PersonHasId(clientA);
20+
PersonHasId secondPredicate = new PersonHasId(clientB);
21+
22+
// same object -> returns true
23+
assertTrue(firstPredicate.equals(firstPredicate));
24+
25+
// same values -> returns true
26+
PersonHasId firstPredicateCopy = new PersonHasId(clientA);
27+
assertTrue(firstPredicate.equals(firstPredicateCopy));
28+
29+
// different types -> returns false
30+
assertFalse(firstPredicate.equals(1));
31+
32+
// null -> returns false
33+
assertFalse(firstPredicate.equals(null));
34+
35+
// different person -> returns false
36+
assertFalse(firstPredicate.equals(secondPredicate));
37+
}
38+
39+
@Test
40+
public void test_clientIdMatches_returnsTrue() {
41+
// Same client id
42+
PersonHasId predicate = new PersonHasId(new ClientId("1"));
43+
assertTrue(predicate.test(new PersonBuilder().withClientId("1").build()));
44+
}
45+
46+
@Test
47+
public void test_clientIdMatches_returnsFalse() {
48+
// different client id
49+
PersonHasId predicate = new PersonHasId(new ClientId("0"));
50+
assertFalse(predicate.test(new PersonBuilder().withClientId("1").build()));
51+
}
52+
}

0 commit comments

Comments
 (0)