Skip to content

Commit 552436d

Browse files
authored
Merge pull request #264 from slachiewicz/mockito4
Move Tests to Mockito4
2 parents c6cf180 + 0d014bc commit 552436d

File tree

45 files changed

+90
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+90
-84
lines changed

OCPP-J/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ dependencies {
66
compile project(':common')
77
compile 'com.google.code.gson:gson:2.8.0'
88
compile 'org.java-websocket:Java-WebSocket:1.5.3'
9-
testCompile 'junit:junit:4.12'
10-
testCompile 'org.mockito:mockito-core:1.10.19'
9+
testCompile 'junit:junit:4.13.2'
10+
testCompile 'org.mockito:mockito-core:4.11.0'
1111
testCompile 'org.hamcrest:hamcrest-core:1.3'
1212
}
1313

OCPP-J/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<dependency>
7373
<groupId>org.mockito</groupId>
7474
<artifactId>mockito-core</artifactId>
75-
<version>1.10.19</version>
75+
<version>4.11.0</version>
7676
<scope>test</scope>
7777
</dependency>
7878
<dependency>

OCPP-J/src/test/java/eu/chargetime/ocpp/wss/test/BaseWssSocketBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static org.hamcrest.CoreMatchers.is;
44
import static org.junit.Assert.*;
5-
import static org.mockito.Matchers.any;
5+
import static org.mockito.ArgumentMatchers.any;
66
import static org.mockito.Mockito.*;
77

88
import eu.chargetime.ocpp.wss.BaseWssFactoryBuilder;

ocpp-common/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ dependencies {
55
compile group: 'javax.xml.soap', name: 'javax.xml.soap-api', version: '1.4.0'
66
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.1'
77

8-
testCompile 'junit:junit:4.12'
9-
testCompile 'org.mockito:mockito-core:1.10.19'
8+
testCompile 'junit:junit:4.13.2'
9+
testCompile 'org.mockito:mockito-core:4.11.0'
1010
testCompile 'org.hamcrest:hamcrest-all:1.3'
1111
}
1212

ocpp-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<dependency>
8181
<groupId>org.mockito</groupId>
8282
<artifactId>mockito-core</artifactId>
83-
<version>1.10.19</version>
83+
<version>4.11.0</version>
8484
<scope>test</scope>
8585
</dependency>
8686
<dependency>

ocpp-common/src/test/java/eu/chargetime/ocpp/test/ClientTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ of this software and associated documentation files (the "Software"), to deal
4141
import org.junit.Test;
4242
import org.junit.runner.RunWith;
4343
import org.mockito.Mock;
44-
import org.mockito.runners.MockitoJUnitRunner;
44+
import org.mockito.junit.MockitoJUnitRunner;
4545

