-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeTest.java
More file actions
135 lines (109 loc) · 2.92 KB
/
NodeTest.java
File metadata and controls
135 lines (109 loc) · 2.92 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import student.TestCase;
// -------------------------------------------------------------------------
/**
* Tests for the {@link Node} class.
*
* @author karl88
* @author sfbahr
* @version Sep 17, 2014
*/
public class NodeTest
extends TestCase
{
// ~ Fields ................................................................
private Node<String> node1;
private Node<String> node2;
private Node<String> node3;
// ~ Public methods ........................................................
// ----------------------------------------------------------
/**
* Create some new nodes for each test method.
*/
public void setUp()
{
node1 = new Node<String>("node1");
node2 = new Node<String>("node2");
node3 = new Node<String>("node3");
}
// ----------------------------------------------------------
/**
* tests the join() method
*/
public void testJoin()
{
Exception thrown = null;
try
{
node1.join(node2);
node1.join(node2);
}
catch (Exception e)
{
thrown = e;
}
assertTrue(thrown instanceof IllegalStateException);
assertEquals(
"A node is already following this one.",
thrown.getMessage());
assertEquals(node1.next(), node2);
assertEquals(node2.previous(), node1);
thrown = null;
try
{
node1.join(null);
}
catch (Exception e)
{
thrown = e;
}
assertTrue(thrown instanceof IllegalStateException);
thrown = null;
try
{
node1.join(node3);
}
catch (Exception e)
{
thrown = e;
}
assertTrue(thrown instanceof IllegalStateException);
assertEquals(
"A node is already following this one.",
thrown.getMessage());
thrown = null;
try
{
node3.join(node2);
}
catch (Exception e)
{
thrown = e;
}
assertTrue(thrown instanceof IllegalStateException);
assertEquals(
"A node is already preceding the one passed to this method.",
thrown.getMessage());
node1.split();
node2.split();
node3.split();
node1.join(null);
assertNull(node1.next());
}
// ----------------------------------------------------------
/**
* tests the split method
*/
public void testSplit()
{
node1.join(node2.join(node3));
node1.setData("test");
assertEquals("test", node1.data());
node1.split();
assertNull(node1.next());
assertNull(node2.previous());
assertEquals(node2.next(), node3);
assertEquals(node3.previous(), node2);
assertNull(node3.next());
assertNull(node3.split());
}
}