Browse Source

Add tests for EventPropertyManager.

pull/119/head
Chris Smith 9 years ago
parent
commit
d48b9e9f4b
1 changed files with 76 additions and 0 deletions
  1. 76
    0
      test/com/dmdirc/ui/messages/EventPropertyManagerTest.java

+ 76
- 0
test/com/dmdirc/ui/messages/EventPropertyManagerTest.java View File

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.ui.messages;
24
+
25
+import com.dmdirc.Channel;
26
+import com.dmdirc.DMDircMBassador;
27
+import com.dmdirc.events.ChannelMessageEvent;
28
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
29
+
30
+import org.junit.Before;
31
+import org.junit.Test;
32
+import org.junit.runner.RunWith;
33
+import org.mockito.Mock;
34
+import org.mockito.runners.MockitoJUnitRunner;
35
+
36
+import static org.junit.Assert.assertEquals;
37
+import static org.junit.Assert.assertFalse;
38
+import static org.junit.Assert.assertSame;
39
+
40
+@RunWith(MockitoJUnitRunner.class)
41
+public class EventPropertyManagerTest {
42
+
43
+    private EventPropertyManager manager;
44
+
45
+    @Mock private DMDircMBassador eventBus;
46
+    @Mock private Channel channel;
47
+    @Mock private ChannelClientInfo client;
48
+
49
+    @Before
50
+    public void setUp() {
51
+        manager = new EventPropertyManager(eventBus);
52
+    }
53
+
54
+    @Test
55
+    public void testAppliesBuiltInFunctions() {
56
+        assertEquals("test 123", manager.applyFunction("TeSt 123", "lowercase"));
57
+        assertEquals("TEST 123", manager.applyFunction("TeSt 123", "uppercase"));
58
+        assertEquals("TeSt 123", manager.applyFunction("  TeSt 123  ", "trim"));
59
+    }
60
+
61
+    @Test
62
+    public void testGetsProperties() {
63
+        final String message = "a message";
64
+        final ChannelMessageEvent event = new ChannelMessageEvent(channel, client, message);
65
+
66
+        assertSame(message, manager.getProperty(event, ChannelMessageEvent.class, "message").get());
67
+        assertSame(channel, manager.getProperty(event, ChannelMessageEvent.class, "channel").get());
68
+        assertSame(client, manager.getProperty(event, ChannelMessageEvent.class, "client").get());
69
+    }
70
+
71
+    @Test
72
+    public void testNonExistantProperties() {
73
+        assertFalse(manager.getProperty(new Object(), Object.class, "foobar").isPresent());
74
+    }
75
+
76
+}

Loading…
Cancel
Save