Parcourir la source

Fix tests after mockito upgrade.

Mockito now errors if a mock is unnecessary, plus a few other minor
API changes.
pull/714/head
Chris Smith il y a 7 ans
Parent
révision
232ee993d4
21 fichiers modifiés avec 33 ajouts et 147 suppressions
  1. 0
    5
      src/test/java/com/dmdirc/ServerManagerTest.java
  2. 0
    3
      src/test/java/com/dmdirc/commandparser/aliases/AliasCommandHandlerTest.java
  3. 0
    8
      src/test/java/com/dmdirc/commandparser/commands/channel/KickReasonTest.java
  4. 0
    2
      src/test/java/com/dmdirc/commandparser/commands/channel/NamesTest.java
  5. 0
    1
      src/test/java/com/dmdirc/commandparser/commands/chat/MeTest.java
  6. 5
    7
      src/test/java/com/dmdirc/commandparser/commands/global/NewServerTest.java
  7. 0
    1
      src/test/java/com/dmdirc/commandparser/parsers/CommandParserTest.java
  8. 0
    6
      src/test/java/com/dmdirc/config/ConfigValueRetrieverTest.java
  9. 0
    16
      src/test/java/com/dmdirc/config/prefs/PreferencesDialogModelTest.java
  10. 0
    1
      src/test/java/com/dmdirc/config/profiles/IdentitiesProfileMigratorTest.java
  11. 0
    54
      src/test/java/com/dmdirc/harness/CommandArgsMatcher.java
  12. 0
    1
      src/test/java/com/dmdirc/logger/DiskLoggingErrorManagerTest.java
  13. 3
    4
      src/test/java/com/dmdirc/logger/SentryLoggingErrorManagerTest.java
  14. 0
    2
      src/test/java/com/dmdirc/ui/WindowManagerTest.java
  15. 0
    1
      src/test/java/com/dmdirc/ui/core/aliases/CoreAliasDialogModelTest.java
  16. 0
    2
      src/test/java/com/dmdirc/ui/core/aliases/RenameAliasValidatorTest.java
  17. 24
    27
      src/test/java/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModelTest.java
  18. 1
    3
      src/test/java/com/dmdirc/ui/core/profiles/AddNicknameValidatorTest.java
  19. 0
    1
      src/test/java/com/dmdirc/ui/core/profiles/EditSelectedProfileNameValidatorTest.java
  20. 0
    1
      src/test/java/com/dmdirc/ui/core/profiles/NewProfileNameValidatorTest.java
  21. 0
    1
      src/test/java/com/dmdirc/updater/manager/UpdateManagerImplTest.java

+ 0
- 5
src/test/java/com/dmdirc/ServerManagerTest.java Voir le fichier

61
     @Mock private IdentityFactory identityFactory;
61
     @Mock private IdentityFactory identityFactory;
62
     @Mock private ConfigProviderMigrator configProviderMigrator;
62
     @Mock private ConfigProviderMigrator configProviderMigrator;
63
     @Mock private Profile profile;
63
     @Mock private Profile profile;
64
-    @Mock private AggregateConfigProvider configProvider;
65
     @Mock private WindowManager windowManager;
64
     @Mock private WindowManager windowManager;
66
     @Mock private ServerFactoryImpl serverFactoryImpl;
65
     @Mock private ServerFactoryImpl serverFactoryImpl;
67
     @Mock private Server server;
66
     @Mock private Server server;
79
         serverManager = new ServerManager(profileManager, identityFactory, windowManager, serverFactoryImpl, eventBus);
78
         serverManager = new ServerManager(profileManager, identityFactory, windowManager, serverFactoryImpl, eventBus);
80
 
79
 
81
         when(server.getState()).thenReturn(ServerState.DISCONNECTED);
80
         when(server.getState()).thenReturn(ServerState.DISCONNECTED);
82
-        when(server.getGroupChatManager()).thenReturn(groupChatManager);
83
         when(server.getWindowModel()).thenReturn(windowModel);
81
         when(server.getWindowModel()).thenReturn(windowModel);
84
 
82
 
85
-        when(profileManager.getProfiles()).thenReturn(Collections.singletonList(profile));
86
         when(profileManager.getDefault()).thenReturn(profile);
83
         when(profileManager.getDefault()).thenReturn(profile);
87
         when(identityFactory.createMigratableConfig(anyString(), anyString(), anyString(),
84
         when(identityFactory.createMigratableConfig(anyString(), anyString(), anyString(),
88
                 anyString())).thenReturn(configProviderMigrator);
85
                 anyString())).thenReturn(configProviderMigrator);
89
-        when(configProviderMigrator.getConfigProvider()).thenReturn(configProvider);
90
 
86
 
91
         when(serverFactoryImpl.getServer(eq(configProviderMigrator),
87
         when(serverFactoryImpl.getServer(eq(configProviderMigrator),
92
                 any(ScheduledExecutorService.class), uriCaptor.capture(), eq(profile)))
88
                 any(ScheduledExecutorService.class), uriCaptor.capture(), eq(profile)))
194
 
190
 
195
         final Server serverB = mock(Server.class);
191
         final Server serverB = mock(Server.class);
196
         when(serverB.isNetwork("Quakenet")).thenReturn(false);
192
         when(serverB.isNetwork("Quakenet")).thenReturn(false);
197
-        when(serverB.getState()).thenReturn(ServerState.CONNECTED);
198
 
