From b95b043fd07f8e760b1863ff127bee2b1d2633c9 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Wed, 1 Oct 2025 19:13:42 -0500 Subject: Initial Commit --- src/test/java/ChannelNodeTest.java | 120 +++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/test/java/ChannelNodeTest.java (limited to 'src/test') diff --git a/src/test/java/ChannelNodeTest.java b/src/test/java/ChannelNodeTest.java new file mode 100644 index 0000000..5623d72 --- /dev/null +++ b/src/test/java/ChannelNodeTest.java @@ -0,0 +1,120 @@ +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +class ChannelNodeTest { + @Test void doesCorrectExceptions() { + // Should throw an error when: + // Invalid constructor argument + // Invalid member function argument + + IChannelNode testNodeA = new ChannelNode(); + IChannelNode testNodeB = new ChannelNode(); + + // Null map should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.BOTH)); + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(new HashMap<>(), null)); + + // Should not throw + assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.INCOMING)); + assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.OUTGOING)); + assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.BOTH)); + + + + // Null endpoint should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.BOTH)); + + // Self endpoint should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.BOTH)); + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeB, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeB.addConnection(testNodeA, null)); + + + + // Null iterable should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.BOTH)); + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeB}), null)); + assertThrows(IllegalArgumentException.class, () -> testNodeB.addConnections(List.of(new IChannelNode[]{testNodeA}), null)); + + // Self endpoint should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.BOTH)); + + + + // Null node should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.BOTH)); + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeB, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeB.removeConnection(testNodeA, null)); + + // Self node should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.BOTH)); + + + + // Null iterable should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.BOTH)); + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{}), null)); + + // Self node should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.BOTH)); + + + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.clearConnections(null)); + + + + // Null node should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, null)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.INCOMING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.OUTGOING)); + assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.BOTH)); + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(testNodeB, null)); + + + + // Null direction should always throw + assertThrows(IllegalArgumentException.class, () -> testNodeA.getConnections(null)); + } + +} // End of ChannelNodeTest \ No newline at end of file -- cgit v1.2.3