Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
UniquePersonListTest: add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pyokagan committed Aug 8, 2018
1 parent d14889b commit 42def33
Showing 1 changed file with 156 additions and 1 deletion.
157 changes: 156 additions & 1 deletion src/test/java/seedu/address/model/UniquePersonListTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,173 @@
package seedu.address.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BOB;

import java.util.Arrays;
import java.util.List;

import org.assertj.core.internal.bytebuddy.implementation.bind.MethodDelegationBinder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import seedu.address.model.person.Person;
import seedu.address.model.person.UniquePersonList;
import seedu.address.model.person.exceptions.DuplicatePersonException;
import seedu.address.model.person.exceptions.PersonNotFoundException;
import seedu.address.testutil.PersonBuilder;

public class UniquePersonListTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

private final UniquePersonList uniquePersonList = new UniquePersonList();

@Test
public void contains_nullPerson_throwsNullPointerException() {
thrown.expect(NullPointerException.class);
uniquePersonList.contains(null);
}

@Test
public void contains_personNotInList_returnsFalse() {
assertFalse(uniquePersonList.contains(ALICE));
}

@Test
public void contains_personInList_returnsTrue() {
uniquePersonList.add(ALICE);
assertTrue(uniquePersonList.contains(ALICE));
}

@Test
public void contains_personWithSameIdentityFieldsInList_returnsTrue() {
uniquePersonList.add(ALICE);
Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
.build();
assertTrue(uniquePersonList.contains(editedAlice));
}

@Test
public void setPerson_nullTargetPerson_throwsNullPointerException() {
thrown.expect(NullPointerException.class);
uniquePersonList.setPerson(null, ALICE);
}

@Test
public void setPerson_nullEditedPerson_throwsNullPointerException() {
thrown.expect(NullPointerException.class);
uniquePersonList.setPerson(ALICE, null);
}

@Test
public void setPerson_targetPersonNotInList_throwsPersonNotFoundException() {
thrown.expect(PersonNotFoundException.class);
uniquePersonList.setPerson(ALICE, ALICE);
}

@Test
public void setPerson_editedPersonIsSamePerson_success() {
uniquePersonList.add(ALICE);
uniquePersonList.setPerson(ALICE, ALICE);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(ALICE);
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void setPerson_editedPersonHasSameIdentity_success() {
uniquePersonList.add(ALICE);
Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
.build();
uniquePersonList.setPerson(ALICE, editedAlice);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(editedAlice);
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void setPerson_editedPersonHasDifferentIdentity_success() {
uniquePersonList.add(ALICE);
uniquePersonList.setPerson(ALICE, BOB);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(BOB);
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void setPerson_editedPersonHasNonUniqueIdentity_throwsDuplicatePersonException() {
uniquePersonList.add(ALICE);
uniquePersonList.add(BOB);
thrown.expect(DuplicatePersonException.class);
uniquePersonList.setPerson(ALICE, BOB);
}

@Test
public void remove_nullPerson_throwsNullPointerException() {
thrown.expect(NullPointerException.class);
uniquePersonList.remove(null);
}

@Test
public void remove_personDoesNotExist_throwsPersonNotFoundException() {
thrown.expect(PersonNotFoundException.class);
uniquePersonList.remove(ALICE);
}

@Test
public void remove_existingPerson_removesPerson() {
uniquePersonList.add(ALICE);
uniquePersonList.remove(ALICE);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void setPersons_nullUniquePersonList_throwsNullPointerException() {
thrown.expect(NullPointerException.class);
uniquePersonList.setPersons((UniquePersonList) null);
}

@Test
public void setPersons_uniquePersonList_replacesOwnListWithProvidedUniquePersonList() {
uniquePersonList.add(ALICE);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(BOB);
uniquePersonList.setPersons(expectedUniquePersonList);
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void setPersons_nullList_throwsNullPointerException() {
thrown.expect(NullPointerException.class);
uniquePersonList.setPersons((List<Person>) null);
}

@Test
public void setPersons_list_replacesOwnListWithProvidedList() {
uniquePersonList.add(ALICE);
List<Person> personList = Arrays.asList(BOB);
uniquePersonList.setPersons(personList);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(BOB);
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void setPersons_listWithDuplicatePersons_throwsDuplicatePersonException() {
List<Person> listWithDuplicatePersons = Arrays.asList(ALICE, ALICE);
thrown.expect(DuplicatePersonException.class);
uniquePersonList.setPersons(listWithDuplicatePersons);
}

@Test
public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() {
UniquePersonList uniquePersonList = new UniquePersonList();
thrown.expect(UnsupportedOperationException.class);
uniquePersonList.asUnmodifiableObservableList().remove(0);
}
Expand Down

0 comments on commit 42def33

Please sign in to comment.