193
 
199
         serverManager.registerServer(serverA);
194
         serverManager.registerServer(serverA);
200
         serverManager.registerServer(serverB);
195
         serverManager.registerServer(serverB);

+ 0
- 3
src/test/java/com/dmdirc/commandparser/aliases/AliasCommandHandlerTest.java Voir le fichier

55
     @Mock private CommandController commandController;
55
     @Mock private CommandController commandController;
56
     @Mock private CommandParser commandParser;
56
     @Mock private CommandParser commandParser;
57
     @Mock private CommandContext context;
57
     @Mock private CommandContext context;
58
-    @Mock private CommandInfo commandInfo;
59
     @Mock private EventBus eventbus;
58
     @Mock private EventBus eventbus;
60
     @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
59
     @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
61
 
60
 
65
         when(inputModel.getCommandParser()).thenReturn(commandParser);
64
         when(inputModel.getCommandParser()).thenReturn(commandParser);
66
         when(commandController.getCommandChar()).thenReturn('#');
65
         when(commandController.getCommandChar()).thenReturn('#');
67
         when(commandController.getSilenceChar()).thenReturn('/');
66
         when(commandController.getSilenceChar()).thenReturn('/');
68
-        when(context.getSource()).thenReturn(container);
69
-        when(context.getCommandInfo()).thenReturn(commandInfo);
70
         when(container.getEventBus()).thenReturn(eventbus);
67
         when(container.getEventBus()).thenReturn(eventbus);
71
     }
68
     }
72
 
69
 

+ 0
- 8
src/test/java/com/dmdirc/commandparser/commands/channel/KickReasonTest.java Voir le fichier

32
 import com.dmdirc.interfaces.GroupChatUser;
32
 import com.dmdirc.interfaces.GroupChatUser;
33
 import com.dmdirc.interfaces.User;
33
 import com.dmdirc.interfaces.User;
34
 import com.dmdirc.interfaces.WindowModel;
34
 import com.dmdirc.interfaces.WindowModel;
35
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
36
-import com.dmdirc.parser.interfaces.ChannelInfo;
37
 
35
 
38
 import java.util.Optional;
36
 import java.util.Optional;
39
 
37
 
61
     @Mock private CommandController controller;
59
     @Mock private CommandController controller;
62
     @Mock private WindowModel container;
60
     @Mock private WindowModel container;
63
     @Mock private EventBus eventbus;
61
     @Mock private EventBus eventbus;
64
-    @Mock private ChannelInfo channelInfo;
65
-    @Mock private AggregateConfigProvider configProvider;
66
     @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
62
     @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
67
     private KickReason command;
63
     private KickReason command;
68
 
64
 
69
     @Before
65
     @Before
