Skip to content

Commit ba04245

Browse files
committed
Merge Mockito
2 parents e321ab0 + acbdad1 commit ba04245

6 files changed

Lines changed: 88 additions & 50 deletions

File tree

ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/actions/RunCommandActionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111
package org.eclipse.che.ide.actions;
1212

13+
import static org.mockito.ArgumentMatchers.nullable;
1314
import static org.mockito.Matchers.any;
14-
import static org.mockito.Matchers.anyString;
1515
import static org.mockito.Matchers.eq;
1616
import static org.mockito.Mockito.mock;
1717
import static org.mockito.Mockito.never;
@@ -53,15 +53,15 @@ public class RunCommandActionTest {
5353

5454
@Before
5555
public void setUp() throws Exception {
56-
when(commandManager.getCommand(anyString())).thenReturn(Optional.of(command));
56+
when(commandManager.getCommand(nullable(String.class))).thenReturn(Optional.of(command));
5757
}
5858

5959
@Test
6060
public void commandNameShouldBePresent() {
6161
when(event.getParameters()).thenReturn(Collections.singletonMap("otherParam", "MCI"));
6262
action.actionPerformed(event);
6363

64-
verify(commandExecutor, never()).executeCommand(any(CommandImpl.class), anyString());
64+
verify(commandExecutor, never()).executeCommand(any(CommandImpl.class), nullable(String.class));
6565
}
6666

6767
@Test
@@ -75,6 +75,6 @@ public void actionShouldBePerformed() {
7575

7676
action.actionPerformed(event);
7777

78-
verify(commandExecutor).executeCommand(eq(command), anyString());
78+
verify(commandExecutor).executeCommand(eq(command), nullable(String.class));
7979
}
8080
}

ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/project/ProjectServiceClientTest.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
1818
import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE;
1919
import static org.junit.Assert.assertEquals;
20-
import static org.mockito.Matchers.any;
21-
import static org.mockito.Matchers.anyBoolean;
22-
import static org.mockito.Matchers.anyString;
23-
import static org.mockito.Matchers.eq;
20+
import static org.mockito.ArgumentMatchers.any;
21+
import static org.mockito.ArgumentMatchers.anyBoolean;
22+
import static org.mockito.ArgumentMatchers.anyList;
23+
import static org.mockito.ArgumentMatchers.anyString;
24+
import static org.mockito.ArgumentMatchers.eq;
25+
import static org.mockito.ArgumentMatchers.nullable;
2426
import static org.mockito.Mockito.mock;
2527
import static org.mockito.Mockito.never;
2628
import static org.mockito.Mockito.verify;
@@ -58,6 +60,7 @@
5860
import org.junit.Test;
5961
import org.junit.runner.RunWith;
6062
import org.mockito.ArgumentCaptor;
63+
import org.mockito.ArgumentMatchers;
6164
import org.mockito.Captor;
6265
import org.mockito.Mock;
6366

@@ -112,9 +115,9 @@ public void setUp() throws Exception {
112115

113116
when(loaderFactory.newLoader(any())).thenReturn(messageLoader);
114117
when(asyncRequest.loader(messageLoader)).thenReturn(asyncRequest);
115-
when(asyncRequest.data(any())).thenReturn(asyncRequest);
118+
when(asyncRequest.data(any(String.class))).thenReturn(asyncRequest);
116119
when(asyncRequest.send(unmarshallableItemRef)).thenReturn(itemRefPromise);
117-
when(asyncRequest.header(any(), any())).thenReturn(asyncRequest);
120+
when(asyncRequest.header(any(String.class), any(String.class))).thenReturn(asyncRequest);
118121
when(unmarshaller.newUnmarshaller(ItemReference.class)).thenReturn(unmarshallableItemRef);
119122
when(unmarshaller.newListUnmarshaller(ProjectConfigDto.class))
120123
.thenReturn(unmarshallablePrjsConf);
@@ -127,13 +130,38 @@ public void setUp() throws Exception {
127130
when(unmarshaller.newUnmarshaller(TreeElement.class)).thenReturn(unmarshallableTreeElem);
128131
when(unmarshaller.newUnmarshaller(ProjectConfigDto.class)).thenReturn(unmarshallablePrjConf);
129132

130-
when(requestFactory.createGetRequest(anyString())).thenReturn(asyncRequest);
131-
when(requestFactory.createPostRequest(anyString(), any(MimeType.class)))
133+
when(requestFactory.createGetRequest(any(String.class))).thenReturn(asyncRequest);
134+
when(requestFactory.createRequest(
135+
any(RequestBuilder.Method.class),
136+
any(String.class),
137+
any(SourceStorageDto.class),
138+
any(Boolean.class)))
139+
.thenReturn(asyncRequest);
140+
when(requestFactory.createRequest(
141+
any(RequestBuilder.Method.class), any(String.class), anyList(), any(Boolean.class)))
142+
.thenReturn(asyncRequest);
143+
when(requestFactory.createRequest(
144+
any(RequestBuilder.Method.class), any(String.class), any(), any(Boolean.class)))
145+
.thenReturn(asyncRequest);
146+
when(requestFactory.createPostRequest(any(String.class), anyList())).thenReturn(asyncRequest);
147+
when(requestFactory.createPostRequest(any(String.class), any())).thenReturn(asyncRequest);
148+
when(requestFactory.createPostRequest(
149+
any(String.class), ArgumentMatchers.<List<NewProjectConfigDto>>any()))
150+
.thenReturn(asyncRequest);
151+
when(requestFactory.createPostRequest(any(String.class), nullable(MimeType.class)))
152+
.thenReturn(asyncRequest);
153+
when(requestFactory.createPostRequest(any(String.class), nullable(SourceStorageDto.class)))
154+
.thenReturn(asyncRequest);
155+
when(requestFactory.createPostRequest(any(String.class), nullable(CopyOptions.class)))
156+
.thenReturn(asyncRequest);
157+
when(requestFactory.createPostRequest(any(String.class), nullable(MoveOptions.class)))
132158
.thenReturn(asyncRequest);
133159
when(requestFactory.createRequest(
134-
any(RequestBuilder.Method.class), anyString(), any(), anyBoolean()))
160+
any(RequestBuilder.Method.class),
161+
any(String.class),
162+
any(CopyOptions.class),
163+
any(Boolean.class)))
135164
.thenReturn(asyncRequest);
136-
when(requestFactory.createPostRequest(anyString(), any())).thenReturn(asyncRequest);
137165
}
138166

