Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2122S1#85 from benedictchuajj/branch-…
Browse files Browse the repository at this point in the history
…Increase-ViewTests

Increase code coverage for view command related classes
  • Loading branch information
benedictchuajj authored Oct 14, 2021
2 parents f67488c + 7bdcb71 commit f491e46
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 6 deletions.
8 changes: 3 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ Address | String | a/
<div markdown="block" class="alert alert-info">

**:information_source: Notes about the command format:**<br>

* When `<attribute>` is given, it means that the any *attribute tag* can be used, with the exception of *client id* in some cases

* In the format for the commands provided, words which are in `UPPERCASE` refers to the `input` that the user must key in

* If the inputs are wrapped in curly brackets `{}`, they are inputs that are related to the preceeding argument tag

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

### Delete particular contact : `delete`

Deletes an existing client from the address book using their either client id or email address identify the client.
Deletes an existing client from the address book using their either client id or email address identify the client.
Both attributes can be given together.

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

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

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

Examples:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public ObservableList<Person> getPersonToView() {

@Override
public boolean isPersonExistToView() {
return personToView.size() == 1 && personToView.get(0) != null;
return personToView.size() == 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.SearchCommand;
import seedu.address.logic.commands.ViewCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
Expand Down Expand Up @@ -124,6 +125,15 @@ public void parseCommand_filter() throws Exception {
assertEquals(new FilterCommand(new PersonContainsKeywordsPredicate(aMM)), command);
}

@Test
public void parseCommand_view() throws Exception {
String input = "1";
ClientId clientId = new ClientId(input);
ViewCommand command = (ViewCommand) parser.parseCommand(
ViewCommand.COMMAND_WORD + " " + input);
assertEquals(new ViewCommand(clientId, new PersonHasId(clientId)), command);
}

@Test
public void parseCommand_help() throws Exception {
assertTrue(parser.parseCommand(HelpCommand.COMMAND_WORD) instanceof HelpCommand);
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/seedu/address/model/ModelManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException
assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredPersonList().remove(0));
}

@Test
public void test_isPersonExistToView() {
// predicate returns empty list -> false
AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build();
UserPrefs userPrefs = new UserPrefs();
modelManager = new ModelManager(addressBook, userPrefs);
modelManager.updatePersonToView(new PersonHasId(CARL.getClientId()));
assertFalse(modelManager.isPersonExistToView());

// predicate returns 1 person in list -> true
modelManager.updatePersonToView(new PersonHasId(ALICE.getClientId()));
assertTrue(modelManager.isPersonExistToView());
}

@Test
public void getPersonToView_viewFirstClient_returnsTrue() {
AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build();
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/seedu/address/model/person/ClientIdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package seedu.address.model.person;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

public class ClientIdTest {

@Test
public void constructor_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new ClientId(null));
}

@Test
public void constructor_invalidCurrentPlan_throwsIllegalArgumentException() {
String invalidClientId = " ";
assertThrows(IllegalArgumentException.class, () -> new ClientId(invalidClientId));
}

@Test
public void isClientId() {
// null input
assertThrows(NullPointerException.class, () -> ClientId.isValidClientId(null));

// invalid client id
assertFalse(ClientId.isValidClientId(" ")); // spaces only
assertFalse(ClientId.isValidClientId("-1")); // negative int

// valid client id
assertTrue(ClientId.isValidClientId("0")); // zero
assertTrue(ClientId.isValidClientId("12345")); // any positive int
}

@Test
public void isEqual() {
String input1 = "1";
String input2 = "2";
ClientId clientA = new ClientId(input1);
ClientId clientB = new ClientId(input2);
ClientId clientC = new ClientId(input1);

// same value
assertTrue(clientA.equals(clientA));
assertTrue(clientA.equals(clientC));

// different value
assertFalse(clientA.equals(clientB));
}
}
52 changes: 52 additions & 0 deletions src/test/java/seedu/address/model/person/PersonHasIdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package seedu.address.model.person;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import seedu.address.testutil.PersonBuilder;

public class PersonHasIdTest {

@Test
public void equals() {
String input1 = "1";
String input2 = "2";
ClientId clientA = new ClientId(input1);
ClientId clientB = new ClientId(input2);

PersonHasId firstPredicate = new PersonHasId(clientA);
PersonHasId secondPredicate = new PersonHasId(clientB);

// same object -> returns true
assertTrue(firstPredicate.equals(firstPredicate));

// same values -> returns true
PersonHasId firstPredicateCopy = new PersonHasId(clientA);
assertTrue(firstPredicate.equals(firstPredicateCopy));

// different types -> returns false
assertFalse(firstPredicate.equals(1));

// null -> returns false
assertFalse(firstPredicate.equals(null));

// different person -> returns false
assertFalse(firstPredicate.equals(secondPredicate));
}

@Test
public void test_clientIdMatches_returnsTrue() {
// Same client id
PersonHasId predicate = new PersonHasId(new ClientId("1"));
assertTrue(predicate.test(new PersonBuilder().withClientId("1").build()));
}

@Test
public void test_clientIdMatches_returnsFalse() {
// different client id
PersonHasId predicate = new PersonHasId(new ClientId("0"));
assertFalse(predicate.test(new PersonBuilder().withClientId("1").build()));
}
}

0 comments on commit f491e46

Please sign in to comment.