70
     public void setup() {
66
     public void setup() {
71
-        when(container.getConfigManager()).thenReturn(configProvider);
72
-        when(configProvider.getOption("general", "kickmessage")).thenReturn("KICKREASON");
73
-        when(channel.getChannelInfo()).thenReturn(channelInfo);
74
         when(channel.getConnection()).thenReturn(Optional.of(connection));
67
         when(channel.getConnection()).thenReturn(Optional.of(connection));
75
         when(connection.getUser("user")).thenReturn(user1);
68
         when(connection.getUser("user")).thenReturn(user1);
76
         when(connection.getUser("user1")).thenReturn(user2);
69
         when(connection.getUser("user1")).thenReturn(user2);
77
-        when(groupChatUser.getHostname()).thenReturn(Optional.of("HOSTNAME"));
78
         when(channel.getUser(user1)).thenReturn(Optional.of(groupChatUser));
70
         when(channel.getUser(user1)).thenReturn(Optional.of(groupChatUser));
79
         when(channel.getUser(user2)).thenReturn(Optional.empty());
71
         when(channel.getUser(user2)).thenReturn(Optional.empty());
80
         when(controller.getCommandChar()).thenReturn('/');
72
         when(controller.getCommandChar()).thenReturn('/');

+ 0
- 2
src/test/java/com/dmdirc/commandparser/commands/channel/NamesTest.java Voir le fichier

46
 public class NamesTest {
46
 public class NamesTest {
47
 
47
 
48
     @Mock private CommandController controller;
48
     @Mock private CommandController controller;
49
-    @Mock private ChannelInfo channelinfo;
50
     @Mock private Channel channel;
49
     @Mock private Channel channel;
51
     @Mock private Connection connection;
50
     @Mock private Connection connection;
52
     @Mock private Parser parser;
51
     @Mock private Parser parser;
57
     public void setUp() throws InvalidIdentityFileException {
56
     public void setUp() throws InvalidIdentityFileException {
58
         when(channel.getConnection()).thenReturn(Optional.of(connection));
57
         when(channel.getConnection()).thenReturn(Optional.of(connection));
59
         when(connection.getParser()).thenReturn(Optional.of(parser));
58
         when(connection.getParser()).thenReturn(Optional.of(parser));
60
-        when(channel.getChannelInfo()).thenReturn(channelinfo);
61
         when(channel.getName()).thenReturn("#chan");
59
         when(channel.getName()).thenReturn("#chan");
62
 
60
 
63
         command = new Names(controller);
61
         command = new Names(controller);

+ 0
- 1
src/test/java/com/dmdirc/commandparser/commands/chat/MeTest.java Voir le fichier

50
 
50
 
51
     @Before
51
     @Before
52
     public void setUp() {
52
     public void setUp() {
53
-        when(chat.getWindowModel()).thenReturn(frameContainer);
54
         when(frameContainer.getEventBus()).thenReturn(eventbus);
53
         when(frameContainer.getEventBus()).thenReturn(eventbus);
55
         command = new Me(controller);
54
         command = new Me(controller);
56
     }
55
     }

+ 5
- 7
src/test/java/com/dmdirc/commandparser/commands/global/NewServerTest.java Voir le fichier

44
 import org.mockito.Mock;
44
 import org.mockito.Mock;
45
 import org.mockito.runners.MockitoJUnitRunner;
45
 import org.mockito.runners.MockitoJUnitRunner;
46
 
46
 
47
+import static org.mockito.ArgumentMatchers.isNull;
47
 import static org.mockito.Matchers.any;
48
 import static org.mockito.Matchers.any;
48
 import static org.mockito.Matchers.eq;
49
 import static org.mockito.Matchers.eq;
49
 import static org.mockito.Matchers.isA;
50
 import static org.mockito.Matchers.isA;
56
     @Mock private EventBus eventBus;
57
     @Mock private EventBus eventBus;
57
     @Mock private CommandController controller;
58
     @Mock private CommandController controller;
58
     @Mock private ProfileManager profileManager;
59
     @Mock private ProfileManager profileManager;
59
-    @Mock private Profile identity;
60
     @Mock private WindowModel container;
60
     @Mock private WindowModel container;
61
     @Mock private ServiceManager serviceManager;
61
     @Mock private ServiceManager serviceManager;
62
     @Mock private ConnectionFactory factory;
62
     @Mock private ConnectionFactory factory;
66
     @Before
66
     @Before
67
     public void setup() {
67
     public void setup() {
68
         when(container.getEventBus()).thenReturn(eventBus);
68
         when(container.getEventBus()).thenReturn(eventBus);
69
-        when(factory.createServer(any(URI.class), any(Profile.class))).thenReturn(connection);
70
-        when(profileManager.getProfiles()).thenReturn(
71
-                Collections.singletonList(identity));
69
+        when(factory.createServer(any(URI.class), isNull())).thenReturn(connection);
72
         command = new NewServer(controller, factory, serviceManager, profileManager, new URIParser());
70
         command = new NewServer(controller, factory, serviceManager, profileManager, new URIParser());
73
     }
71
     }
74
 
72
 
77
         command.execute(container, new CommandArguments(controller, "/foo irc.foo.com"),
75
         command.execute(container, new CommandArguments(controller, "/foo irc.foo.com"),
78
                 new CommandContext(null, NewServer.INFO));
76
                 new CommandContext(null, NewServer.INFO));
79
 
77
 
80
-        verify(factory).createServer(eq(new URI("irc://irc.foo.com")), any(Profile.class));
78
+        verify(factory).createServer(eq(new URI("irc://irc.foo.com")), isNull());
81
         verify(connection).connect();
79
         verify(connection).connect();
82
     }
80
     }
83
 
81
 
86
         command.execute(container, new CommandArguments(controller, "/foo irc.foo.com:1234"),
84
         command.execute(container, new CommandArguments(controller, "/foo irc.foo.com:1234"),
87
                 new CommandContext(null, NewServer.INFO));
85
                 new CommandContext(null, NewServer.INFO));
88
 
86
 
89
-        verify(factory).createServer(eq(new URI("irc://irc.foo.com:1234")), any(Profile.class));
87
+        verify(factory).createServer(eq(new URI("irc://irc.foo.com:1234")), isNull());
90
         verify(connection).connect();
88
         verify(connection).connect();
91
     }
89
     }
92
 
90
 
95
         command.execute(container, new CommandArguments(controller, "/foo otheruri://foo.com:123/blah"),
93
         command.execute(container, new CommandArguments(controller, "/foo otheruri://foo.com:123/blah"),
96
                 new CommandContext(null, NewServer.INFO));
94
                 new CommandContext(null, NewServer.INFO));
97
 
95
 
98
-        verify(factory).createServer(eq(new URI("otheruri://foo.com:123/blah")), any(Profile.class));
96
+        verify(factory).createServer(eq(new URI("otheruri://foo.com:123/blah")), isNull());
99
         verify(connection).connect();
97
         verify(connection).connect();
100
     }
98
     }
101
 
99
 

+ 0
- 1
src/test/java/com/dmdirc/commandparser/parsers/CommandParserTest.java Voir le fichier

81
         when(container.getConnection()).thenReturn(Optional.of(connection));
81
         when(container.getConnection()).thenReturn(Optional.of(connection));
82
         when(connection.getGroupChatManager()).thenReturn(groupChatManager);
82
         when(connection.getGroupChatManager()).thenReturn(groupChatManager);
83
         when(groupChatManager.isValidChannelName("#channel1")).thenReturn(true);
83
         when(groupChatManager.isValidChannelName("#channel1")).thenReturn(true);
84
-        when(groupChatManager.isValidChannelName("#channel2")).thenReturn(true);
85
         when(groupChatManager.getChannel("#channel1")).thenReturn(Optional.of(channel));
84
         when(groupChatManager.getChannel("#channel1")).thenReturn(Optional.of(channel));
86
 
85
 
87
         commandParser = new TestCommandParser(configProvider, commandController, eventBus);
86
         commandParser = new TestCommandParser(configProvider, commandController, eventBus);

