diff --git a/app/src/main/java/ru/dragonestia/picker/repository/impl/RoomRepositoryImpl.java b/app/src/main/java/ru/dragonestia/picker/repository/impl/RoomRepositoryImpl.java index e3a349a..caf9193 100644 --- a/app/src/main/java/ru/dragonestia/picker/repository/impl/RoomRepositoryImpl.java +++ b/app/src/main/java/ru/dragonestia/picker/repository/impl/RoomRepositoryImpl.java @@ -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()); @@ -67,7 +67,7 @@ public void remove(Room room) { public Optional 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); @@ -90,7 +90,7 @@ public List all(Node node) { public Optional pickFree(Node node, Collection 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; diff --git a/app/src/test/java/ru/dragonestia/picker/service/RoomServiceTests.java b/app/src/test/java/ru/dragonestia/picker/service/RoomServiceTests.java index c0e2c8e..aa227a1 100644 --- a/app/src/test/java/ru/dragonestia/picker/service/RoomServiceTests.java +++ b/app/src/test/java/ru/dragonestia/picker/service/RoomServiceTests.java @@ -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")))); + } }