139167
@Test

infrastructures/docker/src/test/java/org/eclipse/che/workspace/infrastructure/docker/DockerInternalRuntimeTest.java

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import static org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.RUNNING;
1717
import static org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.STARTING;
1818
import static org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.STOPPED;
19+
import static org.mockito.ArgumentMatchers.anyList;
20+
import static org.mockito.ArgumentMatchers.nullable;
1921
import static org.mockito.Matchers.any;
20-
import static org.mockito.Matchers.anyListOf;
21-
import static org.mockito.Matchers.anyString;
2222
import static org.mockito.Mockito.atLeastOnce;
2323
import static org.mockito.Mockito.doAnswer;
2424
import static org.mockito.Mockito.doNothing;
@@ -101,7 +101,7 @@ public void setup() throws Exception {
101101
when(internalMachineCfg2.getInstallers()).thenReturn(singletonList(newInstaller(2)));
102102
environment.setContainers(ImmutableMap.of(DEV_MACHINE, config1, DB_MACHINE, config2));
103103

104-
doNothing().when(networks).createNetwork(anyString());
104+
doNothing().when(networks).createNetwork(nullable(String.class));
105105
when(runtimeContext.getIdentity()).thenReturn(IDENTITY);
106106
when(runtimeContext.getDockerEnvironment()).thenReturn(environment);
107107
final LinkedList<String> orderedContainers = new LinkedList<>();
@@ -114,7 +114,7 @@ public void setup() throws Exception {
114114
.thenReturn(
115115
ImmutableMap.of(DEV_MACHINE, internalMachineCfg1, DB_MACHINE, internalMachineCfg2));
116116
ServersCheckerFactory serversCheckerFactory = mock(ServersCheckerFactory.class);
117-
when(serversCheckerFactory.create(any(), anyString(), any()))
117+
when(serversCheckerFactory.create(any(), nullable(String.class), any()))
118118
.thenReturn(mock(ServersChecker.class));
119119
dockerRuntime =
120120
new DockerInternalRuntime(
@@ -136,7 +136,8 @@ public void startsDockerRuntimeAndPropagatesMachineStatusEvents() throws Excepti
136136
mockContainerStart();
137137
dockerRuntime.start(emptyMap());
138138

139-
verify(starter, times(2)).startContainer(anyString(), anyString(), any(), any(), any());
139+
verify(starter, times(2))
140+
.startContainer(nullable(String.class), nullable(String.class), any(), any(), any());
140141
verify(eventService, times(4)).publish(any(MachineStatusEvent.class));
141142
verifyEventsOrder(
142143
newEvent(DEV_MACHINE, STARTING, null),
@@ -154,7 +155,8 @@ public void throwsExceptionWhenOneMachineStartFailed() throws Exception {
154155
try {
155156
dockerRuntime.start(emptyMap());
156157
} catch (InfrastructureException ex) {
157-
verify(starter, times(1)).startContainer(anyString(), anyString(), any(), any(), any());
158+
verify(starter, times(1))
159+
.startContainer(nullable(String.class), nullable(String.class), any(), any(), any());
158160
verify(eventService, times(2)).publish(any(MachineStatusEvent.class));
159161
verifyEventsOrder(newEvent(DEV_MACHINE, STARTING, null), newEvent(DEV_MACHINE, FAILED, msg));
160162
throw ex;
@@ -168,7 +170,8 @@ public void throwsExceptionWhenBootstrappingOfInstallersFailed() throws Exceptio
168170
try {
169171
dockerRuntime.start(emptyMap());
170172
} catch (InfrastructureException ex) {
171-
verify(starter, times(1)).startContainer(anyString(), anyString(), any(), any(), any());
173+
verify(starter, times(1))
174+
.startContainer(nullable(String.class), nullable(String.class), any(), any(), any());
172175
verify(bootstrapper, times(1)).bootstrap();
173176
verify(eventService, times(3)).publish(any(MachineStatusEvent.class));
174177
verifyEventsOrder(
@@ -181,12 +184,15 @@ public void throwsExceptionWhenBootstrappingOfInstallersFailed() throws Exceptio
181184

182185
@Test(expectedExceptions = RuntimeStartInterruptedException.class)
183186
public void throwsInterruptionExceptionWhenNetworkCreationInterrupted() throws Exception {
184-
doThrow(RuntimeStartInterruptedException.class).when(networks).createNetwork(anyString());
187+
doThrow(RuntimeStartInterruptedException.class)
188+
.when(networks)
189+
.createNetwork(nullable(String.class));
185190

186191
try {
187192
dockerRuntime.start(emptyMap());
188193
} catch (InfrastructureException ex) {
189-
verify(starter, never()).startContainer(anyString(), anyString(), any(), any(), any());
194+
verify(starter, never())
195+
.startContainer(nullable(String.class), nullable(String.class), any(), any(), any());
190196
throw ex;
191197
}
192198
}
@@ -199,7 +205,8 @@ public void throwsInterruptionExceptionWhenContainerStartInterrupted() throws Ex
199205
try {
200206
dockerRuntime.start(emptyMap());
201207
} catch (InfrastructureException ex) {
202-
verify(starter, times(1)).startContainer(anyString(), anyString(), any(), any(), any());
208+
verify(starter, times(1))
209+
.startContainer(nullable(String.class), nullable(String.class), any(), any(), any());
203210
throw ex;
204211
}
205212
}
@@ -216,16 +223,17 @@ public void throwsInterruptionExceptionWhenThreadInterruptedOnStarFailedBeforeDe
216223
})
217224
.when(starter)
218225
.startContainer(
219-
anyString(),
220-
anyString(),
226+
nullable(String.class),
227+
nullable(String.class),
221228
any(DockerContainerConfig.class),
222229
any(RuntimeIdentity.class),
223230
any(AbnormalMachineStopHandler.class));
224231

225232
try {
226233
dockerRuntime.start(emptyMap());
227234
} catch (InfrastructureException ex) {
228-
verify(starter, times(1)).startContainer(anyString(), anyString(), any(), any(), any());
235+
verify(starter, times(1))
236+
.startContainer(nullable(String.class), nullable(String.class), any(), any(), any());
229237
throw ex;
230238
}
231239
}
@@ -260,42 +268,42 @@ private static MachineStatusEvent newEvent(
260268

261269
private void mockContainerStart() throws InfrastructureException {
262270
when(starter.startContainer(
263-
anyString(),
264-
anyString(),
265-
any(DockerContainerConfig.class),
266-
any(RuntimeIdentity.class),
267-
any(AbnormalMachineStopHandler.class)))
271+
nullable(String.class),
272+
nullable(String.class),
273+
nullable(DockerContainerConfig.class),
274+
nullable(RuntimeIdentity.class),
275+
nullable(AbnormalMachineStopHandler.class)))
268276
.thenReturn(mock(DockerMachine.class));
269277
}
270278

271279
private void mockContainerStartFailed(InfrastructureException exception)
272280
throws InfrastructureException {
273281
when(starter.startContainer(
274-
anyString(),
275-
anyString(),
276-
any(DockerContainerConfig.class),
277-
any(RuntimeIdentity.class),
278-
any(AbnormalMachineStopHandler.class)))
282+
nullable(String.class),
283+
nullable(String.class),
284+
nullable(DockerContainerConfig.class),
285+
nullable(RuntimeIdentity.class),
286+
nullable(AbnormalMachineStopHandler.class)))
279287
.thenThrow(exception);
280288
}
281289

282290
private void mockInstallersBootstrap() throws Exception {
283291
final DockerBootstrapper bootstrapper = mock(DockerBootstrapper.class);
284292
when(bootstrapperFactory.create(
285-
anyString(),
286-
any(RuntimeIdentity.class),
287-
anyListOf(InstallerImpl.class),
288-
any(DockerMachine.class)))
293+
nullable(String.class),
294+
nullable(RuntimeIdentity.class),
295+
anyList(),
296+
nullable(DockerMachine.class)))
289297
.thenReturn(bootstrapper);
290298
doNothing().when(bootstrapper).bootstrap();
291299
}
292300