+ 0
- 6
src/test/java/com/dmdirc/config/ConfigValueRetrieverTest.java Voir le fichier

65
 
65
 
66
     @Test
66
     @Test
67
     public void testRetrievesStringWithFallback() {
67
     public void testRetrievesStringWithFallback() {
68
-        when(configProvider.getOptionString(DOMAIN, KEY, true,
69
-                ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR)).thenReturn(null);
70
         when(configProvider.getOptionString(
68
         when(configProvider.getOptionString(
71
                 DOMAIN, KEY, true, ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR,
69
                 DOMAIN, KEY, true, ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR,
72
                 FALLBACK_DOMAIN, FALLBACK_KEY))
70
                 FALLBACK_DOMAIN, FALLBACK_KEY))
80
     public void testRetrievesStringWithRequiresFalse() {
78
     public void testRetrievesStringWithRequiresFalse() {
81
         when(configProvider.getOptionString(DOMAIN, KEY, false,
79
         when(configProvider.getOptionString(DOMAIN, KEY, false,
82
                 ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR)).thenReturn(null);
80
                 ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR)).thenReturn(null);
83
-        when(configProvider.getOptionString(DOMAIN, KEY, true,
84
-                ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR)).thenReturn("value!");
85
 
81
 
86
         assertNull(retriever.getValue(String.class, DOMAIN, KEY, false));
82
         assertNull(retriever.getValue(String.class, DOMAIN, KEY, false));
87
     }
83
     }
88
 
84
 
89
     @Test
85
     @Test
90
     public void testRetrievesStringWithRequiresTrue() {
86
     public void testRetrievesStringWithRequiresTrue() {
91
-        when(configProvider.getOptionString(DOMAIN, KEY, false,
92
-                ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR)).thenReturn(null);
93
         when(configProvider.getOptionString(DOMAIN, KEY, true,
87
         when(configProvider.getOptionString(DOMAIN, KEY, true,
94
                 ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR)).thenReturn("value!");
88
                 ReadOnlyConfigProvider.PERMISSIVE_VALIDATOR)).thenReturn("value!");
95
 
89
 

+ 0
- 16
src/test/java/com/dmdirc/config/prefs/PreferencesDialogModelTest.java Voir le fichier

66
     @Test
66
     @Test
67
     public void testDefaults() {
67
     public void testDefaults() {
68
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
68
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
69
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
70
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
69
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
71
                 null, null, cm, null, serviceManager, eventBus);
70
                 null, null, cm, null, serviceManager, eventBus);
72
         assertNotNull(pm.getCategory("General"));
71
         assertNotNull(pm.getCategory("General"));
82
     @Test
81
     @Test
83
     public void testDismiss() {
82
     public void testDismiss() {
84
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
83
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
85
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
86
         final PreferencesCategory category = mock(PreferencesCategory.class);
84
         final PreferencesCategory category = mock(PreferencesCategory.class);
87
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
85
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
88
                 null, null, cm, null, serviceManager, eventBus);
86
                 null, null, cm, null, serviceManager, eventBus);
97
         final PreferencesCategory category = mock(PreferencesCategory.class);
95
         final PreferencesCategory category = mock(PreferencesCategory.class);
98
         when(category.save()).thenReturn(false);
96
         when(category.save()).thenReturn(false);
99
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
97
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
100
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
101
-
102
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
98
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
103
                 null, null, cm, null, serviceManager, eventBus);
99
                 null, null, cm, null, serviceManager, eventBus);
104
         pm.addCategory(category);
100
         pm.addCategory(category);
112
         final PreferencesCategory category = mock(PreferencesCategory.class);
108
         final PreferencesCategory category = mock(PreferencesCategory.class);
113
         when(category.save()).thenReturn(true);
109
         when(category.save()).thenReturn(true);
114
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
110
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
115
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
116
-
117
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
111
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
118
                 null, null, cm, null, serviceManager, eventBus);
112
                 null, null, cm, null, serviceManager, eventBus);
119
         pm.addCategory(category);
113
         pm.addCategory(category);
125
     @Test
119
     @Test
126
     public void testGetCategory() {
120
     public void testGetCategory() {
127
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
121
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
128
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
129
-
130
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
122
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
131
                 null, null, cm, null, serviceManager, eventBus);
123
                 null, null, cm, null, serviceManager, eventBus);
132
         assertNull(pm.getCategory("unittest123"));
124
         assertNull(pm.getCategory("unittest123"));
135
     @Test
127
     @Test
136
     public void testGetCategories() {
128
     public void testGetCategories() {
137
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
129
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
138
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
139
-
140
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
130
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
141
                 null, null, cm, null, serviceManager, eventBus);
131
                 null, null, cm, null, serviceManager, eventBus);
142
         assertNotNull(pm.getCategories());
132
         assertNotNull(pm.getCategories());
150
     @Test
140
     @Test
151
     public void testSaveListener() {
141
     public void testSaveListener() {
152
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
142
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
153
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
154
-
155
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
143
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
156
                 null, null, cm, null, serviceManager, eventBus);
144
                 null, null, cm, null, serviceManager, eventBus);
157
         final PreferencesInterface tpi = mock(PreferencesInterface.class);
145
         final PreferencesInterface tpi = mock(PreferencesInterface.class);
164
     @Test
152
     @Test