4646
@RunWith(MockitoJUnitRunner.class)
4747
public class ClientTest {
@@ -59,7 +59,7 @@ public class ClientTest {
5959
@Before
6060
public void setup() {
6161
when(request.validate()).thenReturn(true);
62-
doAnswer(invocation -> eventHandler = invocation.getArgumentAt(1, SessionEvents.class))
62+
doAnswer(invocation -> eventHandler = invocation.getArgument(1, SessionEvents.class))
6363
.when(session)
6464
.open(any(), any());
6565

@@ -77,7 +77,7 @@ public void connect_connects() {
7777
client.connect(someUrl, events);
7878

7979
// Then
80-
verify(session, times(1)).open(eq(someUrl), anyObject());
80+
verify(session, times(1)).open(eq(someUrl), any());
8181
}
8282

8383
@Test
@@ -112,14 +112,15 @@ public void send_aMessage_isCommunicated() throws Exception {
112112
client.send(request);
113113

114114
// Then
115-
verify(session, times(1)).sendRequest(anyString(), eq(request), anyString());
115+
// TODO action and uuid should not be nullable
116+
verify(session, times(1)).sendRequest(nullable(String.class), eq(request), nullable(String.class));
116117
}
117118

118119
@Test
119120
public void responseReceived_aMessageWasSend_PromiseIsCompleted() throws Exception {
120121
// Given
121122
String someUniqueId = "Some id";
122-
when(session.storeRequest(any())).thenReturn(someUniqueId);
123+
lenient().when(session.storeRequest(any())).thenReturn(someUniqueId);
123124
when(promiseRepository.getPromise(any())).thenReturn(Optional.of(completableFuture));
124125

125126
// When

ocpp-common/src/test/java/eu/chargetime/ocpp/test/CommunicatorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package eu.chargetime.ocpp.test;
22

3-
import static org.mockito.Matchers.anyString;
3+
import static org.mockito.ArgumentMatchers.anyString;
44
import static org.mockito.Mockito.*;
55

66
import eu.chargetime.ocpp.*;
@@ -12,7 +12,7 @@
1212
import org.junit.Test;
1313
import org.junit.runner.RunWith;
1414
import org.mockito.Mock;
15-
import org.mockito.runners.MockitoJUnitRunner;
15+
import org.mockito.junit.MockitoJUnitRunner;
1616

1717
/*
1818
ChargeTime.eu - Java-OCA-OCPP
@@ -57,7 +57,7 @@ public void setup() throws Exception {
5757

5858
when(transactionRelatedRequest.transactionRelated()).thenReturn(true);
5959
when(normalRequest.transactionRelated()).thenReturn(false);
60-
doAnswer(invocation -> eventHandler = invocation.getArgumentAt(0, RadioEvents.class))
60+
doAnswer(invocation -> eventHandler = invocation.getArgument(0, RadioEvents.class))
6161
.when(receiver)
6262
.accept(any());
6363
setupCommunicator(true);

ocpp-common/src/test/java/eu/chargetime/ocpp/test/ServerTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.junit.Test;
1313
import org.junit.runner.RunWith;
1414
import org.mockito.Mock;
15-
import org.mockito.runners.MockitoJUnitRunner;
15+
import org.mockito.junit.MockitoJUnitRunner;
1616

1717
/*
1818
ChargeTime.eu - Java-OCA-OCPP
@@ -65,13 +65,13 @@ public void setup() {
6565
UUID sessionId = UUID.randomUUID();
6666
when(request.validate()).thenReturn(true);
6767
when(session.getSessionId()).thenReturn(sessionId);
68-
doAnswer(invocation -> listenerEvents = invocation.getArgumentAt(2, ListenerEvents.class))
68+
doAnswer(invocation -> listenerEvents = invocation.getArgument(2, ListenerEvents.class))
6969
.when(listener)
7070
.open(anyString(), anyInt(), any());
71-
doAnswer(invocation -> sessionEvents = invocation.getArgumentAt(0, SessionEvents.class))
71+
doAnswer(invocation -> sessionEvents = invocation.getArgument(0, SessionEvents.class))
7272
.when(session)
7373
.accept(any());
74-
doAnswer(invocation -> sessionIndex = invocation.getArgumentAt(0, UUID.class))
74+
doAnswer(invocation -> sessionIndex = invocation.getArgument(0, UUID.class))
7575
.when(serverEvents)
7676
.newSession(any(), any());
7777

@@ -114,7 +114,8 @@ public void send_aMessage_isCommunicated() throws Exception {
114114
server.send(sessionIndex, request);
115115

116116
// Then
117-
verify(session, times(1)).sendRequest(anyString(), eq(request), anyString());
117+
// TODO action and uuid should not be nullable
118+
verify(session, times(1)).sendRequest(nullable(String.class), eq(request), nullable(String.class));
118119
}
119120

120121
@Test

ocpp-common/src/test/java/eu/chargetime/ocpp/test/SessionTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.junit.Test;
1717
import org.junit.runner.RunWith;
1818
import org.mockito.Mock;
19-
import org.mockito.runners.MockitoJUnitRunner;
19+
import org.mockito.junit.MockitoJUnitRunner;
2020

2121
/*
2222
ChargeTime.eu - Java-OCA-OCPP
@@ -63,7 +63,7 @@ public class SessionTest {
6363
public void setup() throws Exception {
6464
when(featureRepository.findFeature(any())).thenReturn(Optional.of(feature));
6565
session = new Session(communicator, queue, fulfiller, featureRepository);
66-
doAnswer(invocation -> eventHandler = invocation.getArgumentAt(1, CommunicatorEvents.class))
66+
doAnswer(invocation -> eventHandler = invocation.getArgument(1, CommunicatorEvents.class))
6767
.when(communicator)
6868
.connect(any(), any());
6969
session.open(null, sessionEvents);
@@ -103,7 +103,8 @@ public boolean validate() {
103103
session.sendRequest(someAction, someRequest, null);
104104

105105
// Then
106-
verify(communicator, times(1)).sendCall(anyString(), eq(someAction), eq(someRequest));
106+
// TODO uniqueid should not be nullable
107+
verify(communicator, times(1)).sendCall(nullable(String.class), eq(someAction), eq(someRequest));
107108
}
108109

109110
@Test
@@ -115,7 +116,8 @@ public void sendRequest_someUniqueId_sendsUniqueIdToCommunicator() {
115116
session.sendRequest(null, null, someUniqueId);
116117

117118
// Then
118-
verify(communicator, times(1)).sendCall(eq(someUniqueId), anyString(), any());
119+
// TODO uuid and request should not be nullable
120+
verify(communicator, times(1)).sendCall(eq(someUniqueId), nullable(String.class), nullable(Request.class));
119121
}
120122

121123
@Test
@@ -153,7 +155,7 @@ public void open_connectsViaCommunicator() {
153155
public void onCall_unhandledCallback_callSendCallError() throws Exception {
154156
// Given
155157
String someId = "Some id";
156-
doAnswer(invocation -> invocation.getArgumentAt(0, CompletableFuture.class).complete(null))
158+
doAnswer(invocation -> invocation.getArgument(0, CompletableFuture.class).complete(null))
157159
.when(fulfiller)
158160
.fulfill(any(), any(), any());
159161
when(communicator.unpackPayload(any(), any())).thenReturn(new TestRequest());
@@ -162,7 +164,8 @@ public void onCall_unhandledCallback_callSendCallError() throws Exception {
162164
eventHandler.onCall(someId, null, null);
163165

164166
// then
165-
verify(communicator, times(1)).sendCallError(eq(someId), anyString(), anyString(), anyString());
167+
// TODO action should not be nullable
168+
verify(communicator, times(1)).sendCallError(eq(someId), nullable(String.class), anyString(), anyString());
166169
}
167170

168171
@Test
@@ -178,7 +181,7 @@ public boolean validate() {
178181

179182
doAnswer(
180183
invocation ->
181-
invocation.getArgumentAt(0, CompletableFuture.class).complete(aConfirmation))
184+
invocation.getArgument(0, CompletableFuture.class).complete(aConfirmation))
182185
.when(fulfiller)
183186
.fulfill(any(), any(), any());
184187
when(communicator.unpackPayload(any(), any())).thenReturn(new TestRequest());
@@ -187,7 +190,8 @@ public boolean validate() {
187190
eventHandler.onCall(someId, null, null);
188191

189192
// then
190-
verify(communicator, times(1)).sendCallResult(anyString(), anyString(), eq(aConfirmation));
193+
// TODO action should not be nullable
194+
verify(communicator, times(1)).sendCallResult(anyString(), nullable(String.class), eq(aConfirmation));
191195
}
192196

193197
@Test
@@ -197,7 +201,7 @@ public void onCall_callbackThrowsException_callSendCallResult() throws Exception
197201
doAnswer(
198202
invocation ->
199203
invocation
200-
.getArgumentAt(0, CompletableFuture.class)
204+
.getArgument(0, CompletableFuture.class)
201205
.completeExceptionally(new Exception()))
202206
.when(fulfiller)
203207
.fulfill(any(), any(), any());
@@ -207,7 +211,8 @@ public void onCall_callbackThrowsException_callSendCallResult() throws Exception
207211
eventHandler.onCall(someId, null, null);
208212

209213
// then
210-
verify(communicator, times(1)).sendCallError(eq(someId), anyString(), anyString(), anyString());
214+
// TODO uniqueid should not be nullable
215+
verify(communicator, times(1)).sendCallError(eq(someId), nullable(String.class), anyString(), anyString());
211216
}
212217

213218
@Test
@@ -229,6 +234,7 @@ public void onCall_unknownAction_callSendCallError() {
229234
eventHandler.onCall(someId, null, null);
230235

231236
// Then
232-
verify(communicator, times(1)).sendCallError(eq(someId), anyString(), anyString(), anyString());
237+
// TODO uniqueid should not be nullable
238+
verify(communicator, times(1)).sendCallError(eq(someId), nullable(String.class), anyString(), anyString());
233239
}
234240
}

ocpp-common/src/test/java/eu/chargetime/ocpp/test/SimpleRequestDispatcherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
2727

2828
import static org.hamcrest.CoreMatchers.is;
2929
import static org.junit.Assert.assertThat;
30-
import static org.mockito.Matchers.any;
30+
import static org.mockito.ArgumentMatchers.any;
3131
import static org.mockito.Mockito.when;
3232

3333
import eu.chargetime.ocpp.SessionEvents;
@@ -38,7 +38,7 @@ of this software and associated documentation files (the "Software"), to deal
3838
import org.junit.Test;
3939
import org.junit.runner.RunWith;
4040
import org.mockito.Mock;
41-
import org.mockito.runners.MockitoJUnitRunner;
41+
import org.mockito.junit.MockitoJUnitRunner;
4242

4343
@RunWith(MockitoJUnitRunner.class)
4444
public class SimpleRequestDispatcherTest {

0 commit comments

Comments
 (0)