293301
private void mockInstallersBootstrapFailed(InfrastructureException exception) throws Exception {
294302
when(bootstrapperFactory.create(
295-
anyString(),
296-
any(RuntimeIdentity.class),
297-
anyListOf(InstallerImpl.class),
298-
any(DockerMachine.class)))
303+
nullable(String.class),
304+
nullable(RuntimeIdentity.class),
305+
anyList(),
306+
nullable(DockerMachine.class)))
299307
.thenReturn(bootstrapper);
300308
doThrow(exception).when(bootstrapper).bootstrap();
301309
}

multiuser/machine-auth/che-multiuser-machine-authentication/src/test/java/org/eclipse/che/multiuser/machine/authentication/server/MachineTokenInterceptorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.inject.name.Names;
2626
import com.google.inject.spi.ConstructorBinding;
2727
import java.lang.reflect.Method;
28+
import javax.persistence.EntityManagerFactory;
2829
import org.eclipse.che.api.core.notification.EventService;
2930
import org.eclipse.che.api.workspace.server.WorkspaceRuntimes;
3031
import org.eclipse.che.api.workspace.server.WorkspaceSharedPool;
@@ -63,6 +64,7 @@ public void configure() {
6364
//Bind manager and his dep-s. To bind interceptor, guice must create intercepted class by himself.
6465
bind(WorkspaceDao.class).toInstance(mock(WorkspaceDao.class));
6566
bind(EventService.class).toInstance(mock(EventService.class));
67+
bind(EntityManagerFactory.class).toInstance(mock(EntityManagerFactory.class));
6668
bind(DBInitializer.class).toInstance(mock(DBInitializer.class));
6769
bind(WorkspaceSharedPool.class)
6870
.toInstance(new WorkspaceSharedPool("cached", null, null));

wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/hc/HttpConnectionServerCheckerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
package org.eclipse.che.api.workspace.server.hc;
1212

13-
import static org.mockito.Matchers.any;
13+
import static org.mockito.ArgumentMatchers.nullable;
1414
import static org.mockito.Matchers.eq;
1515
import static org.mockito.Mockito.doReturn;
1616
import static org.mockito.Mockito.spy;
@@ -52,7 +52,7 @@ public void setUp() throws Exception {
5252
new HttpConnectionServerChecker(
5353
SERVER_URL, MACHINE_NAME, SERVER_REF, 1, 10, TimeUnit.SECONDS, timer));
5454

55-
doReturn(conn).when(checker).createConnection(any(URL.class));
55+
doReturn(conn).when(checker).createConnection(nullable(URL.class));
5656
when(conn.getResponseCode()).thenReturn(200);
5757
}
5858