165
     public void testOpenAction() {
153
     public void testOpenAction() {
166
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
154
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
167
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
168
 
155
 
169
         new PreferencesDialogModel(null, null, null, null, cm, null, serviceManager, eventBus);
156
         new PreferencesDialogModel(null, null, null, null, cm, null, serviceManager, eventBus);
170
 
157
 
174
     @Test
161
     @Test
175
     public void testCloseAction() {
162
     public void testCloseAction() {
176
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
163
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
177
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
178
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
164
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
179
                 null, null, cm, null, serviceManager, eventBus);
165
                 null, null, cm, null, serviceManager, eventBus);
180
         pm.close();
166
         pm.close();
185
     @Test
171
     @Test
186
     public void testCategoryObjectSaveListeners() {
172
     public void testCategoryObjectSaveListeners() {
187
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
173
         final AggregateConfigProvider cm = mock(AggregateConfigProvider.class);
188
-        when(cm.getOption("domain", "option")).thenReturn("fallback");
189
-
190
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
174
         final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
191
                 null, null, cm, null, serviceManager, eventBus);
175
                 null, null, cm, null, serviceManager, eventBus);
192
         final PreferencesCategory category = mock(PreferencesCategory.class);
176
         final PreferencesCategory category = mock(PreferencesCategory.class);

+ 0
- 1
src/test/java/com/dmdirc/config/profiles/IdentitiesProfileMigratorTest.java Voir le fichier

56
         instance = new IdentitiesProfileMigrator(identityManager, profileManager);
56
         instance = new IdentitiesProfileMigrator(identityManager, profileManager);
57
         when(configProvider1.getName()).thenReturn("name1");
57
         when(configProvider1.getName()).thenReturn("name1");
58
         when(configProvider1.getOption("profile", "realname")).thenReturn("realname1");
58
         when(configProvider1.getOption("profile", "realname")).thenReturn("realname1");
59
-        when(configProvider1.hasOptionString("profile", "ident1")).thenReturn(false);
60
         when(configProvider1.getOptionList("profile", "nicknames")).thenReturn(
59
         when(configProvider1.getOptionList("profile", "nicknames")).thenReturn(
61
                 Lists.newArrayList("nickname1")
60
                 Lists.newArrayList("nickname1")
62
         );
61
         );

+ 0
- 54
src/test/java/com/dmdirc/harness/CommandArgsMatcher.java Voir le fichier

1
-/*
2
- * Copyright (c) 2006-2015 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.harness;
24
-
25
-import com.dmdirc.commandparser.CommandArguments;
26
-
27
-import org.hamcrest.Description;
28
-import org.mockito.ArgumentMatcher;
29
-import org.mockito.Mockito;
30
-
31
-public class CommandArgsMatcher extends ArgumentMatcher<CommandArguments> {
32
-
33
-    private final String text;
34
-
35
-    public CommandArgsMatcher(final String text) {
36
-        this.text = text;
37
-    }
38
-
39
-    /** {@inheritDoc} */
40
-    @Override
41
-    public boolean matches(final Object item) {
42
-        return text.equals(((CommandArguments) item).getLine());
43
-    }
44
-
45
-    /** {@inheritDoc} */
46
-    @Override
47
-    public void describeTo(final Description description) {
48
-        description.appendText("eqLine(\"" + text + "\")");
49
-    }
50
-
51
-    public static CommandArguments eqLine(final String line) {
52
-        return Mockito.argThat(new CommandArgsMatcher(line));
53
-    }
54
-}

+ 0
- 1
src/test/java/com/dmdirc/logger/DiskLoggingErrorManagerTest.java Voir le fichier

62
     public void setUp() throws Exception {
62
     public void setUp() throws Exception {
63
         when(error.getTimestamp()).thenReturn(LocalDateTime.now());
63
         when(error.getTimestamp()).thenReturn(LocalDateTime.now());
64
         when(error.getError()).thenReturn(programError);
64
         when(error.getError()).thenReturn(programError);
65
-        when(programError.getThrowable()).thenReturn(Optional.of(new IllegalArgumentException()));
66
         when(programError.getThrowableAsString()).thenReturn(Optional.of("test"));
65
         when(programError.getThrowableAsString()).thenReturn(Optional.of("test"));
67
         when(programError.getLevel()).thenReturn(ErrorLevel.MEDIUM);
66
         when(programError.getLevel()).thenReturn(ErrorLevel.MEDIUM);
68
         when(config.getBinder()).thenReturn(configBinder);
67
         when(config.getBinder()).thenReturn(configBinder);

+ 3
- 4
src/test/java/com/dmdirc/logger/SentryLoggingErrorManagerTest.java Voir le fichier

38
 import org.mockito.Mock;
38
 import org.mockito.Mock;
39
 import org.mockito.runners.MockitoJUnitRunner;
39
 import org.mockito.runners.MockitoJUnitRunner;
40
 
40
 
41
+import static org.mockito.ArgumentMatchers.isNull;
41
 import static org.mockito.Matchers.any;
42
 import static org.mockito.Matchers.any;
42
 import static org.mockito.Matchers.anyString;
43
 import static org.mockito.Matchers.anyString;
43
 import static org.mockito.Matchers.eq;
44
 import static org.mockito.Matchers.eq;
77
     @Test
78
     @Test
78
     public void testHandleErrorEvent() throws Exception {
79
     public void testHandleErrorEvent() throws Exception {
79
         instance.handleErrorEvent(appErrorEvent);
80
         instance.handleErrorEvent(appErrorEvent);
80
-        verify(sentryErrorReporter).sendException(anyString(), any(ErrorLevel.class),
81
-                any(LocalDateTime.class), any());
81
+        verify(sentryErrorReporter).sendException(isNull(), isNull(), isNull(), any());
82
     }
82
     }
83
 
83
 
84
     @Test
84
     @Test
120
         instance.handleSubmitErrors(true);
120
         instance.handleSubmitErrors(true);
121
         instance.handleNoErrorReporting(false);
121
         instance.handleNoErrorReporting(false);
122
         instance.handleErrorEvent(appErrorEvent);
122
         instance.handleErrorEvent(appErrorEvent);
123
-        verify(sentryErrorReporter).sendException(anyString(), any(ErrorLevel.class),
124
-                any(LocalDateTime.class), any());
123
+        verify(sentryErrorReporter).sendException(isNull(), isNull(), isNull(), any());
125
     }
124
     }
126
 
125
 
127
     @Test
126
     @Test

+ 0
- 2
src/test/java/com/dmdirc/ui/WindowManagerTest.java Voir le fichier

252
         final CustomWindow customContainer = mock(CustomWindow.class);
252
         final CustomWindow customContainer = mock(CustomWindow.class);
253
         final CustomWindow customChild = mock(CustomWindow.class);
253
         final CustomWindow customChild = mock(CustomWindow.class);
254
 
254
 
255
-        when(customContainer.getName()).thenReturn("test");
256
         when(customChild.getName()).thenReturn("test1");
255
         when(customChild.getName()).thenReturn("test1");
257
 
256
 
258
         manager.addWindow(customContainer);
257
         manager.addWindow(customContainer);
266
         final CustomWindow customContainer = mock(CustomWindow.class);
265
         final CustomWindow customContainer = mock(CustomWindow.class);
267
         final CustomWindow customChild = mock(CustomWindow.class);
266
         final CustomWindow customChild = mock(CustomWindow.class);
268
 
267
 
269
-        when(customContainer.getName()).thenReturn("test");
270
         when(customChild.getName()).thenReturn("test1");
268
         when(customChild.getName()).thenReturn("test1");
271
 
269
 
272
         manager.addWindow(customContainer);
270
         manager.addWindow(customContainer);

+ 0
- 1
src/test/java/com/dmdirc/ui/core/aliases/CoreAliasDialogModelTest.java Voir le fichier

66
     @Before
66
     @Before
67
     public void setupAliases() {
67
     public void setupAliases() {
68
         aliases = new HashSet<>();
68
         aliases = new HashSet<>();
69
-        when(commandController.getCommandChar()).thenReturn('/');
70
     }
69
     }
71
 
70
 
72
     @Before
71
     @Before

+ 0
- 2
src/test/java/com/dmdirc/ui/core/aliases/RenameAliasValidatorTest.java Voir le fichier

56
     @Test
56
     @Test
57
     public void testRenameSelected() {
57
     public void testRenameSelected() {
58
         when(model.getSelectedAlias()).thenReturn(Optional.ofNullable(alias1));
58
         when(model.getSelectedAlias()).thenReturn(Optional.ofNullable(alias1));
59
-        when(model.getSelectedAliasName()).thenReturn("alias1");
60
         final RenameAliasValidator instance = new RenameAliasValidator(model);
59
         final RenameAliasValidator instance = new RenameAliasValidator(model);
61
         assertFalse(instance.validate("alias1").isFailure());
60
         assertFalse(instance.validate("alias1").isFailure());
62
         assertTrue(instance.validate("alias2").isFailure());
61
         assertTrue(instance.validate("alias2").isFailure());
67
     @Test
66
     @Test
68
     public void testRenameNonSelected() {
67
     public void testRenameNonSelected() {
69
         when(model.getSelectedAlias()).thenReturn(Optional.<Alias>empty());
68
         when(model.getSelectedAlias()).thenReturn(Optional.<Alias>empty());
70
-        when(model.getSelectedAliasName()).thenReturn(null);
71
         final RenameAliasValidator instance = new RenameAliasValidator(model);
69
         final RenameAliasValidator instance = new RenameAliasValidator(model);
72
         assertTrue(instance.validate("alias1").isFailure());
70
         assertTrue(instance.validate("alias1").isFailure());
73
         assertTrue(instance.validate("alias2").isFailure());
71
         assertTrue(instance.validate("alias2").isFailure());

+ 24
- 27
src/test/java/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModelTest.java Voir le fichier

47
     private static final String FEEDBACK = "DMDirc Rocks.";
47
     private static final String FEEDBACK = "DMDirc Rocks.";
48
 
48
 
49
     @Mock private FeedbackSenderFactory feedbackSenderFactory;
49
     @Mock private FeedbackSenderFactory feedbackSenderFactory;
50
-    @Mock private FeedbackSender feedbackSender;
51
     @Mock private FeedbackDialogModelListener listener;
50
     @Mock private FeedbackDialogModelListener listener;
52
     @Mock private FeedbackHelper feedbackHelper;
51
     @Mock private FeedbackHelper feedbackHelper;
53
 
52
 
56
     @Before
55
     @Before
57
     public void setup() {
56
     public void setup() {
58
         instance = new CoreFeedbackDialogModel(feedbackSenderFactory, feedbackHelper);
57
         instance = new CoreFeedbackDialogModel(feedbackSenderFactory, feedbackHelper);
59
-        when(feedbackSenderFactory.getFeedbackSender(anyString(), anyString(), anyString(),
60
-                anyString(), anyString(), anyString())).thenReturn(feedbackSender);
61
     }
58
     }
62
 
59
 
63
     @Test
60
     @Test
64
     public void testName() {
61
     public void testName() {
65
         assertEquals("testName", Optional.<String>empty(), instance.getName());
62
         assertEquals("testName", Optional.<String>empty(), instance.getName());
66
-        instance.setName(Optional.ofNullable(NAME));
67
-        assertEquals("testName", Optional.ofNullable(NAME), instance.getName());
63
+        instance.setName(Optional.of(NAME));
64
+        assertEquals("testName", Optional.of(NAME), instance.getName());
68
     }
65
     }
69
 
66
 
70
     @Test
67
     @Test
71
     public void testEmail() {
68
     public void testEmail() {
72
         assertEquals("testEmail", Optional.<String>empty(), instance.getEmail());
69
         assertEquals("testEmail", Optional.<String>empty(), instance.getEmail());
73
-        instance.setEmail(Optional.ofNullable(EMAIL));
74
-        assertEquals("testEmail", Optional.ofNullable(EMAIL), instance.getEmail());
70
+        instance.setEmail(Optional.of(EMAIL));
71
+        assertEquals("testEmail", Optional.of(EMAIL), instance.getEmail());
75
     }
72
     }
76
 
73
 
77
     @Test
74
     @Test
78
     public void testFeedback() {
75
     public void testFeedback() {
79
         assertEquals("testFeedback", Optional.<String>empty(), instance.getFeedback());
76
         assertEquals("testFeedback", Optional.<String>empty(), instance.getFeedback());
80
-        instance.setFeedback(Optional.ofNullable(FEEDBACK));
81
-        assertEquals("testFeedback", Optional.ofNullable(FEEDBACK), instance.getFeedback());
77
+        instance.setFeedback(Optional.of(FEEDBACK));
78
+        assertEquals("testFeedback", Optional.of(FEEDBACK), instance.getFeedback());
82
     }
79
     }
83
 
80
 
84
     @Test
81
     @Test
99
     public void testSaveWithoutServerWithoutDMDirc() {
96
     public void testSaveWithoutServerWithoutDMDirc() {
100
         instance.setIncludeDMDircInfo(false);
97
         instance.setIncludeDMDircInfo(false);
101
         instance.setIncludeServerInfo(false);
98
         instance.setIncludeServerInfo(false);
102
-        instance.setName(Optional.ofNullable(NAME));
103
-        instance.setEmail(Optional.ofNullable(EMAIL));
104
-        instance.setFeedback(Optional.ofNullable(FEEDBACK));
99
+        instance.setName(Optional.of(NAME));
100
+        instance.setEmail(Optional.of(EMAIL));
101
+        instance.setFeedback(Optional.of(FEEDBACK));
105
         instance.save();
102
         instance.save();
106
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
103
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
107
                 feedbackHelper.getVersion(), "", "");
104
                 feedbackHelper.getVersion(), "", "");
111
     public void testSaveWithoutServerWithDMDirc() {
108
     public void testSaveWithoutServerWithDMDirc() {
112
         instance.setIncludeDMDircInfo(true);
109
         instance.setIncludeDMDircInfo(true);
113
         instance.setIncludeServerInfo(false);
110
         instance.setIncludeServerInfo(false);
114
-        instance.setName(Optional.ofNullable(NAME));
115
-        instance.setEmail(Optional.ofNullable(EMAIL));
116
-        instance.setFeedback(Optional.ofNullable(FEEDBACK));
111
+        instance.setName(Optional.of(NAME));
112
+        instance.setEmail(Optional.of(EMAIL));
113
+        instance.setFeedback(Optional.of(FEEDBACK));
117
         instance.save();
114
         instance.save();
118
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
115
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
119
                 feedbackHelper.getVersion(), "", feedbackHelper.getDMDircInfo());
116
                 feedbackHelper.getVersion(), "", feedbackHelper.getDMDircInfo());
123
     public void testSaveWithoutDMDircWithServer() {
120
     public void testSaveWithoutDMDircWithServer() {
124
         instance.setIncludeDMDircInfo(false);
121
         instance.setIncludeDMDircInfo(false);
125
         instance.setIncludeServerInfo(true);
122
         instance.setIncludeServerInfo(true);
126
-        instance.setName(Optional.ofNullable(NAME));
127
-        instance.setEmail(Optional.ofNullable(EMAIL));
128
-        instance.setFeedback(Optional.ofNullable(FEEDBACK));
123
+        instance.setName(Optional.of(NAME));
124
+        instance.setEmail(Optional.of(EMAIL));
125
+        instance.setFeedback(Optional.of(FEEDBACK));
129
         instance.save();
126
         instance.save();
130
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
127
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
131
                 feedbackHelper.getVersion(), feedbackHelper.getServerInfo(), "");
128
                 feedbackHelper.getVersion(), feedbackHelper.getServerInfo(), "");
135
     public void testSaveWithServerWithDMDirc() {
132
     public void testSaveWithServerWithDMDirc() {
136
         instance.setIncludeDMDircInfo(true);
133
         instance.setIncludeDMDircInfo(true);
137
         instance.setIncludeServerInfo(true);
134
         instance.setIncludeServerInfo(true);
138
-        instance.setName(Optional.ofNullable(NAME));
139
-        instance.setEmail(Optional.ofNullable(EMAIL));
140
-        instance.setFeedback(Optional.ofNullable(FEEDBACK));
135
+        instance.setName(Optional.of(NAME));
136
+        instance.setEmail(Optional.of(EMAIL));
137
+        instance.setFeedback(Optional.of(FEEDBACK));
141
         instance.save();
138
         instance.save();
142
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
139
         verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
143
                 feedbackHelper.getVersion(), feedbackHelper.getServerInfo(),
140
                 feedbackHelper.getVersion(), feedbackHelper.getServerInfo(),
147
     @Test
144
     @Test
148
     public void testNameListener() {
145
     public void testNameListener() {
149
         instance.addListener(listener);
146
         instance.addListener(listener);
150
-        instance.setName(Optional.ofNullable(NAME));
151
-        verify(listener).nameChanged(Optional.ofNullable(NAME));
147
+        instance.setName(Optional.of(NAME));
148
+        verify(listener).nameChanged(Optional.of(NAME));
152
     }
149
     }
153
 
150
 
154
     @Test
151
     @Test
155
     public void testEmailListener() {
152
     public void testEmailListener() {
156
         instance.addListener(listener);
153
         instance.addListener(listener);
157
-        instance.setEmail(Optional.ofNullable(EMAIL));
158
-        verify(listener).emailChanged(Optional.ofNullable(EMAIL));
154
+        instance.setEmail(Optional.of(EMAIL));
155
+        verify(listener).emailChanged(Optional.of(EMAIL));
159
     }
156
     }
160
 
157
 
161
     @Test
158
     @Test
162
     public void testFeedbackListener() {
159
     public void testFeedbackListener() {
163
         instance.addListener(listener);
160
         instance.addListener(listener);
164
-        instance.setFeedback(Optional.ofNullable(FEEDBACK));
165
-        verify(listener).feedbackChanged(Optional.ofNullable(FEEDBACK));
161
+        instance.setFeedback(Optional.of(FEEDBACK));
162
+        verify(listener).feedbackChanged(Optional.of(FEEDBACK));
166
     }
163
     }
167
 
164
 
168
     @Test
165
     @Test

+ 1
- 3
src/test/java/com/dmdirc/ui/core/profiles/AddNicknameValidatorTest.java Voir le fichier

52
         when(model.getSelectedProfile())
52
         when(model.getSelectedProfile())
53
                 .thenReturn(Optional.ofNullable(profile));
53
                 .thenReturn(Optional.ofNullable(profile));
54
         when(model.getSelectedProfileNicknames())
54
         when(model.getSelectedProfileNicknames())
55
-                .thenReturn(Optional.ofNullable(nicknames));
56
-        when(model.getSelectedProfileSelectedNickname())
57
-                .thenReturn(Optional.ofNullable("nickname2"));
55
+                .thenReturn(Optional.of(nicknames));
58
     }
56
     }
59
 
57
 
60
     @Test
58
     @Test

+ 0
- 1
src/test/java/com/dmdirc/ui/core/profiles/EditSelectedProfileNameValidatorTest.java Voir le fichier

52
     public void setupModel() {
52
     public void setupModel() {
53
         final List<MutableProfile> profiles = Lists.newArrayList(profile1, profile2, profile3);
53
         final List<MutableProfile> profiles = Lists.newArrayList(profile1, profile2, profile3);
54
         when(profile1.getName()).thenReturn("profile1");
54
         when(profile1.getName()).thenReturn("profile1");
55
-        when(profile2.getName()).thenReturn("profile2");
56
         when(profile3.getName()).thenReturn("profile3");
55
         when(profile3.getName()).thenReturn("profile3");
57
         when(model.getProfileList()).thenReturn(profiles);
56
         when(model.getProfileList()).thenReturn(profiles);
58
         when(model.getSelectedProfile()).thenReturn(Optional.ofNullable(profile2));
57
         when(model.getSelectedProfile()).thenReturn(Optional.ofNullable(profile2));

+ 0
- 1
src/test/java/com/dmdirc/ui/core/profiles/NewProfileNameValidatorTest.java Voir le fichier

55
         when(profile2.getName()).thenReturn("profile2");
55
         when(profile2.getName()).thenReturn("profile2");
56
         when(profile3.getName()).thenReturn("profile3");
56
         when(profile3.getName()).thenReturn("profile3");
57
         when(model.getProfileList()).thenReturn(profiles);
57
         when(model.getProfileList()).thenReturn(profiles);
58
-        when(model.getSelectedProfile()).thenReturn(Optional.ofNullable(profile2));
59
     }
58
     }
60
 
59
 
61
     @Test
60
     @Test

+ 0
- 1
src/test/java/com/dmdirc/updater/manager/UpdateManagerImplTest.java Voir le fichier

111
     @Test
111
     @Test
112
     public void testGetNoRetrievalStrategy() {
112
     public void testGetNoRetrievalStrategy() {
113
         // Given a retrieval strategies that can handle a specific check result
113
         // Given a retrieval strategies that can handle a specific check result
114
-        when(strategy1.canHandle(checkResult1)).thenReturn(true);
115
         manager.addRetrievalStrategy(strategy1);
114
         manager.addRetrievalStrategy(strategy1);
116
 
115
 
117
         // Then null is returned for other check results
116
         // Then null is returned for other check results

Chargement…
Annuler
Enregistrer