|
@@ -22,32 +22,41 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.config.prefs;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.actions.ActionManager;
|
26
|
|
-import com.dmdirc.actions.CoreActionType;
|
|
25
|
+import com.dmdirc.events.ClientPrefsClosedEvent;
|
|
26
|
+import com.dmdirc.events.ClientPrefsOpenedEvent;
|
27
|
27
|
import com.dmdirc.interfaces.ActionListener;
|
28
|
28
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
29
|
29
|
import com.dmdirc.plugins.PluginManager;
|
30
|
30
|
import com.dmdirc.plugins.Service;
|
31
|
31
|
|
|
32
|
+import com.google.common.eventbus.EventBus;
|
|
33
|
+
|
32
|
34
|
import java.util.ArrayList;
|
33
|
35
|
import java.util.List;
|
34
|
36
|
|
35
|
37
|
import org.junit.Before;
|
36
|
38
|
import org.junit.Test;
|
37
|
|
-
|
38
|
|
-import static org.junit.Assert.*;
|
39
|
|
-import static org.mockito.Mockito.*;
|
40
|
|
-
|
|
39
|
+import org.junit.runner.RunWith;
|
|
40
|
+import org.mockito.Mock;
|
|
41
|
+import org.mockito.runners.MockitoJUnitRunner;
|
|
42
|
+
|
|
43
|
+import static org.junit.Assert.assertFalse;
|
|
44
|
+import static org.junit.Assert.assertNotNull;
|
|
45
|
+import static org.junit.Assert.assertNull;
|
|
46
|
+import static org.junit.Assert.assertTrue;
|
|
47
|
+import static org.mockito.Matchers.isA;
|
|
48
|
+import static org.mockito.Mockito.mock;
|
|
49
|
+import static org.mockito.Mockito.verify;
|
|
50
|
+import static org.mockito.Mockito.when;
|
|
51
|
+
|
|
52
|
+@RunWith(MockitoJUnitRunner.class)
|
41
|
53
|
public class PreferencesDialogModelTest {
|
42
|
54
|
|
43
|
|
- private ActionManager actionManager;
|
44
|
|
- private PluginManager pluginManager;
|
|
55
|
+ @Mock private EventBus eventBus;
|
|
56
|
+ @Mock private PluginManager pluginManager;
|
45
|
57
|
|
46
|
58
|
@Before
|
47
|
59
|
public void setup() {
|
48
|
|
- actionManager = mock(ActionManager.class);
|
49
|
|
- pluginManager = mock(PluginManager.class);
|
50
|
|
-
|
51
|
60
|
final List<Service> services = new ArrayList<>();
|
52
|
61
|
final Service tabcompleter = mock(Service.class);
|
53
|
62
|
when(tabcompleter.getName()).thenReturn("tabber");
|
|
@@ -61,7 +70,7 @@ public class PreferencesDialogModelTest {
|
61
|
70
|
AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
|
62
|
71
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
63
|
72
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
64
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
73
|
+ null, null, cm, null, pluginManager, eventBus);
|
65
|
74
|
assertNotNull(pm.getCategory("General"));
|
66
|
75
|
assertNotNull(pm.getCategory("Connection"));
|
67
|
76
|
assertNotNull(pm.getCategory("Messages"));
|
|
@@ -78,7 +87,7 @@ public class PreferencesDialogModelTest {
|
78
|
87
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
79
|
88
|
final PreferencesCategory category = mock(PreferencesCategory.class);
|
80
|
89
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
81
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
90
|
+ null, null, cm, null, pluginManager, eventBus);
|
82
|
91
|
pm.addCategory(category);
|
83
|
92
|
pm.dismiss();
|
84
|
93
|
|
|
@@ -93,7 +102,7 @@ public class PreferencesDialogModelTest {
|
93
|
102
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
94
|
103
|
|
95
|
104
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
96
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
105
|
+ null, null, cm, null, pluginManager, eventBus);
|
97
|
106
|
pm.addCategory(category);
|
98
|
107
|
assertFalse(pm.save());
|
99
|
108
|
|
|
@@ -108,7 +117,7 @@ public class PreferencesDialogModelTest {
|
108
|
117
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
109
|
118
|
|
110
|
119
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
111
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
120
|
+ null, null, cm, null, pluginManager, eventBus);
|
112
|
121
|
pm.addCategory(category);
|
113
|
122
|
assertTrue(pm.save());
|
114
|
123
|
|
|
@@ -121,7 +130,7 @@ public class PreferencesDialogModelTest {
|
121
|
130
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
122
|
131
|
|
123
|
132
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
124
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
133
|
+ null, null, cm, null, pluginManager, eventBus);
|
125
|
134
|
assertNull(pm.getCategory("unittest123"));
|
126
|
135
|
}
|
127
|
136
|
|
|
@@ -131,7 +140,7 @@ public class PreferencesDialogModelTest {
|
131
|
140
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
132
|
141
|
|
133
|
142
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
134
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
143
|
+ null, null, cm, null, pluginManager, eventBus);
|
135
|
144
|
assertNotNull(pm.getCategories());
|
136
|
145
|
assertFalse(pm.getCategories().isEmpty());
|
137
|
146
|
|
|
@@ -146,7 +155,7 @@ public class PreferencesDialogModelTest {
|
146
|
155
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
147
|
156
|
|
148
|
157
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
149
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
158
|
+ null, null, cm, null, pluginManager, eventBus);
|
150
|
159
|
final PreferencesInterface tpi = mock(PreferencesInterface.class);
|
151
|
160
|
|
152
|
161
|
pm.registerSaveListener(tpi);
|
|
@@ -160,9 +169,9 @@ public class PreferencesDialogModelTest {
|
160
|
169
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
161
|
170
|
|
162
|
171
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
163
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
172
|
+ null, null, cm, null, pluginManager, eventBus);
|
164
|
173
|
|
165
|
|
- verify(actionManager).triggerEvent(CoreActionType.CLIENT_PREFS_OPENED, null, pm);
|
|
174
|
+ verify(eventBus).post(isA(ClientPrefsOpenedEvent.class));
|
166
|
175
|
}
|
167
|
176
|
|
168
|
177
|
@Test
|
|
@@ -171,10 +180,10 @@ public class PreferencesDialogModelTest {
|
171
|
180
|
AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
|
172
|
181
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
173
|
182
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
174
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
183
|
+ null, null, cm, null, pluginManager, eventBus);
|
175
|
184
|
pm.close();
|
176
|
185
|
|
177
|
|
- verify(actionManager).triggerEvent(CoreActionType.CLIENT_PREFS_CLOSED, null);
|
|
186
|
+ verify(eventBus).post(isA(ClientPrefsClosedEvent.class));
|
178
|
187
|
}
|
179
|
188
|
|
180
|
189
|
@Test
|
|
@@ -183,7 +192,7 @@ public class PreferencesDialogModelTest {
|
183
|
192
|
when(cm.getOption("domain", "option")).thenReturn("fallback");
|
184
|
193
|
|
185
|
194
|
final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
|
186
|
|
- null, null, cm, null, actionManager, pluginManager);
|
|
195
|
+ null, null, cm, null, pluginManager, eventBus);
|
187
|
196
|
final PreferencesCategory category = mock(PreferencesCategory.class);
|
188
|
197
|
final PreferencesInterface tpi = mock(PreferencesInterface.class);
|
189
|
198
|
when(category.hasObject()).thenReturn(true);
|