|
@@ -0,0 +1,91 @@
|
|
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.config.profiles;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.DMDircMBassador;
|
|
26
|
+import com.dmdirc.events.ProfileAddedEvent;
|
|
27
|
+import com.dmdirc.events.ProfileDeletedEvent;
|
|
28
|
+
|
|
29
|
+import org.junit.Before;
|
|
30
|
+import org.junit.Test;
|
|
31
|
+import org.junit.runner.RunWith;
|
|
32
|
+import org.mockito.Mock;
|
|
33
|
+import org.mockito.runners.MockitoJUnitRunner;
|
|
34
|
+
|
|
35
|
+import static junit.framework.TestCase.assertEquals;
|
|
36
|
+import static junit.framework.TestCase.assertFalse;
|
|
37
|
+import static junit.framework.TestCase.assertTrue;
|
|
38
|
+import static org.mockito.Matchers.any;
|
|
39
|
+import static org.mockito.Mockito.reset;
|
|
40
|
+import static org.mockito.Mockito.verify;
|
|
41
|
+
|
|
42
|
+@RunWith(MockitoJUnitRunner.class)
|
|
43
|
+public class ProfileManagerTest {
|
|
44
|
+
|
|
45
|
+ @Mock private DMDircMBassador eventBus;
|
|
46
|
+ @Mock private Profile profile1;
|
|
47
|
+ @Mock private Profile profile2;
|
|
48
|
+
|
|
49
|
+ private ProfileManager instance;
|
|
50
|
+
|
|
51
|
+ @Before
|
|
52
|
+ public void setUp() throws Exception {
|
|
53
|
+ instance = new ProfileManager(eventBus);
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ @Test
|
|
57
|
+ public void testAddProfile() {
|
|
58
|
+ assertTrue(instance.getProfiles().isEmpty());
|
|
59
|
+ instance.addProfile(profile1);
|
|
60
|
+ assertEquals(1, instance.getProfiles().size());
|
|
61
|
+ assertTrue(instance.getProfiles().contains(profile1));
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ @Test
|
|
65
|
+ public void testAddProfile_Event() {
|
|
66
|
+ instance.addProfile(profile1);
|
|
67
|
+ verify(eventBus).publishAsync(any(ProfileAddedEvent.class));
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Test
|
|
71
|
+ public void testDeleteProfile() {
|
|
72
|
+ instance.addProfile(profile1);
|
|
73
|
+ instance.addProfile(profile2);
|
|
74
|
+ assertEquals(2, instance.getProfiles().size());
|
|
75
|
+ assertTrue(instance.getProfiles().contains(profile1));
|
|
76
|
+ assertTrue(instance.getProfiles().contains(profile2));
|
|
77
|
+ instance.deleteProfile(profile2);
|
|
78
|
+ assertEquals(1, instance.getProfiles().size());
|
|
79
|
+ assertTrue(instance.getProfiles().contains(profile1));
|
|
80
|
+ assertFalse(instance.getProfiles().contains(profile2));
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ @Test
|
|
84
|
+ public void testDeleteProfile_Event() {
|
|
85
|
+ instance.addProfile(profile1);
|
|
86
|
+ //Fairly certain this shouldn't be needed, but the any matcher below seems to match the add
|
|
87
|
+ reset(eventBus);
|
|
88
|
+ instance.deleteProfile(profile1);
|
|
89
|
+ verify(eventBus).publishAsync(any(ProfileDeletedEvent.class));
|
|
90
|
+ }
|
|
91
|
+}
|