Skip to content

Commit

Permalink
Chore: add PersonTaskBridgeList tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peppapighs committed Oct 16, 2022
1 parent 9b58115 commit d2bad62
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
"java.configuration.updateBuildConfiguration": "interactive",
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
}
14 changes: 7 additions & 7 deletions src/main/java/swift/model/bridge/PersonTaskBridgeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import swift.model.bridge.exceptions.BridgeNotFoundException;
import swift.model.bridge.exceptions.DuplicateBridgeException;
import swift.model.person.Person;
import swift.model.task.Task;
import swift.model.task.exceptions.DuplicateTaskException;
import swift.model.task.exceptions.TaskNotFoundException;

/**
* Represents a list of person-task bridges.
Expand Down Expand Up @@ -40,7 +40,7 @@ public boolean contains(PersonTaskBridge toCheck) {
public void add(PersonTaskBridge toAdd) {
requireNonNull(toAdd);
if (contains(toAdd)) {
throw new DuplicateTaskException();
throw new DuplicateBridgeException();
}
internalList.add(toAdd);
}
Expand All @@ -54,7 +54,7 @@ public void add(PersonTaskBridge toAdd) {
public void remove(PersonTaskBridge toRemove) {
requireNonNull(toRemove);
if (!internalList.remove(toRemove)) {
throw new TaskNotFoundException();
throw new BridgeNotFoundException();
}
}

Expand All @@ -63,7 +63,7 @@ public void remove(PersonTaskBridge toRemove) {
*
* @param person The person whose person-task bridges are to be removed.
*/
public void remove(Person person) {
public void removePerson(Person person) {
requireNonNull(person);
internalList.removeIf(bridge -> bridge.getPersonId().equals(person.getId()));
}
Expand All @@ -73,7 +73,7 @@ public void remove(Person person) {
*
* @param task The task whose person-task bridges are to be removed.
*/
public void remove(Task task) {
public void removeTask(Task task) {
requireNonNull(task);
internalList.removeIf(bridge -> bridge.getTaskId().equals(task.getId()));
}
Expand All @@ -94,7 +94,7 @@ public Iterator<PersonTaskBridge> iterator() {
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof PersonTaskBridgeList // instanceof handles nulls
&& internalList.equals(((PersonTaskBridgeList) other).internalList));
&& internalList.equals(((PersonTaskBridgeList) other).internalList));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package swift.model.bridge.exceptions;

/**
* Signals that the operation is unable to find the specified bridge.
*/
public class BridgeNotFoundException extends RuntimeException {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package swift.model.bridge.exceptions;

/**
* Signals that the operation will result in duplicate PersonTaskBridge
* (PersonTaskBridge are
* considered duplicates if they have the same
* person ID and task ID).
*/
public class DuplicateBridgeException extends RuntimeException {
public DuplicateBridgeException() {
super("Operation would result in duplicate bridges");
}
}
66 changes: 57 additions & 9 deletions src/test/java/swift/model/bridge/PersonTaskBridgeListTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package swift.model.bridge;

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 swift.testutil.Assert.assertThrows;

import java.util.UUID;

import org.junit.jupiter.api.Test;

import swift.model.bridge.exceptions.BridgeNotFoundException;
import swift.model.bridge.exceptions.DuplicateBridgeException;
import swift.testutil.PersonBuilder;
import swift.testutil.TaskBuilder;
import swift.testutil.TypicalBridges;

public class PersonTaskBridgeListTest {
private static final PersonTaskBridge DEFAULT_BRIDGE = new PersonTaskBridge(
UUID.fromString(PersonBuilder.DEFAULT_UUID),
UUID.fromString(TaskBuilder.DEFAULT_ID));

private final PersonTaskBridgeList bridges = new PersonTaskBridgeList();

@Test
Expand All @@ -25,20 +23,70 @@ public void contains_nullBridge_throwsNullPointerException() {

@Test
public void contains_bridgeNotInList_returnsFalse() {
assertFalse(bridges.contains(DEFAULT_BRIDGE));
assertFalse(bridges.contains(TypicalBridges.DEFAULT_BRIDGE_1));
}

@Test
public void contains_bridgeInList_returnsTrue() {
bridges.add(DEFAULT_BRIDGE);
assertTrue(bridges.contains(DEFAULT_BRIDGE));
bridges.add(TypicalBridges.DEFAULT_BRIDGE_1);
assertTrue(bridges.contains(TypicalBridges.DEFAULT_BRIDGE_1));
}

@Test
public void add_nullBridge_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> bridges.add(null));
}

@Test
public void add_duplicateTask_throwsDuplicateBridgeException() {
bridges.add(TypicalBridges.DEFAULT_BRIDGE_1);
assertThrows(DuplicateBridgeException.class, () -> bridges.add(TypicalBridges.DEFAULT_BRIDGE_1));
}

@Test
public void remove_nullBridge_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> bridges.remove(null));
}

@Test
public void remove_bridgeNotInList_throwsBridgeNotFoundException() {
assertThrows(BridgeNotFoundException.class, () -> bridges.remove(TypicalBridges.DEFAULT_BRIDGE_1));
}

@Test
public void remove_existingBridge_removesBridge() {
bridges.add(TypicalBridges.DEFAULT_BRIDGE_1);
bridges.remove(TypicalBridges.DEFAULT_BRIDGE_1);
PersonTaskBridgeList expectedUniqueBridgeList = new PersonTaskBridgeList();
assertEquals(bridges, expectedUniqueBridgeList);
}

@Test
public void removePerson_nullPerson_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> bridges.removePerson(null));
}

@Test
public void removePerson_existingBridge_removesBridge() {
bridges.add(TypicalBridges.DEFAULT_BRIDGE_1);
bridges.removePerson(new PersonBuilder().withId("c4c645da-27b3-454d-9428-5295a6ee1f33").build());
PersonTaskBridgeList expectedUniqueBridgeList = new PersonTaskBridgeList();
assertEquals(bridges, expectedUniqueBridgeList);
}

@Test
public void removeTask_nullTask_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> bridges.removeTask(null));
}

@Test
public void removeTask_existingBridge_removesBridge() {
bridges.add(TypicalBridges.DEFAULT_BRIDGE_1);
bridges.removeTask(new TaskBuilder().withId("bfbf250c-fd58-49b4-be15-ca12095ca2ee").build());
PersonTaskBridgeList expectedUniqueBridgeList = new PersonTaskBridgeList();
assertEquals(bridges, expectedUniqueBridgeList);
}

@Test
public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() {
assertThrows(UnsupportedOperationException.class, () -> bridges
Expand Down

0 comments on commit d2bad62

Please sign in to comment.