|
@@ -33,10 +33,12 @@ import com.dmdirc.events.QueryMessageEvent;
|
33
|
33
|
import com.dmdirc.events.ServerConnectedEvent;
|
34
|
34
|
import com.dmdirc.events.ServerInviteReceivedEvent;
|
35
|
35
|
import com.dmdirc.events.ServerNoticeEvent;
|
|
36
|
+import com.dmdirc.events.UserInfoResponseEvent;
|
36
|
37
|
import com.dmdirc.interfaces.Connection;
|
37
|
38
|
import com.dmdirc.interfaces.User;
|
38
|
39
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
39
|
40
|
import com.dmdirc.interfaces.config.ConfigProvider;
|
|
41
|
+import com.dmdirc.parser.events.UserInfoEvent;
|
40
|
42
|
import com.dmdirc.plugins.PluginInfo;
|
41
|
43
|
import com.dmdirc.plugins.PluginMetaData;
|
42
|
44
|
|
|
@@ -54,6 +56,7 @@ import static org.junit.Assert.assertTrue;
|
54
|
56
|
import static org.mockito.Matchers.anyString;
|
55
|
57
|
import static org.mockito.Mockito.never;
|
56
|
58
|
import static org.mockito.Mockito.verify;
|
|
59
|
+import static org.mockito.Mockito.verifyNoMoreInteractions;
|
57
|
60
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
58
|
61
|
import static org.mockito.Mockito.when;
|
59
|
62
|
|
|
@@ -79,6 +82,7 @@ public class QAuthManagerTest {
|
79
|
82
|
@Mock private Invite invite;
|
80
|
83
|
@Mock private Connection connection;
|
81
|
84
|
@Mock private PreferencesCategory preferencesCategory;
|
|
85
|
+ @Mock private UserInfoResponseEvent userInfoResponseEvent;
|
82
|
86
|
@Captor private ArgumentCaptor<PreferencesCategory> preferencesCategoryArgumentCaptor;
|
83
|
87
|
private QAuthManager instance;
|
84
|
88
|
|
|
@@ -107,6 +111,7 @@ public class QAuthManagerTest {
|
107
|
111
|
when(preferencesDialogModel.getConfigManager()).thenReturn(aggregateConfigProvider);
|
108
|
112
|
when(preferencesDialogModel.getIdentity()).thenReturn(configProvider);
|
109
|
113
|
when(preferencesDialogModel.getCategory("Plugins")).thenReturn(preferencesCategory);
|
|
114
|
+ when(userInfoResponseEvent.getConnection()).thenReturn(connection);
|
110
|
115
|
instance = new QAuthManager("pluginDomain", pluginInfo, config, eventBus);
|
111
|
116
|
|
112
|
117
|
instance.handleUsername("username");
|
|
@@ -256,5 +261,31 @@ public class QAuthManagerTest {
|
256
|
261
|
assertTrue(preferencesCategoryArgumentCaptor.getValue().getSettings().size() > 1);
|
257
|
262
|
}
|
258
|
263
|
|
259
|
|
- // TODO: Test ServerNumericEvent method
|
|
264
|
+ @Test
|
|
265
|
+ public void testWhoisReply_NotWaiting() throws Exception {
|
|
266
|
+ instance.handleUserInfoResponse(userInfoResponseEvent);
|
|
267
|
+ verifyNoMoreInteractions(connection);
|
|
268
|
+ }
|
|
269
|
+
|
|
270
|
+ @Test
|
|
271
|
+ public void testWhoisReply_Waiting_Authed() throws Exception {
|
|
272
|
+ when(userInfoResponseEvent.getInfo(UserInfoEvent.UserInfoType.ACCOUNT_NAME))
|
|
273
|
+ .thenReturn(Optional.of("RAR"));
|
|
274
|
+ when(userInfoResponseEvent.getUser()).thenReturn(localUser);
|
|
275
|
+ instance.handleWhois(true);
|
|
276
|
+ instance.handleConnect(serverConnectedEvent);
|
|
277
|
+ instance.handleUserInfoResponse(userInfoResponseEvent);
|
|
278
|
+ verify(connection, never()).sendMessage(anyString(), anyString());
|
|
279
|
+ }
|
|
280
|
+
|
|
281
|
+ @Test
|
|
282
|
+ public void testWhoisReply_Waiting_NotAuthed() throws Exception {
|
|
283
|
+ when(userInfoResponseEvent.getInfo(UserInfoEvent.UserInfoType.ACCOUNT_NAME))
|
|
284
|
+ .thenReturn(Optional.empty());
|
|
285
|
+ when(userInfoResponseEvent.getUser()).thenReturn(localUser);
|
|
286
|
+ instance.handleWhois(true);
|
|
287
|
+ instance.handleConnect(serverConnectedEvent);
|
|
288
|
+ instance.handleUserInfoResponse(userInfoResponseEvent);
|
|
289
|
+ verify(connection).sendMessage(anyString(), anyString());
|
|
290
|
+ }
|
260
|
291
|
}
|