diff --git a/.vscode/settings.json b/.vscode/settings.json index 050505ce79e..b2d807b9cd0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } diff --git a/src/main/java/swift/model/bridge/PersonTaskBridgeList.java b/src/main/java/swift/model/bridge/PersonTaskBridgeList.java index 76bcec87031..fe9a1527b34 100644 --- a/src/main/java/swift/model/bridge/PersonTaskBridgeList.java +++ b/src/main/java/swift/model/bridge/PersonTaskBridgeList.java @@ -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. @@ -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); } @@ -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(); } } @@ -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())); } @@ -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())); } @@ -94,7 +94,7 @@ public Iterator 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 diff --git a/src/main/java/swift/model/bridge/exceptions/BridgeNotFoundException.java b/src/main/java/swift/model/bridge/exceptions/BridgeNotFoundException.java new file mode 100644 index 00000000000..9372473a620 --- /dev/null +++ b/src/main/java/swift/model/bridge/exceptions/BridgeNotFoundException.java @@ -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 { +} diff --git a/src/main/java/swift/model/bridge/exceptions/DuplicateBridgeException.java b/src/main/java/swift/model/bridge/exceptions/DuplicateBridgeException.java new file mode 100644 index 00000000000..0a33735fbf0 --- /dev/null +++ b/src/main/java/swift/model/bridge/exceptions/DuplicateBridgeException.java @@ -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"); + } +} diff --git a/src/test/java/swift/model/bridge/PersonTaskBridgeListTest.java b/src/test/java/swift/model/bridge/PersonTaskBridgeListTest.java index bc846bbc4f2..99ba54ebb45 100644 --- a/src/test/java/swift/model/bridge/PersonTaskBridgeListTest.java +++ b/src/test/java/swift/model/bridge/PersonTaskBridgeListTest.java @@ -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 @@ -25,13 +23,13 @@ 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 @@ -39,6 +37,56 @@ 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