Browse Source

Add some super basic OutputQueue tests.

pull/134/head
Chris Smith 7 years ago
parent
commit
d00ce697b5

+ 76
- 0
irc/src/test/java/com/dmdirc/parser/irc/outputqueue/PriorityOutputQueueTest.java View File

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2016 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.parser.irc.outputqueue;
24
+
25
+import com.dmdirc.parser.common.QueuePriority;
26
+import org.junit.Before;
27
+import org.junit.Test;
28
+
29
+import java.io.BufferedOutputStream;
30
+import java.io.BufferedReader;
31
+import java.io.IOException;
32
+import java.io.InputStreamReader;
33
+import java.io.PipedInputStream;
34
+import java.io.PipedOutputStream;
35
+
36
+import static org.junit.Assert.assertEquals;
37
+
38
+public class PriorityOutputQueueTest {
39
+
40
+    private BufferedReader reader;
41
+    private BufferedOutputStream outputStream;
42
+    private PriorityOutputQueue outputQueue;
43
+
44
+    @Before
45
+    public void setup() throws IOException {
46
+        PipedInputStream pipeInput = new PipedInputStream();
47
+        reader = new BufferedReader(new InputStreamReader(pipeInput));
48
+        outputStream = new BufferedOutputStream(new PipedOutputStream(pipeInput));
49
+        outputQueue = new PriorityOutputQueue();
50
+    }
51
+
52
+    @Test(expected = IllegalStateException.class)
53
+    public void testThrowsIfOutputStreamNotSet() {
54
+        outputQueue.sendLine("testing", QueuePriority.IMMEDIATE);
55
+    }
56
+
57
+    @Test
58
+    public void testSendsLinesToOutput() throws IOException {
59
+        outputQueue.setOutputStream(outputStream);
60
+        outputQueue.sendLine("test 123");
61
+        outputQueue.sendLine("456...");
62
+        assertEquals("test 123", reader.readLine());
63
+        assertEquals("456...", reader.readLine());
64
+    }
65
+
66
+    @Test
67
+    public void testDiscarding() throws IOException {
68
+        outputQueue.setOutputStream(outputStream);
69
+        outputQueue.setDiscarding(true);
70
+        outputQueue.sendLine("test 123");
71
+        outputQueue.setDiscarding(false);
72
+        outputQueue.sendLine("456...");
73
+        assertEquals("456...", reader.readLine());
74
+    }
75
+
76
+}

Loading…
Cancel
Save