Migrate Hamcrest assertions to AssertJ

Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ
and add checkstyle rules to ensure they don't return.

See gh-23022
This commit is contained in:
Phillip Webb
2019-05-23 15:48:03 -07:00
parent 2294625cf0
commit 95a9d46a87
322 changed files with 4358 additions and 4814 deletions

View File

@@ -33,11 +33,8 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.MimeType;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -57,8 +54,8 @@ public class MappingJackson2MessageConverterTests {
@Test
public void defaultConstructor() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
assertThat(converter.getSupportedMimeTypes(),
contains(new MimeType("application", "json")));
assertThat(converter.getSupportedMimeTypes())
.contains(new MimeType("application", "json"));
assertFalse(converter.getObjectMapper().getDeserializationConfig()
.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
}
@@ -67,7 +64,7 @@ public class MappingJackson2MessageConverterTests {
public void mimetypeParametrizedConstructor() {
MimeType mimetype = new MimeType("application", "xml", StandardCharsets.UTF_8);
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(mimetype);
assertThat(converter.getSupportedMimeTypes(), contains(mimetype));
assertThat(converter.getSupportedMimeTypes()).contains(mimetype);
assertFalse(converter.getObjectMapper().getDeserializationConfig()
.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
}
@@ -77,7 +74,7 @@ public class MappingJackson2MessageConverterTests {
MimeType jsonMimetype = new MimeType("application", "json", StandardCharsets.UTF_8);
MimeType xmlMimetype = new MimeType("application", "xml", StandardCharsets.UTF_8);
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(jsonMimetype, xmlMimetype);
assertThat(converter.getSupportedMimeTypes(), contains(jsonMimetype, xmlMimetype));
assertThat(converter.getSupportedMimeTypes()).contains(jsonMimetype, xmlMimetype);
assertFalse(converter.getObjectMapper().getDeserializationConfig()
.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
}
@@ -238,9 +235,9 @@ public class MappingJackson2MessageConverterTests {
Message<?> message = converter.toMessage(jsonViewResponse(), new MessageHeaders(map), returnType);
String actual = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
assertThat(actual, containsString("\"withView1\":\"with\""));
assertThat(actual, containsString("\"withView2\":\"with\""));
assertThat(actual, not(containsString("\"withoutView\":\"with\"")));
assertThat(actual).contains("\"withView1\":\"with\"");
assertThat(actual).contains("\"withView2\":\"with\"");
assertThat(actual).doesNotContain("\"withoutView\":\"with\"");
method = getClass().getDeclaredMethod("jsonViewPayload", JacksonViewBean.class);
MethodParameter param = new MethodParameter(method, 0);

View File

@@ -27,16 +27,16 @@ import org.xmlunit.diff.DifferenceEvaluator;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.tests.XmlContent;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.xmlunit.diff.ComparisonType.XML_STANDALONE;
import static org.xmlunit.diff.DifferenceEvaluators.Default;
import static org.xmlunit.diff.DifferenceEvaluators.chain;
import static org.xmlunit.diff.DifferenceEvaluators.downgradeDifferencesToEqual;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
/**
* @author Arjen Poutsma
@@ -92,7 +92,7 @@ public class MarshallingMessageConverterTests {
String actual = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat(actual, isSimilarTo("<myBean><name>Foo</name></myBean>").withDifferenceEvaluator(ev));
assertThat(XmlContent.of(actual)).isSimilarTo("<myBean><name>Foo</name></myBean>", ev);
}

View File

@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
@@ -41,8 +40,8 @@ import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -88,7 +87,7 @@ public class MethodMessageHandlerTests {
Map<String, HandlerMethod> handlerMethods = this.messageHandler.getHandlerMethods();
assertNotNull(handlerMethods);
assertThat(handlerMethods.keySet(), Matchers.hasSize(3));
assertThat(handlerMethods).hasSize(3);
}
@Test

View File

@@ -26,7 +26,6 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
@@ -47,8 +46,8 @@ import org.springframework.util.PathMatcher;
import org.springframework.util.RouteMatcher;
import org.springframework.util.SimpleRouteMatcher;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -70,9 +69,9 @@ public class MethodMessageHandlerTests {
Map<String, HandlerMethod> mappings = messageHandler.getHandlerMethods();
assertEquals(5, mappings.keySet().size());
assertThat(mappings.keySet(), Matchers.containsInAnyOrder(
assertThat(mappings).containsOnlyKeys(
"/handleMessage", "/handleMessageWithArgument", "/handleMessageWithError",
"/handleMessageMatch1", "/handleMessageMatch2"));
"/handleMessageMatch1", "/handleMessageMatch2");
}
@Test

View File

@@ -27,12 +27,13 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.messaging.support.MessageBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
/**
* Unit tests for
@@ -61,27 +62,27 @@ public class SimpAttributesContextHolderTests {
@Test
public void resetAttributes() {
SimpAttributesContextHolder.setAttributes(this.simpAttributes);
assertThat(SimpAttributesContextHolder.getAttributes(), sameInstance(this.simpAttributes));
assertThat(SimpAttributesContextHolder.getAttributes()).isSameAs(this.simpAttributes);
SimpAttributesContextHolder.resetAttributes();
assertThat(SimpAttributesContextHolder.getAttributes(), nullValue());
assertThat(SimpAttributesContextHolder.getAttributes()).isNull();
}
@Test
public void getAttributes() {
assertThat(SimpAttributesContextHolder.getAttributes(), nullValue());
assertThat(SimpAttributesContextHolder.getAttributes()).isNull();
SimpAttributesContextHolder.setAttributes(this.simpAttributes);
assertThat(SimpAttributesContextHolder.getAttributes(), sameInstance(this.simpAttributes));
assertThat(SimpAttributesContextHolder.getAttributes()).isSameAs(this.simpAttributes);
}
@Test
public void setAttributes() {
SimpAttributesContextHolder.setAttributes(this.simpAttributes);
assertThat(SimpAttributesContextHolder.getAttributes(), sameInstance(this.simpAttributes));
assertThat(SimpAttributesContextHolder.getAttributes()).isSameAs(this.simpAttributes);
SimpAttributesContextHolder.setAttributes(null);
assertThat(SimpAttributesContextHolder.getAttributes(), nullValue());
assertThat(SimpAttributesContextHolder.getAttributes()).isNull();
}
@Test
@@ -98,11 +99,11 @@ public class SimpAttributesContextHolderTests {
SimpAttributesContextHolder.setAttributesFromMessage(message);
SimpAttributes attrs = SimpAttributesContextHolder.getAttributes();
assertThat(attrs, notNullValue());
assertThat(attrs.getSessionId(), is(sessionId));
assertThat(attrs).isNotNull();
assertThat(attrs.getSessionId()).isEqualTo(sessionId);
attrs.setAttribute("name1", "value1");
assertThat(map.get("name1"), is("value1"));
assertThat(map.get("name1")).isEqualTo("value1");
}
@Test
@@ -125,7 +126,7 @@ public class SimpAttributesContextHolderTests {
@Test
public void currentAttributes() {
SimpAttributesContextHolder.setAttributes(this.simpAttributes);
assertThat(SimpAttributesContextHolder.currentAttributes(), sameInstance(this.simpAttributes));
assertThat(SimpAttributesContextHolder.currentAttributes()).isSameAs(this.simpAttributes);
}
@Test

View File

@@ -23,12 +23,8 @@ 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.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -57,8 +53,8 @@ public class SimpAttributesTests {
public void getAttribute() {
this.simpAttributes.setAttribute("name1", "value1");
assertThat(this.simpAttributes.getAttribute("name1"), is("value1"));
assertThat(this.simpAttributes.getAttribute("name2"), nullValue());
assertThat(this.simpAttributes.getAttribute("name1")).isEqualTo("value1");
assertThat(this.simpAttributes.getAttribute("name2")).isNull();
}
@Test
@@ -67,7 +63,8 @@ public class SimpAttributesTests {
this.simpAttributes.setAttribute("name2", "value1");
this.simpAttributes.setAttribute("name3", "value1");
assertThat(this.simpAttributes.getAttributeNames(), arrayContainingInAnyOrder("name1", "name2", "name3"));
assertThat(this.simpAttributes.getAttributeNames())
.containsExactlyInAnyOrder("name1", "name2", "name3");
}
@Test
@@ -76,7 +73,7 @@ public class SimpAttributesTests {
this.simpAttributes.registerDestructionCallback("name1", callback);
assertThat(this.simpAttributes.getAttribute(
SimpAttributes.DESTRUCTION_CALLBACK_NAME_PREFIX + "name1"), sameInstance(callback));
SimpAttributes.DESTRUCTION_CALLBACK_NAME_PREFIX + "name1")).isSameAs(callback);
}
@Test
@@ -94,12 +91,12 @@ public class SimpAttributesTests {
this.simpAttributes.registerDestructionCallback("name1", callback1);
this.simpAttributes.registerDestructionCallback("name2", callback2);
assertThat(this.simpAttributes.getAttributeNames().length, is(2));
assertThat(this.simpAttributes.getAttributeNames().length).isEqualTo(2);
}
@Test
public void getSessionMutex() {
assertThat(this.simpAttributes.getSessionMutex(), sameInstance(this.map));
assertThat(this.simpAttributes.getSessionMutex()).isSameAs(this.map);
}
@Test
@@ -107,7 +104,7 @@ public class SimpAttributesTests {
Object mutex = new Object();
this.simpAttributes.setAttribute(SimpAttributes.SESSION_MUTEX_NAME, mutex);
assertThat(this.simpAttributes.getSessionMutex(), sameInstance(mutex));
assertThat(this.simpAttributes.getSessionMutex()).isSameAs(mutex);
}
@Test

View File

@@ -25,9 +25,7 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.ObjectFactory;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -66,7 +64,7 @@ public class SimpSessionScopeTests {
this.simpAttributes.setAttribute("name", "value");
Object actual = this.scope.get("name", this.objectFactory);
assertThat(actual, is("value"));
assertThat(actual).isEqualTo("value");
}
@Test
@@ -74,8 +72,8 @@ public class SimpSessionScopeTests {
given(this.objectFactory.getObject()).willReturn("value");
Object actual = this.scope.get("name", this.objectFactory);
assertThat(actual, is("value"));
assertThat(this.simpAttributes.getAttribute("name"), is("value"));
assertThat(actual).isEqualTo("value");
assertThat(this.simpAttributes.getAttribute("name")).isEqualTo("value");
}
@Test
@@ -83,11 +81,11 @@ public class SimpSessionScopeTests {
this.simpAttributes.setAttribute("name", "value");
Object removed = this.scope.remove("name");
assertThat(removed, is("value"));
assertThat(this.simpAttributes.getAttribute("name"), nullValue());
assertThat(removed).isEqualTo("value");
assertThat(this.simpAttributes.getAttribute("name")).isNull();
removed = this.scope.remove("name");
assertThat(removed, nullValue());
assertThat(removed).isNull();
}
@Test
@@ -101,7 +99,7 @@ public class SimpSessionScopeTests {
@Test
public void getSessionId() {
assertThat(this.scope.getConversationId(), is("session1"));
assertThat(this.scope.getConversationId()).isEqualTo("session1");
}

View File

@@ -67,8 +67,7 @@ import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -539,7 +538,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
@MessageMapping("/scope")
public void scope() {
SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes();
assertThat(simpAttributes.getAttribute("name"), is("value"));
assertThat(simpAttributes.getAttribute("name")).isEqualTo("value");
this.method = "scope";
}

View File

@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
@@ -77,7 +76,7 @@ import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
@@ -288,10 +287,10 @@ public class MessageBrokerConfigurationTests {
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
List<MessageConverter> converters = compositeConverter.getConverters();
assertThat(converters.size(), Matchers.is(3));
assertThat(converters.get(0), Matchers.instanceOf(StringMessageConverter.class));
assertThat(converters.get(1), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(converters.get(2), Matchers.instanceOf(MappingJackson2MessageConverter.class));
assertThat(converters).hasSize(3);
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
@@ -328,9 +327,9 @@ public class MessageBrokerConfigurationTests {
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters().size(), Matchers.is(1));
assertThat(compositeConverter.getConverters()).hasSize(1);
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next(), Matchers.is(testConverter));
assertThat(iterator.next()).isEqualTo(testConverter);
}
@Test
@@ -346,12 +345,12 @@ public class MessageBrokerConfigurationTests {
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
assertThat(compositeConverter.getConverters()).hasSize(4);
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next(), Matchers.is(testConverter));
assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
assertThat(iterator.next()).isEqualTo(testConverter);
assertThat(iterator.next()).isInstanceOf(StringMessageConverter.class);
assertThat(iterator.next()).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(iterator.next()).isInstanceOf(MappingJackson2MessageConverter.class);
}
@Test
@@ -375,8 +374,8 @@ public class MessageBrokerConfigurationTests {
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {};
config.setApplicationContext(new StaticApplicationContext());
assertThat(config.simpValidator(), Matchers.notNullValue());
assertThat(config.simpValidator(), Matchers.instanceOf(OptionalValidatorFactoryBean.class));
assertThat(config.simpValidator()).isNotNull();
assertThat(config.simpValidator()).isInstanceOf(OptionalValidatorFactoryBean.class);
}
@Test
@@ -399,8 +398,8 @@ public class MessageBrokerConfigurationTests {
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {};
config.setApplicationContext(appCxt);
assertThat(config.simpValidator(), Matchers.notNullValue());
assertThat(config.simpValidator(), Matchers.instanceOf(TestValidator.class));
assertThat(config.simpValidator()).isNotNull();
assertThat(config.simpValidator()).isInstanceOf(TestValidator.class);
}
@Test
@@ -410,7 +409,7 @@ public class MessageBrokerConfigurationTests {
SimpAnnotationMethodMessageHandler messageHandler =
context.getBean(SimpAnnotationMethodMessageHandler.class);
assertThat(messageHandler.getValidator(), Matchers.notNullValue(Validator.class));
assertThat(messageHandler.getValidator()).isNotNull();
}
@Test

View File

@@ -43,9 +43,8 @@ import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.concurrent.SettableListenableFuture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -111,7 +110,7 @@ public class DefaultStompSessionTests {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
assertEquals(StompCommand.CONNECT, accessor.getCommand());
assertEquals("my-host", accessor.getHost());
assertThat(accessor.getAcceptVersion(), containsInAnyOrder("1.1", "1.2"));
assertThat(accessor.getAcceptVersion()).containsExactly("1.1", "1.2");
assertArrayEquals(new long[] {11, 12}, accessor.getHeartbeat());
}
@@ -125,7 +124,7 @@ public class DefaultStompSessionTests {
Message<byte[]> message = this.messageCaptor.getValue();
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
assertEquals(StompCommand.CONNECT, accessor.getCommand());
assertThat(accessor.getAcceptVersion(), containsInAnyOrder("1.1"));
assertThat(accessor.getAcceptVersion()).containsExactly("1.1");
}
@Test

View File

@@ -40,8 +40,7 @@ import org.springframework.util.Assert;
import org.springframework.util.SocketUtils;
import org.springframework.util.concurrent.ListenableFuture;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -120,10 +119,10 @@ public class ReactorNettyTcpStompClientTests {
ListenableFuture<StompSession> producerFuture = this.client.connect(producingHandler);
assertTrue(consumingHandler1.awaitForMessageCount(2, 5000));
assertThat(consumingHandler1.getReceived(), containsInAnyOrder("foo1", "foo2"));
assertThat(consumingHandler1.getReceived()).containsExactly("foo1", "foo2");
assertTrue(consumingHandler2.awaitForMessageCount(2, 5000));
assertThat(consumingHandler2.getReceived(), containsInAnyOrder("foo1", "foo2"));
assertThat(consumingHandler2.getReceived()).containsExactly("foo1", "foo2");
consumerFuture1.get().disconnect();
consumerFuture2.get().disconnect();

View File

@@ -21,7 +21,6 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.springframework.messaging.Message;
@@ -37,7 +36,7 @@ import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.MultiValueMap;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -113,7 +112,7 @@ public class StompHeaderAccessorTests {
assertNotNull(headerAccessor.getHeader("stompCredentials"));
assertEquals("joe", headerAccessor.getLogin());
assertEquals("joe123", headerAccessor.getPasscode());
assertThat(headerAccessor.toString(), CoreMatchers.containsString("passcode=[PROTECTED]"));
assertThat(headerAccessor.toString()).contains("passcode=[PROTECTED]");
Map<String, List<String>> output = headerAccessor.toNativeHeaderMap();
assertEquals("joe", output.get(StompHeaderAccessor.STOMP_LOGIN_HEADER).get(0));

View File

@@ -30,8 +30,7 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.converter.MessageConverter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
@@ -162,13 +161,13 @@ public class MultiServerUserRegistryTests {
SimpUser user = this.registry.getUsers().iterator().next();
assertTrue(user.hasSessions());
assertEquals(2, user.getSessions().size());
assertThat(user.getSessions(), containsInAnyOrder(localSession, remoteSession));
assertThat(user.getSessions()).containsExactlyInAnyOrder(localSession, remoteSession);
assertSame(localSession, user.getSession("sess123"));
assertEquals(remoteSession, user.getSession("sess456"));
user = this.registry.getUser("joe");
assertEquals(2, user.getSessions().size());
assertThat(user.getSessions(), containsInAnyOrder(localSession, remoteSession));
assertThat(user.getSessions()).containsExactlyInAnyOrder(localSession, remoteSession);
assertSame(localSession, user.getSession("sess123"));
assertEquals(remoteSession, user.getSession("sess456"));
}

View File

@@ -18,9 +18,8 @@ package org.springframework.messaging.support;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Gary Russell
@@ -32,12 +31,12 @@ public class ErrorMessageTests {
public void testToString() {
ErrorMessage em = new ErrorMessage(new RuntimeException("foo"));
String emString = em.toString();
assertThat(emString, not(containsString("original")));
assertThat(emString).doesNotContain("original");
em = new ErrorMessage(new RuntimeException("foo"), new GenericMessage<>("bar"));
emString = em.toString();
assertThat(emString, containsString("original"));
assertThat(emString, containsString(em.getOriginalMessage().toString()));
assertThat(emString).contains("original");
assertThat(emString).contains(em.getOriginalMessage().toString());
}
}

View File

@@ -31,9 +31,8 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
@@ -108,8 +107,8 @@ public class ExecutorSubscribableChannelTests {
@Test
public void subscribeTwice() {
assertThat(this.channel.subscribe(this.handler), equalTo(true));
assertThat(this.channel.subscribe(this.handler), equalTo(false));
assertThat(this.channel.subscribe(this.handler)).isEqualTo(true);
assertThat(this.channel.subscribe(this.handler)).isEqualTo(false);
this.channel.send(this.message);
verify(this.handler, times(1)).handleMessage(this.message);
}
@@ -117,8 +116,8 @@ public class ExecutorSubscribableChannelTests {
@Test
public void unsubscribeTwice() {
this.channel.subscribe(this.handler);
assertThat(this.channel.unsubscribe(this.handler), equalTo(true));
assertThat(this.channel.unsubscribe(this.handler), equalTo(false));
assertThat(this.channel.unsubscribe(this.handler)).isEqualTo(true);
assertThat(this.channel.unsubscribe(this.handler)).isEqualTo(false);
this.channel.send(this.message);
verify(this.handler, never()).handleMessage(this.message);
}
@@ -134,7 +133,7 @@ public class ExecutorSubscribableChannelTests {
this.channel.send(message);
}
catch (MessageDeliveryException actualException) {
assertThat(actualException.getCause(), equalTo(ex));
assertThat(actualException.getCause()).isEqualTo(ex);
}
verifyZeroInteractions(secondHandler);
}

View File

@@ -29,9 +29,8 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.SerializationTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -344,7 +343,7 @@ public class MessageHeaderAccessorTests {
return payload;
}
});
assertThat(actual, startsWith("headers={contentType=text/plain} payload=" + getClass().getName() + "$"));
assertThat(actual).startsWith("headers={contentType=text/plain} payload=" + getClass().getName() + "$");
}
@Test