summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author@syxhe <t.me/syxhe>2025-10-01 19:13:42 -0500
committer@syxhe <t.me/syxhe>2025-10-01 19:13:42 -0500
commitb95b043fd07f8e760b1863ff127bee2b1d2633c9 (patch)
tree86258c3b16e7455cfe9d9c4dfaf8595d4ee5a746 /src
Initial Commit
Diffstat (limited to 'src')
-rw-r--r--src/main/java/IChannelNode.java22
-rw-r--r--src/main/java/ISecrets.java3
-rw-r--r--src/test/java/ChannelNodeTest.java120
3 files changed, 145 insertions, 0 deletions
diff --git a/src/main/java/IChannelNode.java b/src/main/java/IChannelNode.java
new file mode 100644
index 0000000..463f3ac
--- /dev/null
+++ b/src/main/java/IChannelNode.java
@@ -0,0 +1,22 @@
1import java.util.List;
2import java.util.Map;
3
4public interface IChannelNode {
5 enum Direction {
6 INCOMING,
7 OUTGOING,
8 BOTH
9 }
10
11 void setConnections(Map<IChannelNode, Integer> conmap, Direction dir);
12 void addConnection(IChannelNode node, Direction dir);
13 void addConnections(Iterable<IChannelNode> nodes, Direction dir);
14 void removeConnection(IChannelNode node, Direction dir);
15 void removeConnections(Iterable<IChannelNode> nodes, Direction dir);
16 void clearConnections(Direction dir);
17
18 boolean connectionExists(IChannelNode node, Direction dir);
19 Map<IChannelNode, Integer> getIncomingConnections();
20 Map<IChannelNode, Integer> getOutgoingConnections();
21 List<Map<IChannelNode, Integer>> getConnections(Direction dir);
22}
diff --git a/src/main/java/ISecrets.java b/src/main/java/ISecrets.java
new file mode 100644
index 0000000..d936429
--- /dev/null
+++ b/src/main/java/ISecrets.java
@@ -0,0 +1,3 @@
1public interface ISecrets {
2 String getAPIToken();
3}
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