Skip to content

Commit

Permalink
Added more tests. Fixed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletRedMan committed Mar 6, 2024
1 parent 62f71cb commit 5e7976e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void remove(Room room) {

synchronized (node2roomsMap) {
if (node.isEmpty()) {
throw new IllegalArgumentException("Node '" + nodeId + "' does not exist");
throw new NodeNotFoundException("Node '" + nodeId + "' does not exist");
}

node2roomsMap.get(node.get()).remove(room.getId());
Expand All @@ -67,7 +67,7 @@ public void remove(Room room) {
public Optional<Room> find(Node node, String identifier) {
synchronized (node2roomsMap) {
if (!node2roomsMap.containsKey(node)) {
throw new IllegalArgumentException("Node '" + node.id() + "' does not exist");
throw new NodeNotFoundException("Node '" + node.id() + "' does not exist");
}

var result = node2roomsMap.get(node).getOrDefault(identifier, null);
Expand All @@ -90,7 +90,7 @@ public List<Room> all(Node node) {
public Optional<Room> pickFree(Node node, Collection<User> users) {
synchronized (node2roomsMap) {
if (!node2roomsMap.containsKey(node)) {
throw new IllegalArgumentException("Node '" + node.id() + "' does not exist");
throw new NodeNotFoundException("Node '" + node.id() + "' does not exist");
}

Room room = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ void test_removeNode() {

Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.all(node));
}

@Test
void test_nodeDoesNotExists() {
var node = new Node("Bruh", PickingMode.ROUND_ROBIN, false);
var room = Room.create("test", node, SlotLimit.unlimited(), "", false);

Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.create(room));
Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.remove(room));
Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.find(node, "Bruh"));
Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.pickAvailable(node, List.of(new User("1"))));
}
}

0 comments on commit 5e7976e

Please sign in to comment.