Pārlūkot izejas kodu

Add a few more tests.

pull/33/head
Chris Smith 9 gadus atpakaļ
vecāks
revīzija
787f8c78b3

+ 133
- 0
test/com/dmdirc/util/collections/QueuedLinkedHashSetTest.java Parādīt failu

@@ -0,0 +1,133 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.collections;
24
+
25
+import java.util.NoSuchElementException;
26
+
27
+import org.junit.Before;
28
+import org.junit.Test;
29
+
30
+import static org.junit.Assert.assertEquals;
31
+import static org.junit.Assert.assertFalse;
32
+import static org.junit.Assert.assertNull;
33
+import static org.junit.Assert.assertTrue;
34
+
35
+public class QueuedLinkedHashSetTest {
36
+
37
+    private QueuedLinkedHashSet<String> set;
38
+
39
+    @Before
40
+    public void setup() {
41
+        set = new QueuedLinkedHashSet<>();
42
+    }
43
+
44
+    @Test(expected = NoSuchElementException.class)
45
+    public void testElementWhenNewlyCreated() {
46
+        set.element();
47
+    }
48
+
49
+    @Test(expected = NoSuchElementException.class)
50
+    public void testElementWhenEmpty() {
51
+        set.offer("foo");
52
+        set.remove();
53
+        set.element();
54
+    }
55
+
56
+    @Test(expected = NoSuchElementException.class)
57
+    public void testRemoveWhenNewlyCreated() {
58
+        set.remove();
59
+    }
60
+
61
+    @Test(expected = NoSuchElementException.class)
62
+    public void testRemoveWhenEmpty() {
63
+        set.offer("foo");
64
+        set.remove();
65
+        set.remove();
66
+    }
67
+
68
+    @Test
69
+    public void testOfferMultipleItems() {
70
+        assertTrue(set.offer("one"));
71
+        assertEquals(1, set.size());
72
+        assertFalse(set.offer("one"));
73
+        assertEquals(1, set.size());
74
+    }
75
+
76
+    @Test
77
+    public void testRemove() {
78
+        set.offer("one");
79
+        set.offer("two");
80
+        assertEquals("two", set.remove());
81
+        assertEquals("one", set.remove());
82
+        assertTrue(set.isEmpty());
83
+    }
84
+
85
+    @Test
86
+    public void testPoll() {
87
+        set.offer("one");
88
+        set.offer("two");
89
+        assertEquals("two", set.poll());
90
+        assertEquals("one", set.poll());
91
+        assertTrue(set.isEmpty());
92
+    }
93
+
94
+    @Test
95
+    public void testPeekWhenNewlyCreated() {
96
+        assertNull(set.peek());
97
+    }
98
+
99
+    @Test
100
+    public void testPeekWhenEmpty() {
101
+        set.offer("foo");
102
+        set.remove();
103
+        assertNull(set.peek());
104
+    }
105
+
106
+    @Test
107
+    public void testPeek() {
108
+        set.offer("one");
109
+        set.offer("two");
110
+        assertEquals("two", set.peek());
111
+        assertEquals("two", set.peek());
112
+        assertEquals(2, set.size());
113
+    }
114
+
115
+    @Test
116
+    public void testOfferAndMoveExisting() {
117
+        set.offer("one");
118
+        set.offer("two");
119
+        set.offerAndMove("one");
120
+        assertEquals("one", set.peek());
121
+        assertEquals(2, set.size());
122
+    }
123
+
124
+    @Test
125
+    public void testOfferAndMoveNew() {
126
+        set.offer("one");
127
+        set.offer("two");
128
+        set.offerAndMove("three");
129
+        assertEquals("three", set.peek());
130
+        assertEquals(3, set.size());
131
+    }
132
+
133
+}

+ 59
- 0
test/com/dmdirc/util/colours/ColourTest.java Parādīt failu

@@ -0,0 +1,59 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.colours;
24
+
25
+import org.junit.Test;
26
+
27
+import static org.junit.Assert.assertEquals;
28
+import static org.junit.Assert.assertFalse;
29
+import static org.junit.Assert.assertTrue;
30
+import static org.junit.Assume.assumeTrue;
31
+
32
+public class ColourTest {
33
+
34
+    @Test
35
+    public void testGetters() {
36
+        final Colour colour = new Colour(12, 0, 255);
37
+        assertEquals(12, colour.getRed());
38
+        assertEquals(0, colour.getGreen());
39
+        assertEquals(255, colour.getBlue());
40
+    }
41
+
42
+    @Test
43
+    public void testEquals() {
44
+        assertTrue(new Colour(1, 2, 3).equals(new Colour(1, 2, 3)));
45
+        assertTrue(Colour.RED.equals(new Colour(255, 0, 0)));
46
+        assertFalse(new Colour(3, 2, 1).equals(new Colour(1, 2, 3)));
47
+        assertFalse(Colour.RED.equals(new Colour(255, 1, 0)));
48
+    }
49
+
50
+    @Test
51
+    public void testHashcodeSameForEqualColours() {
52
+        assumeTrue(new Colour(1, 2, 3).equals(new Colour(1, 2, 3)));
53
+        assertEquals(new Colour(1, 2, 3).hashCode(), new Colour(1, 2, 3).hashCode());
54
+
55
+        assumeTrue(Colour.RED.equals(new Colour(255, 0, 0)));
56
+        assertEquals(Colour.RED.hashCode(), new Colour(255, 0, 0).hashCode());
57
+    }
58
+
59
+}

Notiek ielāde…
Atcelt
Saglabāt