Migrate to BDD Mockito
Migrate all tests to consistently use BDD Mockito. Also add checksyle rule to enforce going forwards.
This commit is contained in:
@@ -67,13 +67,13 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link StompSubProtocolHandler} tests.
|
||||
@@ -99,7 +99,7 @@ public class StompSubProtocolHandlerTests {
|
||||
this.channel = Mockito.mock(MessageChannel.class);
|
||||
this.messageCaptor = ArgumentCaptor.forClass(Message.class);
|
||||
|
||||
when(this.channel.send(any())).thenReturn(true);
|
||||
given(this.channel.send(any())).willReturn(true);
|
||||
|
||||
this.session = new TestWebSocketSession();
|
||||
this.session.setId("s1");
|
||||
@@ -223,7 +223,7 @@ public class StompSubProtocolHandlerTests {
|
||||
public void handleMessageToClientWithHeartbeatSuppressingSockJsHeartbeat() throws IOException {
|
||||
|
||||
SockJsSession sockJsSession = Mockito.mock(SockJsSession.class);
|
||||
when(sockJsSession.getId()).thenReturn("s1");
|
||||
given(sockJsSession.getId()).willReturn("s1");
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
|
||||
accessor.setHeartbeat(0, 10);
|
||||
Message<byte[]> message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
|
||||
@@ -236,7 +236,7 @@ public class StompSubProtocolHandlerTests {
|
||||
verifyNoMoreInteractions(sockJsSession);
|
||||
|
||||
sockJsSession = Mockito.mock(SockJsSession.class);
|
||||
when(sockJsSession.getId()).thenReturn("s1");
|
||||
given(sockJsSession.getId()).willReturn("s1");
|
||||
accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
|
||||
accessor.setHeartbeat(0, 0);
|
||||
message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
|
||||
|
||||
@@ -54,11 +54,11 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.notNull;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link WebSocketStompClient}.
|
||||
@@ -95,8 +95,8 @@ public class WebSocketStompClientTests {
|
||||
|
||||
this.webSocketHandlerCaptor = ArgumentCaptor.forClass(WebSocketHandler.class);
|
||||
this.handshakeFuture = new SettableListenableFuture<>();
|
||||
when(webSocketClient.doHandshake(this.webSocketHandlerCaptor.capture(), any(), any(URI.class)))
|
||||
.thenReturn(this.handshakeFuture);
|
||||
given(webSocketClient.doHandshake(this.webSocketHandlerCaptor.capture(), any(), any(URI.class)))
|
||||
.willReturn(this.handshakeFuture);
|
||||
}
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ public class WebSocketStompClientTests {
|
||||
TcpConnection<byte[]> tcpConnection = getTcpConnection();
|
||||
|
||||
ScheduledFuture future = mock(ScheduledFuture.class);
|
||||
when(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).thenReturn(future);
|
||||
given(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).willReturn(future);
|
||||
|
||||
tcpConnection.onReadInactivity(mock(Runnable.class), 2L);
|
||||
tcpConnection.onWriteInactivity(mock(Runnable.class), 2L);
|
||||
|
||||
@@ -43,7 +43,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.springframework.web.socket.sockjs.client.SockJsClient}.
|
||||
@@ -182,7 +181,7 @@ public class SockJsClientTests {
|
||||
|
||||
private ArgumentCaptor<HttpHeaders> setupInfoRequest(boolean webSocketEnabled) {
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = ArgumentCaptor.forClass(HttpHeaders.class);
|
||||
when(this.infoReceiver.executeInfoRequest(any(), headersCaptor.capture())).thenReturn(
|
||||
given(this.infoReceiver.executeInfoRequest(any(), headersCaptor.capture())).willReturn(
|
||||
"{\"entropy\":123," +
|
||||
"\"origins\":[\"*:*\"]," +
|
||||
"\"cookie_needed\":true," +
|
||||
|
||||
Reference in New Issue
Block a user