Refactor AssertJ assertions into more idiomatic ones
This commit refactors some AssertJ assertions into more idiomatic and readable ones. Using the dedicated assertion instead of a generic one will produce more meaningful error messages. For instance, consider collection size: ``` // expected: 5 but was: 2 assertThat(collection.size()).equals(5); // Expected size: 5 but was: 2 in: [1, 2] assertThat(collection).hasSize(5); ``` Closes gh-30104
This commit is contained in:
@@ -128,8 +128,9 @@ abstract class AbstractJmsAnnotationDrivenTests {
|
||||
|
||||
JmsListenerEndpointRegistry customRegistry =
|
||||
context.getBean("customRegistry", JmsListenerEndpointRegistry.class);
|
||||
assertThat(customRegistry.getListenerContainerIds().size()).as("Wrong number of containers in the registry").isEqualTo(2);
|
||||
assertThat(customRegistry.getListenerContainers().size()).as("Wrong number of containers in the registry").isEqualTo(2);
|
||||
assertThat(customRegistry.getListenerContainerIds()).as("Wrong number of containers in the registry")
|
||||
.hasSize(2);
|
||||
assertThat(customRegistry.getListenerContainers()).as("Wrong number of containers in the registry").hasSize(2);
|
||||
assertThat(customRegistry.getListenerContainer("listenerId")).as("Container with custom id on the annotation should be found").isNotNull();
|
||||
assertThat(customRegistry.getListenerContainer("myCustomEndpointId")).as("Container created with custom id should be found").isNotNull();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
Config.class, SimpleMessageListenerTestBean.class);
|
||||
|
||||
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
|
||||
assertThat(factory.getListenerContainers().size()).as("One container should have been registered").isEqualTo(1);
|
||||
assertThat(factory.getListenerContainers()).as("One container should have been registered").hasSize(1);
|
||||
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
|
||||
|
||||
JmsListenerEndpoint endpoint = container.getEndpoint();
|
||||
@@ -84,7 +84,7 @@ class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
void metaAnnotationIsDiscovered() throws Exception {
|
||||
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetaAnnotationTestBean.class)) {
|
||||
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
|
||||
assertThat(factory.getListenerContainers().size()).as("one container should have been registered").isEqualTo(1);
|
||||
assertThat(factory.getListenerContainers()).as("one container should have been registered").hasSize(1);
|
||||
|
||||
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
|
||||
assertThat(endpoint.getClass()).as("Wrong endpoint type").isEqualTo(MethodJmsListenerEndpoint.class);
|
||||
@@ -100,7 +100,7 @@ class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
void sendToAnnotationFoundOnInterfaceProxy() throws Exception {
|
||||
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, ProxyConfig.class, InterfaceProxyTestBean.class)) {
|
||||
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
|
||||
assertThat(factory.getListenerContainers().size()).as("one container should have been registered").isEqualTo(1);
|
||||
assertThat(factory.getListenerContainers()).as("one container should have been registered").hasSize(1);
|
||||
|
||||
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
|
||||
assertThat(endpoint.getClass()).as("Wrong endpoint type").isEqualTo(MethodJmsListenerEndpoint.class);
|
||||
@@ -122,7 +122,7 @@ class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
void sendToAnnotationFoundOnCglibProxy() throws Exception {
|
||||
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, ProxyConfig.class, ClassProxyTestBean.class)) {
|
||||
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
|
||||
assertThat(factory.getListenerContainers().size()).as("one container should have been registered").isEqualTo(1);
|
||||
assertThat(factory.getListenerContainers()).as("one container should have been registered").hasSize(1);
|
||||
|
||||
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
|
||||
assertThat(endpoint.getClass()).as("Wrong endpoint type").isEqualTo(MethodJmsListenerEndpoint.class);
|
||||
|
||||
@@ -81,10 +81,10 @@ public class JmsNamespaceHandlerTests {
|
||||
@Test
|
||||
public void testBeansCreated() {
|
||||
Map<String, ?> containers = context.getBeansOfType(DefaultMessageListenerContainer.class);
|
||||
assertThat(containers.size()).as("Context should contain 3 JMS listener containers").isEqualTo(3);
|
||||
assertThat(containers).as("Context should contain 3 JMS listener containers").hasSize(3);
|
||||
|
||||
containers = context.getBeansOfType(GenericMessageEndpointManager.class);
|
||||
assertThat(containers.size()).as("Context should contain 3 JCA endpoint containers").isEqualTo(3);
|
||||
assertThat(containers).as("Context should contain 3 JCA endpoint containers").hasSize(3);
|
||||
|
||||
assertThat(context.getBeansOfType(JmsListenerContainerFactory.class))
|
||||
.as("Context should contain 3 JmsListenerContainerFactory instances").hasSize(3);
|
||||
|
||||
@@ -138,7 +138,7 @@ class JmsTemplateTests {
|
||||
PrintWriter out = new PrintWriter(sw);
|
||||
springJmsEx.printStackTrace(out);
|
||||
String trace = sw.toString();
|
||||
assertThat(trace.indexOf("host not found") > 0).as("inner jms exception not found").isTrue();
|
||||
assertThat(trace.indexOf("host not found")).as("inner jms exception not found").isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -47,7 +47,7 @@ class JmsGatewaySupportTests {
|
||||
gateway.afterPropertiesSet();
|
||||
assertThat(gateway.getConnectionFactory()).as("Correct ConnectionFactory").isEqualTo(mockConnectionFactory);
|
||||
assertThat(gateway.getJmsTemplate().getConnectionFactory()).as("Correct JmsTemplate").isEqualTo(mockConnectionFactory);
|
||||
assertThat(test.size()).as("initGateway called").isEqualTo(1);
|
||||
assertThat(test).as("initGateway called").hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,7 +63,7 @@ class JmsGatewaySupportTests {
|
||||
gateway.setJmsTemplate(template);
|
||||
gateway.afterPropertiesSet();
|
||||
assertThat(gateway.getJmsTemplate()).as("Correct JmsTemplate").isEqualTo(template);
|
||||
assertThat(test.size()).as("initGateway called").isEqualTo(1);
|
||||
assertThat(test).as("initGateway called").hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user