summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/ChannelNodeTest.java120
1 files changed, 120 insertions, 0 deletions
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 @@
1import static org.junit.jupiter.api.Assertions.*;
2import org.junit.jupiter.api.Test;
3
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8class ChannelNodeTest {
9 @Test void doesCorrectExceptions() {
10 // Should throw an error when:
11 // Invalid constructor argument
12 // Invalid member function argument
13
14 IChannelNode testNodeA = new ChannelNode();
15 IChannelNode testNodeB = new ChannelNode();
16
17 // Null map should always throw
18 assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, null));
19 assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.INCOMING));
20 assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.OUTGOING));
21 assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.BOTH));
22
23 // Null direction should always throw
24 assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(new HashMap<>(), null));
25
26 // Should not throw
27 assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.INCOMING));
28 assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.OUTGOING));
29 assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.BOTH));
30
31
32
33 // Null endpoint should always throw
34 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, null));
35 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.INCOMING));
36 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.OUTGOING));
37 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.BOTH));
38
39 // Self endpoint should always throw
40 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.INCOMING));
41 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.OUTGOING));
42 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.BOTH));
43
44 // Null direction should always throw
45 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeB, null));
46 assertThrows(IllegalArgumentException.class, () -> testNodeB.addConnection(testNodeA, null));
47
48
49
50 // Null iterable should always throw
51 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, null));
52 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.INCOMING));
53 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.OUTGOING));
54 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.BOTH));
55
56 // Null direction should always throw
57 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeB}), null));
58 assertThrows(IllegalArgumentException.class, () -> testNodeB.addConnections(List.of(new IChannelNode[]{testNodeA}), null));
59
60 // Self endpoint should always throw
61 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.INCOMING));
62 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.OUTGOING));
63 assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.BOTH));
64
65
66
67 // Null node should always throw
68 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, null));
69 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.INCOMING));
70 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.OUTGOING));
71 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.BOTH));
72
73 // Null direction should always throw
74 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeB, null));
75 assertThrows(IllegalArgumentException.class, () -> testNodeB.removeConnection(testNodeA, null));
76
77 // Self node should always throw
78 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.INCOMING));
79 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.OUTGOING));
80 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.BOTH));
81
82
83
84 // Null iterable should always throw
85 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, null));
86 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.INCOMING));
87 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.OUTGOING));
88 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.BOTH));
89
90 // Null direction should always throw
91 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{}), null));
92
93 // Self node should always throw
94 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.INCOMING));
95 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.OUTGOING));
96 assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.BOTH));
97
98
99
100 // Null direction should always throw
101 assertThrows(IllegalArgumentException.class, () -> testNodeA.clearConnections(null));
102
103
104
105 // Null node should always throw
106 assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, null));
107 assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.INCOMING));
108 assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.OUTGOING));
109 assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.BOTH));
110
111 // Null direction should always throw
112 assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(testNodeB, null));
113
114
115
116 // Null direction should always throw
117 assertThrows(IllegalArgumentException.class, () -> testNodeA.getConnections(null));
118 }
119
120} // End of ChannelNodeTest \ No newline at end of file