Clean up Mockito usage
This commit migrates to the MockitoJUnitRunner where sensible, which will later allow for an easier migration to Mockito's extension for JUnit Jupiter. In addition, this commit deletes unnecessary stubbing for various mocks and polishes test fixture setup in various test classes.
This commit is contained in:
parent
d495902a9c
commit
141ef9082f
|
|
@ -25,9 +25,11 @@ import java.sql.Types;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.jdbc.support.lob.LobCreator;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
|
|
@ -36,11 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test cases for the sql lob value:
|
||||
* Test cases for the SQL LOB value:
|
||||
*
|
||||
* BLOB:
|
||||
* 1. Types.BLOB: setBlobAsBytes (byte[])
|
||||
|
|
@ -55,10 +56,16 @@ import static org.mockito.Mockito.verify;
|
|||
*
|
||||
* @author Alef Arendsen
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SqlLobValueTests {
|
||||
|
||||
@Mock
|
||||
private PreparedStatement preparedStatement;
|
||||
|
||||
@Mock
|
||||
private LobHandler handler;
|
||||
|
||||
@Mock
|
||||
private LobCreator creator;
|
||||
|
||||
@Captor
|
||||
|
|
@ -66,10 +73,6 @@ public class SqlLobValueTests {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
preparedStatement = mock(PreparedStatement.class);
|
||||
handler = mock(LobHandler.class);
|
||||
creator = mock(LobCreator.class);
|
||||
given(handler.getLobCreator()).willReturn(creator);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ import javax.jms.TextMessage;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
|
@ -65,6 +65,7 @@ import static org.mockito.Mockito.verify;
|
|||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JmsMessagingTemplateTests {
|
||||
|
||||
@Captor
|
||||
|
|
@ -78,7 +79,6 @@ public class JmsMessagingTemplateTests {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.messagingTemplate = new JmsMessagingTemplate(this.jmsTemplate);
|
||||
}
|
||||
|
||||
|
|
@ -108,8 +108,6 @@ public class JmsMessagingTemplateTests {
|
|||
|
||||
@Test
|
||||
public void customConverterAlwaysTakesPrecedence() {
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
given(this.jmsTemplate.getMessageConverter()).willReturn(messageConverter);
|
||||
MessageConverter customMessageConverter = mock(MessageConverter.class);
|
||||
JmsMessagingTemplate messagingTemplate = new JmsMessagingTemplate();
|
||||
messagingTemplate.setJmsMessageConverter(
|
||||
|
|
@ -648,11 +646,11 @@ public class JmsMessagingTemplateTests {
|
|||
|
||||
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
|
||||
Session mock = mock(Session.class);
|
||||
given(mock.createTextMessage(BDDMockito.any())).willAnswer(
|
||||
given(mock.createTextMessage(any())).willAnswer(
|
||||
(Answer<TextMessage>) invocation ->
|
||||
new StubTextMessage((String) invocation.getArguments()[0]));
|
||||
javax.jms.Message message = creator.createMessage(mock);
|
||||
verify(mock).createTextMessage(BDDMockito.any());
|
||||
verify(mock).createTextMessage(any());
|
||||
return TextMessage.class.cast(message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,34 +19,25 @@ package org.springframework.messaging.simp;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Unit tests for
|
||||
* {@link org.springframework.messaging.simp.SimpAttributes}.
|
||||
* Unit tests for {@link SimpAttributes}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1
|
||||
*/
|
||||
public class SimpAttributesTests {
|
||||
|
||||
private SimpAttributes simpAttributes;
|
||||
private final Map<String, Object> map = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, Object> map;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.map = new ConcurrentHashMap<>();
|
||||
this.simpAttributes = new SimpAttributes("session1", this.map);
|
||||
}
|
||||
private final SimpAttributes simpAttributes = new SimpAttributes("session1", this.map);
|
||||
|
||||
|
||||
@Test
|
||||
|
|
@ -69,7 +60,7 @@ public class SimpAttributesTests {
|
|||
|
||||
@Test
|
||||
public void registerDestructionCallback() {
|
||||
Runnable callback = Mockito.mock(Runnable.class);
|
||||
Runnable callback = mock(Runnable.class);
|
||||
this.simpAttributes.registerDestructionCallback("name1", callback);
|
||||
|
||||
assertThat(this.simpAttributes.getAttribute(
|
||||
|
|
@ -80,14 +71,14 @@ public class SimpAttributesTests {
|
|||
public void registerDestructionCallbackAfterSessionCompleted() {
|
||||
this.simpAttributes.sessionCompleted();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpAttributes.registerDestructionCallback("name1", Mockito.mock(Runnable.class)))
|
||||
this.simpAttributes.registerDestructionCallback("name1", mock(Runnable.class)))
|
||||
.withMessageContaining("already completed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeDestructionCallback() {
|
||||
Runnable callback1 = Mockito.mock(Runnable.class);
|
||||
Runnable callback2 = Mockito.mock(Runnable.class);
|
||||
Runnable callback1 = mock(Runnable.class);
|
||||
Runnable callback2 = mock(Runnable.class);
|
||||
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
||||
this.simpAttributes.registerDestructionCallback("name2", callback2);
|
||||
|
||||
|
|
@ -109,8 +100,8 @@ public class SimpAttributesTests {
|
|||
|
||||
@Test
|
||||
public void sessionCompleted() {
|
||||
Runnable callback1 = Mockito.mock(Runnable.class);
|
||||
Runnable callback2 = Mockito.mock(Runnable.class);
|
||||
Runnable callback1 = mock(Runnable.class);
|
||||
Runnable callback2 = mock(Runnable.class);
|
||||
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
||||
this.simpAttributes.registerDestructionCallback("name2", callback2);
|
||||
|
||||
|
|
@ -122,7 +113,7 @@ public class SimpAttributesTests {
|
|||
|
||||
@Test
|
||||
public void sessionCompletedIsIdempotent() {
|
||||
Runnable callback1 = Mockito.mock(Runnable.class);
|
||||
Runnable callback1 = mock(Runnable.class);
|
||||
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
||||
|
||||
this.simpAttributes.sessionCompleted();
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ import javax.security.auth.Subject;
|
|||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
|
@ -58,6 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
|
|
@ -68,6 +69,7 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Sebastien Deleuze
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SendToMethodReturnValueHandlerTests {
|
||||
|
||||
private static final MimeType MIME_TYPE = new MimeType("text", "plain", StandardCharsets.UTF_8);
|
||||
|
|
@ -75,16 +77,18 @@ public class SendToMethodReturnValueHandlerTests {
|
|||
private static final String PAYLOAD = "payload";
|
||||
|
||||
|
||||
@Mock
|
||||
private MessageChannel messageChannel;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Message<?>> messageCaptor;
|
||||
|
||||
private SendToMethodReturnValueHandler handler;
|
||||
|
||||
private SendToMethodReturnValueHandler handlerAnnotationNotRequired;
|
||||
|
||||
private SendToMethodReturnValueHandler jsonHandler;
|
||||
|
||||
@Mock private MessageChannel messageChannel;
|
||||
|
||||
@Captor private ArgumentCaptor<Message<?>> messageCaptor;
|
||||
|
||||
private MethodParameter noAnnotationsReturnType = param("handleNoAnnotations");
|
||||
private MethodParameter sendToReturnType = param("handleAndSendTo");
|
||||
private MethodParameter sendToDefaultDestReturnType = param("handleAndSendToDefaultDest");
|
||||
|
|
@ -118,8 +122,6 @@ public class SendToMethodReturnValueHandlerTests {
|
|||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
|
||||
messagingTemplate.setMessageConverter(new StringMessageConverter());
|
||||
this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
|
||||
|
|
@ -319,7 +321,7 @@ public class SendToMethodReturnValueHandlerTests {
|
|||
public void testHeadersToSend() throws Exception {
|
||||
Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);
|
||||
|
||||
SimpMessageSendingOperations messagingTemplate = Mockito.mock(SimpMessageSendingOperations.class);
|
||||
SimpMessageSendingOperations messagingTemplate = mock(SimpMessageSendingOperations.class);
|
||||
SendToMethodReturnValueHandler handler = new SendToMethodReturnValueHandler(messagingTemplate, false);
|
||||
|
||||
handler.handleReturnValue(PAYLOAD, this.noAnnotationsReturnType, message);
|
||||
|
|
@ -630,10 +632,12 @@ public class SendToMethodReturnValueHandlerTests {
|
|||
|
||||
private static class TestUser implements Principal {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "joe";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implies(Subject subject) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxProcessor;
|
||||
|
|
@ -74,22 +75,18 @@ import static org.mockito.Mockito.never;
|
|||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test fixture for
|
||||
* {@link org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler}.
|
||||
* Test fixture for {@link SimpAnnotationMethodMessageHandler}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SimpAnnotationMethodMessageHandlerTests {
|
||||
|
||||
private static final String TEST_INVALID_VALUE = "invalidValue";
|
||||
|
||||
|
||||
private TestSimpAnnotationMethodMessageHandler messageHandler;
|
||||
|
||||
private TestController testController;
|
||||
|
||||
@Mock
|
||||
private SubscribableChannel channel;
|
||||
|
||||
|
|
@ -99,11 +96,13 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
|||
@Captor
|
||||
private ArgumentCaptor<Object> payloadCaptor;
|
||||
|
||||
private TestSimpAnnotationMethodMessageHandler messageHandler;
|
||||
|
||||
private TestController testController = new TestController();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
|
||||
brokerTemplate.setMessageConverter(this.converter);
|
||||
|
||||
|
|
@ -111,8 +110,6 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
|||
this.messageHandler.setApplicationContext(new StaticApplicationContext());
|
||||
this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
|
||||
this.messageHandler.afterPropertiesSet();
|
||||
|
||||
this.testController = new TestController();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -287,12 +284,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void listenableFutureFailure() {
|
||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
||||
|
||||
ListenableFutureController controller = new ListenableFutureController();
|
||||
this.messageHandler.registerHandler(controller);
|
||||
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
|
||||
|
|
@ -325,12 +317,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void completableFutureFailure() {
|
||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
||||
|
||||
CompletableFutureController controller = new CompletableFutureController();
|
||||
this.messageHandler.registerHandler(controller);
|
||||
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
|
||||
|
|
@ -363,12 +350,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void monoFailure() {
|
||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
||||
|
||||
ReactiveController controller = new ReactiveController();
|
||||
this.messageHandler.registerHandler(controller);
|
||||
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
|
||||
|
|
@ -381,12 +363,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void fluxNotHandled() {
|
||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
||||
|
||||
ReactiveController controller = new ReactiveController();
|
||||
this.messageHandler.registerHandler(controller);
|
||||
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ import java.security.Principal;
|
|||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.messaging.Message;
|
||||
|
|
@ -49,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
|
|
@ -57,6 +58,7 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Rossen Stoyanchev
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SubscriptionMethodReturnValueHandlerTests {
|
||||
|
||||
public static final MimeType MIME_TYPE = new MimeType("text", "plain", StandardCharsets.UTF_8);
|
||||
|
|
@ -64,14 +66,16 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
|||
private static final String PAYLOAD = "payload";
|
||||
|
||||
|
||||
@Mock
|
||||
private MessageChannel messageChannel;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Message<?>> messageCaptor;
|
||||
|
||||
private SubscriptionMethodReturnValueHandler handler;
|
||||
|
||||
private SubscriptionMethodReturnValueHandler jsonHandler;
|
||||
|
||||
@Mock private MessageChannel messageChannel;
|
||||
|
||||
@Captor private ArgumentCaptor<Message<?>> messageCaptor;
|
||||
|
||||
private MethodParameter subscribeEventReturnType;
|
||||
|
||||
private MethodParameter subscribeEventSendToReturnType;
|
||||
|
|
@ -83,8 +87,6 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
|||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
|
||||
messagingTemplate.setMessageConverter(new StringMessageConverter());
|
||||
this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
|
||||
|
|
@ -148,7 +150,7 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
|||
String destination = "/dest";
|
||||
Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);
|
||||
|
||||
MessageSendingOperations messagingTemplate = Mockito.mock(MessageSendingOperations.class);
|
||||
MessageSendingOperations messagingTemplate = mock(MessageSendingOperations.class);
|
||||
SubscriptionMethodReturnValueHandler handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
|
||||
|
||||
handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
|
@ -42,14 +40,7 @@ import static org.mockito.Mockito.mock;
|
|||
*/
|
||||
public class BrokerMessageHandlerTests {
|
||||
|
||||
private TestBrokerMessageHandler handler;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.handler = new TestBrokerMessageHandler();
|
||||
}
|
||||
private final TestBrokerMessageHandler handler = new TestBrokerMessageHandler();
|
||||
|
||||
|
||||
@Test
|
||||
|
|
@ -61,7 +52,6 @@ public class BrokerMessageHandlerTests {
|
|||
|
||||
@Test
|
||||
public void stopShouldUpdateIsRunning() {
|
||||
|
||||
this.handler.start();
|
||||
assertThat(this.handler.isRunning()).isTrue();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ import java.util.concurrent.ScheduledFuture;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
|
@ -56,11 +57,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@SuppressWarnings("unchecked")
|
||||
public class SimpleBrokerMessageHandlerTests {
|
||||
|
||||
private SimpleBrokerMessageHandler messageHandler;
|
||||
|
||||
|
||||
@Mock
|
||||
private SubscribableChannel clientInChannel;
|
||||
|
||||
|
|
@ -79,7 +82,6 @@ public class SimpleBrokerMessageHandlerTests {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.messageHandler = new SimpleBrokerMessageHandler(
|
||||
this.clientInChannel, this.clientOutChannel, this.brokerChannel, Collections.emptyList());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageDeliveryException;
|
||||
|
|
@ -60,15 +61,17 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultStompSessionTests {
|
||||
|
||||
private DefaultStompSession session;
|
||||
|
||||
private StompHeaders connectHeaders;
|
||||
|
||||
|
||||
@Mock
|
||||
private StompSessionHandler sessionHandler;
|
||||
|
||||
private StompHeaders connectHeaders;
|
||||
|
||||
@Mock
|
||||
private TcpConnection<byte[]> connection;
|
||||
|
||||
|
|
@ -78,9 +81,6 @@ public class DefaultStompSessionTests {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
this.sessionHandler = mock(StompSessionHandler.class);
|
||||
this.connectHeaders = new StompHeaders();
|
||||
this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders);
|
||||
this.session.setMessageConverter(new StringMessageConverter());
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ import java.util.concurrent.ScheduledFuture;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
|
@ -50,6 +50,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
* User tests for {@link UserRegistryMessageHandler}.
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UserRegistryMessageHandlerTests {
|
||||
|
||||
private UserRegistryMessageHandler handler;
|
||||
|
|
@ -60,6 +61,7 @@ public class UserRegistryMessageHandlerTests {
|
|||
|
||||
private MessageConverter converter;
|
||||
|
||||
|
||||
@Mock
|
||||
private MessageChannel brokerChannel;
|
||||
|
||||
|
|
@ -69,9 +71,6 @@ public class UserRegistryMessageHandlerTests {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
given(this.brokerChannel.send(any())).willReturn(true);
|
||||
this.converter = new MappingJackson2MessageConverter();
|
||||
|
||||
|
|
@ -95,7 +94,7 @@ public class UserRegistryMessageHandlerTests {
|
|||
@Test
|
||||
public void brokerUnavailableEvent() throws Exception {
|
||||
|
||||
ScheduledFuture future = Mockito.mock(ScheduledFuture.class);
|
||||
ScheduledFuture future = mock(ScheduledFuture.class);
|
||||
given(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), any(Long.class))).willReturn(future);
|
||||
|
||||
BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this);
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ package org.springframework.messaging.support;
|
|||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.messaging.Message;
|
||||
|
|
@ -46,6 +46,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
|||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ExecutorSubscribableChannelTests {
|
||||
|
||||
private ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
|
||||
|
|
@ -53,18 +54,12 @@ public class ExecutorSubscribableChannelTests {
|
|||
@Mock
|
||||
private MessageHandler handler;
|
||||
|
||||
private final Object payload = new Object();
|
||||
|
||||
private final Message<Object> message = MessageBuilder.withPayload(this.payload).build();
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Runnable> runnableCaptor;
|
||||
|
||||
private final Object payload = new Object();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
private final Message<Object> message = MessageBuilder.withPayload(this.payload).build();
|
||||
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
|
@ -57,6 +57,7 @@ import static org.springframework.http.MediaType.TEXT_XML;
|
|||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EncoderHttpMessageWriterTests {
|
||||
|
||||
private static final Map<String, Object> NO_HINTS = Collections.emptyMap();
|
||||
|
|
@ -67,17 +68,9 @@ public class EncoderHttpMessageWriterTests {
|
|||
@Mock
|
||||
private HttpMessageEncoder<String> encoder;
|
||||
|
||||
private ArgumentCaptor<MediaType> mediaTypeCaptor;
|
||||
private final ArgumentCaptor<MediaType> mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
|
||||
|
||||
private MockServerHttpResponse response;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
|
||||
this.response = new MockServerHttpResponse();
|
||||
}
|
||||
private final MockServerHttpResponse response = new MockServerHttpResponse();
|
||||
|
||||
|
||||
@Test
|
||||
|
|
@ -116,9 +109,6 @@ public class EncoderHttpMessageWriterTests {
|
|||
}
|
||||
|
||||
private void testDefaultMediaType(MediaType negotiatedMediaType) {
|
||||
|
||||
this.mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
|
||||
|
||||
MimeType defaultContentType = MimeTypeUtils.TEXT_XML;
|
||||
configureEncoder(defaultContentType);
|
||||
HttpMessageWriter<String> writer = new EncoderHttpMessageWriter<>(this.encoder);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server.session;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -49,10 +50,6 @@ import static org.mockito.Mockito.verify;
|
|||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultWebSessionManagerTests {
|
||||
|
||||
private DefaultWebSessionManager sessionManager;
|
||||
|
||||
private ServerWebExchange exchange;
|
||||
|
||||
@Mock
|
||||
private WebSessionIdResolver sessionIdResolver;
|
||||
|
||||
|
|
@ -65,10 +62,13 @@ public class DefaultWebSessionManagerTests {
|
|||
@Mock
|
||||
private WebSession updateSession;
|
||||
|
||||
private DefaultWebSessionManager sessionManager;
|
||||
|
||||
private ServerWebExchange exchange;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
given(this.createSession.save()).willReturn(Mono.empty());
|
||||
given(this.createSession.getId()).willReturn("create-session-id");
|
||||
given(this.updateSession.getId()).willReturn("update-session-id");
|
||||
|
|
|
|||
|
|
@ -21,10 +21,11 @@ import java.util.List;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.ReactiveAdapterRegistry;
|
||||
|
|
@ -48,10 +49,9 @@ import static org.mockito.Mockito.verify;
|
|||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DelegatingWebFluxConfigurationTests {
|
||||
|
||||
private DelegatingWebFluxConfiguration delegatingConfig;
|
||||
|
||||
@Mock
|
||||
private WebFluxConfigurer webFluxConfigurer;
|
||||
|
||||
|
|
@ -64,10 +64,11 @@ public class DelegatingWebFluxConfigurationTests {
|
|||
@Captor
|
||||
private ArgumentCaptor<FormatterRegistry> formatterRegistry;
|
||||
|
||||
private DelegatingWebFluxConfiguration delegatingConfig;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
delegatingConfig = new DelegatingWebFluxConfiguration();
|
||||
delegatingConfig.setApplicationContext(new StaticApplicationContext());
|
||||
given(webFluxConfigurer.getValidator()).willReturn(null);
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ import java.util.Map;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
|
|
@ -39,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
|||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
|
|
@ -48,20 +50,20 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
|||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultWebClientTests {
|
||||
|
||||
private WebClient.Builder builder;
|
||||
|
||||
@Mock
|
||||
private ExchangeFunction exchangeFunction;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ClientRequest> captor;
|
||||
|
||||
private WebClient.Builder builder;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.exchangeFunction = mock(ExchangeFunction.class);
|
||||
ClientResponse mockResponse = mock(ClientResponse.class);
|
||||
given(this.exchangeFunction.exchange(this.captor.capture())).willReturn(Mono.just(mockResponse));
|
||||
this.builder = WebClient.builder().baseUrl("/base").exchangeFunction(this.exchangeFunction);
|
||||
|
|
@ -309,7 +311,7 @@ public class DefaultWebClientTests {
|
|||
|
||||
private ClientRequest verifyAndGetRequest() {
|
||||
ClientRequest request = this.captor.getValue();
|
||||
Mockito.verify(this.exchangeFunction).exchange(request);
|
||||
verify(this.exchangeFunction).exchange(request);
|
||||
verifyNoMoreInteractions(this.exchangeFunction);
|
||||
return request;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
|
|
@ -55,10 +55,9 @@ import static org.mockito.Mockito.verify;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DelegatingWebMvcConfigurationTests {
|
||||
|
||||
private DelegatingWebMvcConfiguration delegatingConfig;
|
||||
|
||||
@Mock
|
||||
private WebMvcConfigurer webMvcConfigurer;
|
||||
|
||||
|
|
@ -83,12 +82,7 @@ public class DelegatingWebMvcConfigurationTests {
|
|||
@Captor
|
||||
private ArgumentCaptor<List<HandlerExceptionResolver>> exceptionResolvers;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
delegatingConfig = new DelegatingWebMvcConfiguration();
|
||||
}
|
||||
private final DelegatingWebMvcConfiguration delegatingConfig = new DelegatingWebMvcConfiguration();
|
||||
|
||||
|
||||
@Test
|
||||
|
|
@ -134,7 +128,6 @@ public class DelegatingWebMvcConfigurationTests {
|
|||
converters.add(0, customConverter);
|
||||
}
|
||||
});
|
||||
delegatingConfig = new DelegatingWebMvcConfiguration();
|
||||
delegatingConfig.setConfigurers(configurers);
|
||||
|
||||
RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter(
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
|
|
@ -34,34 +32,27 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
|||
import org.springframework.web.servlet.support.WebContentGenerator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Unit tests for
|
||||
* {@link org.springframework.web.servlet.handler.HandlerMappingTests}.
|
||||
* Unit tests for {@link org.springframework.web.servlet.HandlerMapping}.
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class HandlerMappingTests {
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
private AbstractHandlerMapping handlerMapping;
|
||||
private StaticWebApplicationContext context;
|
||||
private AbstractHandlerMapping handlerMapping = new TestHandlerMapping();
|
||||
private StaticWebApplicationContext context = new StaticWebApplicationContext();
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.context = new StaticWebApplicationContext();
|
||||
this.handlerMapping = new TestHandlerMapping();
|
||||
this.request = new MockHttpServletRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderedInterceptors() throws Exception {
|
||||
HandlerInterceptor i1 = Mockito.mock(HandlerInterceptor.class);
|
||||
HandlerInterceptor i1 = mock(HandlerInterceptor.class);
|
||||
MappedInterceptor mappedInterceptor1 = new MappedInterceptor(new String[]{"/**"}, i1);
|
||||
HandlerInterceptor i2 = Mockito.mock(HandlerInterceptor.class);
|
||||
HandlerInterceptor i3 = Mockito.mock(HandlerInterceptor.class);
|
||||
HandlerInterceptor i2 = mock(HandlerInterceptor.class);
|
||||
HandlerInterceptor i3 = mock(HandlerInterceptor.class);
|
||||
MappedInterceptor mappedInterceptor3 = new MappedInterceptor(new String[]{"/**"}, i3);
|
||||
HandlerInterceptor i4 = Mockito.mock(HandlerInterceptor.class);
|
||||
HandlerInterceptor i4 = mock(HandlerInterceptor.class);
|
||||
|
||||
this.handlerMapping.setInterceptors(mappedInterceptor1, i2, mappedInterceptor3, i4);
|
||||
this.handlerMapping.setApplicationContext(this.context);
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ package org.springframework.web.servlet.mvc.method.annotation;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
|
|
@ -42,19 +42,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
* @author Rossen Stoyanchev
|
||||
* @author Tomasz Nurkiewicz
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ResponseBodyEmitterTests {
|
||||
|
||||
private ResponseBodyEmitter emitter;
|
||||
|
||||
@Mock
|
||||
private ResponseBodyEmitter.Handler handler;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.emitter = new ResponseBodyEmitter();
|
||||
}
|
||||
private final ResponseBodyEmitter emitter = new ResponseBodyEmitter();
|
||||
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -22,9 +22,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.ConversionNotSupportedException;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
|
|
@ -62,6 +60,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
|||
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link ResponseEntityExceptionHandler}.
|
||||
|
|
@ -70,26 +69,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
public class ResponseEntityExceptionHandlerTests {
|
||||
|
||||
private ResponseEntityExceptionHandler exceptionHandlerSupport;
|
||||
private ResponseEntityExceptionHandler exceptionHandlerSupport = new ApplicationExceptionHandler();
|
||||
|
||||
private DefaultHandlerExceptionResolver defaultExceptionResolver;
|
||||
private DefaultHandlerExceptionResolver defaultExceptionResolver = new DefaultHandlerExceptionResolver();
|
||||
|
||||
private WebRequest request;
|
||||
private MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/");
|
||||
|
||||
private MockHttpServletRequest servletRequest;
|
||||
private MockHttpServletResponse servletResponse = new MockHttpServletResponse();
|
||||
|
||||
private MockHttpServletResponse servletResponse;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.servletRequest = new MockHttpServletRequest("GET", "/");
|
||||
this.servletResponse = new MockHttpServletResponse();
|
||||
this.request = new ServletWebRequest(this.servletRequest, this.servletResponse);
|
||||
|
||||
this.exceptionHandlerSupport = new ApplicationExceptionHandler();
|
||||
this.defaultExceptionResolver = new DefaultHandlerExceptionResolver();
|
||||
}
|
||||
private WebRequest request = new ServletWebRequest(this.servletRequest, this.servletResponse);
|
||||
|
||||
|
||||
@Test
|
||||
|
|
@ -179,7 +167,7 @@ public class ResponseEntityExceptionHandlerTests {
|
|||
|
||||
@Test
|
||||
public void methodArgumentNotValid() {
|
||||
Exception ex = Mockito.mock(MethodArgumentNotValidException.class);
|
||||
Exception ex = mock(MethodArgumentNotValidException.class);
|
||||
testException(ex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ package org.springframework.web.socket.config.annotation;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
|
|
@ -37,26 +35,20 @@ import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsServ
|
|||
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test fixture for
|
||||
* {@link org.springframework.web.socket.config.annotation.AbstractWebSocketHandlerRegistration}.
|
||||
* Test fixture for {@link AbstractWebSocketHandlerRegistration}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class WebSocketHandlerRegistrationTests {
|
||||
|
||||
private TestWebSocketHandlerRegistration registration;
|
||||
private TestWebSocketHandlerRegistration registration = new TestWebSocketHandlerRegistration();
|
||||
|
||||
private TaskScheduler taskScheduler;
|
||||
private TaskScheduler taskScheduler = mock(TaskScheduler.class);
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.taskScheduler = Mockito.mock(TaskScheduler.class);
|
||||
this.registration = new TestWebSocketHandlerRegistration();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minimal() {
|
||||
WebSocketHandler handler = new TextWebSocketHandler();
|
||||
|
|
|
|||
|
|
@ -21,8 +21,9 @@ import java.util.Map;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
|
@ -46,12 +47,9 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Rossen Stoyanchev
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SubProtocolWebSocketHandlerTests {
|
||||
|
||||
private SubProtocolWebSocketHandler webSocketHandler;
|
||||
|
||||
private TestWebSocketSession session;
|
||||
|
||||
@Mock SubProtocolHandler stompHandler;
|
||||
|
||||
@Mock SubProtocolHandler mqttHandler;
|
||||
|
|
@ -63,10 +61,13 @@ public class SubProtocolWebSocketHandlerTests {
|
|||
@Mock
|
||||
SubscribableChannel outClientChannel;
|
||||
|
||||
private SubProtocolWebSocketHandler webSocketHandler;
|
||||
|
||||
private TestWebSocketSession session;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel);
|
||||
given(stompHandler.getSupportedProtocols()).willReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
|
||||
given(mqttHandler.getSupportedProtocols()).willReturn(Arrays.asList("MQTT"));
|
||||
|
|
|
|||
|
|
@ -22,9 +22,10 @@ import java.util.concurrent.ScheduledFuture;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.simp.stomp.ConnectionHandlingStompSession;
|
||||
|
|
@ -63,6 +64,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WebSocketStompClientTests {
|
||||
|
||||
@Mock
|
||||
|
|
@ -74,7 +76,6 @@ public class WebSocketStompClientTests {
|
|||
@Mock
|
||||
private WebSocketSession webSocketSession;
|
||||
|
||||
|
||||
private TestWebSocketStompClient stompClient;
|
||||
|
||||
private ArgumentCaptor<WebSocketHandler> webSocketHandlerCaptor;
|
||||
|
|
@ -84,8 +85,6 @@ public class WebSocketStompClientTests {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
WebSocketClient webSocketClient = mock(WebSocketClient.class);
|
||||
this.stompClient = new TestWebSocketStompClient(webSocketClient);
|
||||
this.stompClient.setTaskScheduler(this.taskScheduler);
|
||||
|
|
|
|||
|
|
@ -21,10 +21,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.SubProtocolCapable;
|
||||
|
|
@ -35,6 +32,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
|||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
|
|
@ -44,19 +42,9 @@ import static org.mockito.Mockito.verify;
|
|||
*/
|
||||
public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
|
||||
|
||||
private DefaultHandshakeHandler handshakeHandler;
|
||||
private RequestUpgradeStrategy upgradeStrategy = mock(RequestUpgradeStrategy.class);
|
||||
|
||||
@Mock
|
||||
private RequestUpgradeStrategy upgradeStrategy;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
super.setup();
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.handshakeHandler = new DefaultHandshakeHandler(this.upgradeStrategy);
|
||||
}
|
||||
private DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(this.upgradeStrategy);
|
||||
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.mock.web.test.MockHttpSession;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link HttpSessionHandshakeInterceptor}.
|
||||
|
|
@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
|
||||
private final Map<String, Object> attributes = new HashMap<>();
|
||||
private final WebSocketHandler wsHandler = mock(WebSocketHandler.class);
|
||||
|
||||
|
||||
@Test
|
||||
public void defaultConstructor() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
|
||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||
this.servletRequest.getSession().setAttribute("bar", "baz");
|
||||
|
|
@ -58,9 +58,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
|||
|
||||
@Test
|
||||
public void constructorWithAttributeNames() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
|
||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||
this.servletRequest.getSession().setAttribute("bar", "baz");
|
||||
|
|
@ -76,9 +73,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
|||
|
||||
@Test
|
||||
public void doNotCopyHttpSessionId() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
|
||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||
|
||||
|
|
@ -93,9 +87,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
|||
|
||||
@Test
|
||||
public void doNotCopyAttributes() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
|
||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||
|
||||
|
|
@ -109,9 +100,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
|||
|
||||
@Test
|
||||
public void doNotCauseSessionCreation() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
|
||||
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
|
||||
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -34,6 +33,7 @@ import org.springframework.web.socket.WebSocketHandler;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link OriginHandshakeInterceptor}.
|
||||
|
|
@ -42,16 +42,17 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
|||
*/
|
||||
public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
|
||||
private final Map<String, Object> attributes = new HashMap<>();
|
||||
private final WebSocketHandler wsHandler = mock(WebSocketHandler.class);
|
||||
|
||||
|
||||
@Test
|
||||
public void invalidInput() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new OriginHandshakeInterceptor(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new OriginHandshakeInterceptor(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void originValueMatch() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
List<String> allowed = Collections.singletonList("https://mydomain1.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
|
|
@ -61,8 +62,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void originValueNoMatch() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
List<String> allowed = Collections.singletonList("https://mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
|
|
@ -72,8 +71,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void originListMatch() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.com");
|
||||
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
|
|
@ -83,8 +80,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void originListNoMatch() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.com/");
|
||||
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
|
|
@ -94,8 +89,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void originNoMatchWithNullHostileCollection() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.com/");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
|
||||
Set<String> allowedOrigins = new ConcurrentSkipListSet<>();
|
||||
|
|
@ -107,8 +100,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void originMatchAll() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
|
||||
interceptor.setAllowedOrigins(Collections.singletonList("*"));
|
||||
|
|
@ -118,8 +109,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void sameOriginMatchWithEmptyAllowedOrigins() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
||||
|
|
@ -129,8 +118,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void sameOriginMatchWithAllowedOrigins() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Arrays.asList("http://mydomain1.com"));
|
||||
|
|
@ -140,8 +127,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
|||
|
||||
@Test
|
||||
public void sameOriginNoMatch() throws Exception {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain3.com");
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ import java.util.Map;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
|
|
@ -57,6 +58,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
* @author Sebastien Deleuze
|
||||
* @author Ben Kiefer
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
private static final String sockJsPrefix = "/mysockjs";
|
||||
|
|
@ -66,25 +68,30 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
|||
private static final String sessionUrlPrefix = "/server1/" + sessionId + "/";
|
||||
|
||||
|
||||
@Mock private SessionCreatingTransportHandler xhrHandler;
|
||||
@Mock
|
||||
private SessionCreatingTransportHandler xhrHandler;
|
||||
|
||||
@Mock private TransportHandler xhrSendHandler;
|
||||
@Mock
|
||||
private TransportHandler xhrSendHandler;
|
||||
|
||||
@Mock private HandshakeTransportHandler wsTransportHandler;
|
||||
@Mock
|
||||
private HandshakeTransportHandler wsTransportHandler;
|
||||
|
||||
@Mock private WebSocketHandler wsHandler;
|
||||
@Mock
|
||||
private WebSocketHandler wsHandler;
|
||||
|
||||
@Mock private TaskScheduler taskScheduler;
|
||||
@Mock
|
||||
private TaskScheduler taskScheduler;
|
||||
|
||||
private TestSockJsSession session;
|
||||
|
||||
private TransportHandlingSockJsService service;
|
||||
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setup() {
|
||||
super.setup();
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
Map<String, Object> attributes = Collections.emptyMap();
|
||||
this.session = new TestSockJsSession(sessionId, new StubSockJsServiceConfig(), this.wsHandler, attributes);
|
||||
|
|
|
|||
|
|
@ -167,10 +167,10 @@
|
|||
<property name="ignoreComments" value="true" />
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
|
||||
<property name="id" value="bddMockito"/>
|
||||
<property name="maximum" value="0"/>
|
||||
<property name="format" value="org\.mockito\.Mockito\.(when|doThrow|doAnswer)" />
|
||||
<property name="message"
|
||||
value="Please use BDDMockito imports." />
|
||||
<property name="message" value="Please use BDDMockito." />
|
||||
<property name="ignoreComments" value="true" />
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
|
||||
|
|
|
|||
Loading…
Reference in New Issue