summaryrefslogtreecommitdiff
path: root/src/test/java/ChannelNodeTest.java
blob: 5623d729e66faa49800423c79bd53298bd9fc509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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