@@ -114,7 +114,7 @@ public void shouldRejectAvailabilityInCaseOfExceptionOnResponseCodeRetrieving()
114114

115115
@Test
116116
public void shouldRejectAvailabilityInCaseOfExceptionOnConnectionOpening() throws Exception {
117-
when(checker.createConnection(any(URL.class))).thenThrow(new IOException());
117+
when(checker.createConnection(nullable(URL.class))).thenThrow(new IOException());
118118
assertFalse(checker.isAvailable());
119119
}
120120

wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/hc/ServersCheckerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import static org.mockito.Matchers.anyObject;
1515
import static org.mockito.Matchers.anyString;
1616
import static org.mockito.Matchers.eq;
17+
import static org.mockito.Mockito.after;
1718
import static org.mockito.Mockito.doThrow;
1819
import static org.mockito.Mockito.never;
1920
import static org.mockito.Mockito.spy;
20-
import static org.mockito.Mockito.timeout;
2121
import static org.mockito.Mockito.times;
2222
import static org.mockito.Mockito.verify;
2323
import static org.mockito.Mockito.when;
@@ -107,7 +107,7 @@ public void shouldUseMachineTokenWhenConstructionUrlToCheck() throws Exception {
107107
public void shouldNotifyReadinessHandlerAboutEachServerReadiness() throws Exception {
108108
checker.startAsync(readinessHandler);
109109

110-
verify(readinessHandler, timeout(500).never()).accept(anyString());
110+
verify(readinessHandler, after(500).never()).accept(anyString());
111111

112112
connectionChecker.getReportCompFuture().complete("test_ref");
113113

0 commit comments

Comments
 (0)