From bbd87c3eced3f049897136c99e63bdccfa7f4c8f Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sun, 3 Feb 2019 18:52:46 +0100 Subject: [PATCH] Added checkstyle for tests --- pom.xml | 2 + .../cloud/bus/BusJmxEndpointTests.java | 16 +++++ .../jackson/BusJacksonIntegrationTests.java | 16 +++++ .../BusAutoConfigurationClassPathTests.java | 16 +++++ .../cloud/bus/BusAutoConfigurationTests.java | 58 +++++++++---------- .../bus/ConditionalOnBusEnabledTests.java | 16 ++--- .../cloud/bus/ServiceMatcherTests.java | 39 ++++++------- .../ServiceMatcherWithConfigNamesTests.java | 38 ++++++------ .../bus/endpoint/RefreshBusEndpointTests.java | 4 +- .../RemoteApplicationEventScanTests.java | 19 +++--- .../cloud/bus/jackson/SerializationTests.java | 16 +++-- .../cloud/bus/jackson/SubtypeModuleTests.java | 54 +++++++++-------- 12 files changed, 170 insertions(+), 124 deletions(-) diff --git a/pom.xml b/pom.xml index 30e8fd0..ab60549 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,8 @@ true true + true + diff --git a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java index 00ddcd3..3ca9f1c 100644 --- a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java +++ b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cloud.bus; import org.junit.Test; diff --git a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java index 05da2e9..cbec5b7 100644 --- a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java +++ b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cloud.bus.jackson; import java.util.Collection; diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java index d40efbb..28fa37c 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cloud.bus; import org.junit.Test; diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java index 8a4c6be..26ecef1 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java @@ -53,10 +53,6 @@ import org.springframework.messaging.support.ChannelInterceptorAdapter; import org.springframework.messaging.support.GenericMessage; 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; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -75,9 +71,10 @@ public class BusAutoConfigurationTests { public void defaultId() { this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--server.port=0"); - assertTrue("Wrong ID: " + this.context.getBean(BusProperties.class).getId(), - this.context.getBean(BusProperties.class).getId() - .startsWith("application:0:")); + assertThat(this.context.getBean(BusProperties.class).getId() + .startsWith("application:0:")).as( + "Wrong ID: " + this.context.getBean(BusProperties.class).getId()) + .isTrue(); } @Test @@ -87,8 +84,8 @@ public class BusAutoConfigurationTests { this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class) .send(new GenericMessage<>( new RefreshRemoteApplicationEvent(this, "bar", "bar"))); - assertNull( - this.context.getBean(InboundMessageHandlerConfiguration.class).refresh); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh) + .isNull(); } @Test @@ -98,8 +95,8 @@ public class BusAutoConfigurationTests { this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class) .send(new GenericMessage<>( new RefreshRemoteApplicationEvent(this, "foo", null))); - assertNull( - this.context.getBean(InboundMessageHandlerConfiguration.class).refresh); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh) + .isNull(); } @Test @@ -109,8 +106,8 @@ public class BusAutoConfigurationTests { this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class) .send(new GenericMessage<>( new RefreshRemoteApplicationEvent(this, "foo", null))); - assertNotNull( - this.context.getBean(InboundMessageHandlerConfiguration.class).refresh); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh) + .isNotNull(); } @Test @@ -125,13 +122,13 @@ public class BusAutoConfigurationTests { new RefreshRemoteApplicationEvent(this, "foo", null))); RefreshRemoteApplicationEvent refresh = this.context .getBean(InboundMessageHandlerConfiguration.class).refresh; - assertNotNull(refresh); + assertThat(refresh).isNotNull(); OutboundMessageHandlerConfiguration outbound = this.context .getBean(OutboundMessageHandlerConfiguration.class); outbound.latch.await(2000L, TimeUnit.MILLISECONDS); String message = (String) outbound.message.getPayload(); - assertTrue("Wrong ackId: " + message, - message.contains("\"ackId\":\"" + refresh.getId())); + assertThat(message.contains("\"ackId\":\"" + refresh.getId())) + .as("Wrong ackId: " + message).isTrue(); } @Test @@ -147,11 +144,11 @@ public class BusAutoConfigurationTests { new RefreshRemoteApplicationEvent(this, "foo", null))); RefreshRemoteApplicationEvent refresh = this.context .getBean(InboundMessageHandlerConfiguration.class).refresh; - assertNotNull(refresh); + assertThat(refresh).isNotNull(); SentMessageConfiguration sent = this.context .getBean(SentMessageConfiguration.class); - assertNotNull(sent.event); - assertEquals(1, sent.count); + assertThat(sent.event).isNotNull(); + assertThat(sent.count).isEqualTo(1); } @Test @@ -168,8 +165,8 @@ public class BusAutoConfigurationTests { null, "ID", "bar", RefreshRemoteApplicationEvent.class))); AckMessageConfiguration sent = this.context .getBean(AckMessageConfiguration.class); - assertNotNull(sent.event); - assertEquals(1, sent.count); + assertThat(sent.event).isNotNull(); + assertThat(sent.count).isEqualTo(1); } @Test @@ -180,7 +177,7 @@ public class BusAutoConfigurationTests { OutboundMessageHandlerConfiguration outbound = this.context .getBean(OutboundMessageHandlerConfiguration.class); outbound.latch.await(2000L, TimeUnit.MILLISECONDS); - assertNotNull("message was null", outbound.message); + assertThat(outbound.message).as("message was null").isNotNull(); } @Test @@ -188,8 +185,9 @@ public class BusAutoConfigurationTests { this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar", "--server.port=0"); this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", null)); - assertNull( - this.context.getBean(OutboundMessageHandlerConfiguration.class).message); + assertThat( + this.context.getBean(OutboundMessageHandlerConfiguration.class).message) + .isNull(); } @Test @@ -199,8 +197,8 @@ public class BusAutoConfigurationTests { this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class) .send(new GenericMessage<>( new RefreshRemoteApplicationEvent(this, "foo", "bar:*"))); - assertNotNull( - this.context.getBean(InboundMessageHandlerConfiguration.class).refresh); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh) + .isNotNull(); } @Test @@ -210,8 +208,8 @@ public class BusAutoConfigurationTests { this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class) .send(new GenericMessage<>( new RefreshRemoteApplicationEvent(this, "foo", "bar:**"))); - assertNotNull( - this.context.getBean(InboundMessageHandlerConfiguration.class).refresh); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh) + .isNotNull(); } @Test @@ -221,8 +219,8 @@ public class BusAutoConfigurationTests { this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class) .send(new GenericMessage<>( new RefreshRemoteApplicationEvent(this, "foo", "bar*"))); - assertNotNull( - this.context.getBean(InboundMessageHandlerConfiguration.class).refresh); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh) + .isNotNull(); } // see https://github.com/spring-cloud/spring-cloud-bus/issues/74 diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java index 8686fae..a8ff640 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java @@ -26,8 +26,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Spencer Gibb @@ -50,23 +49,24 @@ public class ConditionalOnBusEnabledTests { public void busEnabledTrue() { load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":true"); - assertTrue("missing bean from @ConditionalOnBusEnabled config", - this.context.containsBean("foo")); + assertThat(this.context.containsBean("foo")) + .as("missing bean from @ConditionalOnBusEnabled config").isTrue(); } @Test public void busEnabledMissing() { load(MyBusEnabledConfig.class); - assertTrue("missing bean from @ConditionalOnBusEnabled config", - this.context.containsBean("foo")); + assertThat(this.context.containsBean("foo")) + .as("missing bean from @ConditionalOnBusEnabled config").isTrue(); } @Test public void busDisabled() { load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":false"); - assertFalse("bean exists from disabled @ConditionalOnBusEnabled config", - this.context.containsBean("foo")); + assertThat(this.context.containsBean("foo")) + .as("bean exists from disabled @ConditionalOnBusEnabled config") + .isFalse(); } private void load(Class config, String... environment) { diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java index 654d1b3..8da68d6 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java @@ -25,8 +25,7 @@ import org.junit.Test; import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; import org.springframework.util.AntPathMatcher; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Dave Syer @@ -54,79 +53,79 @@ public class ServiceMatcherTests { @Test public void fromSelf() { assertThat(this.matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "one:two:8888", "foo:bar:spam", EMPTY_MAP)), is(true)); + this, "one:two:8888", "foo:bar:spam", EMPTY_MAP))).isTrue(); } @Test public void forSelf() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:two:8888", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:two:8888", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:two:*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:two:*", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithGlobalWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "**", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "**", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcardName() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcardNameAndProfile() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*:t*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "o*:t*", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcardString() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue(); } @Test public void notForSelfWithWildCardNameAndMismatchingProfile() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*:f*", EMPTY_MAP)), is(false)); + this, "foo:bar:spam", "o*:f*", EMPTY_MAP))).isFalse(); } @Test public void forSelfWithDoubleWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:**", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:**", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithNoWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithProfileNoWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:two", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:two", EMPTY_MAP))).isTrue(); } @Test public void notForSelf() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)), is(false)); + this, "foo:bar:spam", "one:two:9999", EMPTY_MAP))).isFalse(); } @Test public void notFromSelf() { assertThat(this.matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "one:two:9999", "foo:bar:spam", EMPTY_MAP)), is(false)); + this, "one:two:9999", "foo:bar:spam", EMPTY_MAP))).isFalse(); } /** @@ -136,7 +135,7 @@ public class ServiceMatcherTests { public void forSelfWithMultipleProfiles() { initMatcher("customerportal:dev,cloud:80"); assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP))).isTrue(); } /** @@ -146,7 +145,7 @@ public class ServiceMatcherTests { public void notForSelfWithMultipleProfiles() { initMatcher("customerportal:dev,cloud:80"); assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)), is(false)); + this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP))).isFalse(); } /** @@ -155,10 +154,8 @@ public class ServiceMatcherTests { @Test public void notForSelfWithMultipleProfilesDifferentPort() { initMatcher("customerportal:dev,cloud:80"); - assertThat( - this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP)), - is(false)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP))).isFalse(); } } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java index 23fdfd8..f2fb1cb 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -26,8 +25,7 @@ import org.junit.Test; import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; import org.springframework.util.AntPathMatcher; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Stefan Pfeiffer @@ -55,90 +53,88 @@ public class ServiceMatcherWithConfigNamesTests { @Test public void forSelfWithWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:two:*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:two:*", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcardAndOtherConfigName() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "three:two:*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "three:two:*", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithGlobalWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "**", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "**", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcardName() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcardNameAndProfile() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*:t*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "o*:t*", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithWildcardString() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue(); } @Test public void notForSelfWithWildCardNameAndMismatchingProfile() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "o*:f*", EMPTY_MAP)), is(false)); + this, "foo:bar:spam", "o*:f*", EMPTY_MAP))).isFalse(); } @Test public void forSelfWithDoubleWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:**", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:**", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithNoWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one", EMPTY_MAP))).isTrue(); } @Test public void forSelfWithProfileNoWildcard() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:two", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:two", EMPTY_MAP))).isTrue(); } @Test public void notForSelf() { assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)), is(false)); + this, "foo:bar:spam", "one:two:9999", EMPTY_MAP))).isFalse(); } @Test public void forSelfWithMultipleProfiles() { initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP)), is(true)); + this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP))).isTrue(); } @Test public void notForSelfWithMultipleProfiles() { initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( - this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)), is(false)); + this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP))).isFalse(); } @Test public void notForSelfWithMultipleProfilesDifferentPort() { initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); - assertThat( - this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP)), - is(false)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP))).isFalse(); } } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java index 976dd6f..a5463a9 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java @@ -18,7 +18,7 @@ package org.springframework.cloud.bus.endpoint; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Dave Syer @@ -28,7 +28,7 @@ public class RefreshBusEndpointTests { @Test public void instanceId() throws Exception { RefreshBusEndpoint endpoint = new RefreshBusEndpoint(null, "foo"); - assertEquals("foo", endpoint.getInstanceId()); + assertThat(endpoint.getInstanceId()).isEqualTo("foo"); } } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java index 686c2ce..17ed4f4 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java @@ -41,9 +41,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.test.util.ReflectionTestUtils; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class RemoteApplicationEventScanTests { @@ -115,17 +113,18 @@ public class RemoteApplicationEventScanTests { Arrays.asList(expectedRegisterdClasses)); addStandardSpringCloudEventBusEvents(expectedRegisterdClassesAsList); - assertTrue("Wrong RemoteApplicationEvent classes are registerd in object mapper", - expectedRegisterdClassesAsList.size() == registeredSubtypes.size()); + assertThat(expectedRegisterdClassesAsList.size() == registeredSubtypes.size()) + .as("Wrong RemoteApplicationEvent classes are registerd in object mapper") + .isTrue(); for (final NamedType namedType : registeredSubtypes) { - assertTrue(expectedRegisterdClassesAsList.contains(namedType.getType())); + assertThat(expectedRegisterdClassesAsList.contains(namedType.getType())) + .isTrue(); } - assertThat("RemoteApplicationEvent packages not registered", - Arrays.asList((String[]) ReflectionTestUtils.getField(this.converter, - "packagesToScan")), - containsInAnyOrder(expectedPackageToScan)); + assertThat(Arrays.asList((String[]) ReflectionTestUtils.getField(this.converter, + "packagesToScan"))).as("RemoteApplicationEvent packages not registered") + .contains(expectedPackageToScan); } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java index 8a4f807..54d5dc1 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java @@ -25,9 +25,7 @@ import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEve import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent; import org.springframework.cloud.bus.event.RemoteApplicationEvent; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Dave Syer @@ -46,9 +44,9 @@ public class SerializationTests { String value = this.mapper.writeValueAsString(source); RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class); - assertTrue(event instanceof EnvironmentChangeRemoteApplicationEvent); - assertNotNull(event.getId()); - assertTrue(event.getId().equals(source.getId())); + assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue(); + assertThat(event.getId()).isNotNull(); + assertThat(event.getId().equals(source.getId())).isTrue(); } @Test @@ -61,9 +59,9 @@ public class SerializationTests { value = value.replaceAll(",\"id\":\"[a-f0-9-]*\"", ""); RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class); - assertTrue(event instanceof EnvironmentChangeRemoteApplicationEvent); - assertNotNull(event.getId()); - assertFalse(event.getId().equals(source.getId())); + assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue(); + assertThat(event.getId()).isNotNull(); + assertThat(event.getId().equals(source.getId())).isFalse(); } } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java index 377310f..e758c5c 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java @@ -29,8 +29,6 @@ import org.springframework.cloud.bus.event.test.TypedRemoteApplicationEvent; import org.springframework.messaging.support.MessageBuilder; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; /** * @author Spencer Gibb @@ -46,11 +44,13 @@ public class SubtypeModuleTests { RemoteApplicationEvent event = mapper.readValue( "{\"type\":\"my\", \"destinationService\":\"myservice\", \"originService\":\"myorigin\"}", RemoteApplicationEvent.class); - assertTrue("event is wrong type", event instanceof MyRemoteApplicationEvent); + assertThat(event instanceof MyRemoteApplicationEvent).as("event is wrong type") + .isTrue(); MyRemoteApplicationEvent myEvent = MyRemoteApplicationEvent.class.cast(event); - assertEquals("originService was wrong", "myorigin", myEvent.getOriginService()); - assertEquals("destinationService was wrong", "myservice", - myEvent.getDestinationService()); + assertThat(myEvent.getOriginService()).as("originService was wrong") + .isEqualTo("myorigin"); + assertThat(myEvent.getDestinationService()).as("destinationService was wrong") + .isEqualTo("myservice"); } @Test @@ -59,7 +59,8 @@ public class SubtypeModuleTests { RemoteApplicationEvent event = mapper.readValue("{\"type\":\"another\"}", AnotherRemoteApplicationEvent.class); - assertTrue("event is wrong type", event instanceof AnotherRemoteApplicationEvent); + assertThat(event instanceof AnotherRemoteApplicationEvent) + .as("event is wrong type").isTrue(); } @Test @@ -84,7 +85,8 @@ public class SubtypeModuleTests { Object event = converter.fromMessage(MessageBuilder .withPayload("{\"type\":\"TestRemoteApplicationEvent\"}").build(), RemoteApplicationEvent.class); - assertTrue("event is wrong type", event instanceof TestRemoteApplicationEvent); + assertThat(event instanceof TestRemoteApplicationEvent).as("event is wrong type") + .isTrue(); } @Test @@ -94,12 +96,14 @@ public class SubtypeModuleTests { Object event = converter.fromMessage(MessageBuilder .withPayload("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}") .build(), RemoteApplicationEvent.class); - assertTrue("event is wrong type", event instanceof UnknownRemoteApplicationEvent); - assertEquals("type information is wrong", "NotDefinedTestRemoteApplicationEvent", - ((UnknownRemoteApplicationEvent) event).getTypeInfo()); - assertEquals("payload is wrong", - "{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}", - ((UnknownRemoteApplicationEvent) event).getPayloadAsString()); + assertThat(event instanceof UnknownRemoteApplicationEvent) + .as("event is wrong type").isTrue(); + assertThat(((UnknownRemoteApplicationEvent) event).getTypeInfo()) + .as("type information is wrong") + .isEqualTo("NotDefinedTestRemoteApplicationEvent"); + assertThat(((UnknownRemoteApplicationEvent) event).getPayloadAsString()) + .as("payload is wrong") + .isEqualTo("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}"); } @Test @@ -109,7 +113,8 @@ public class SubtypeModuleTests { Object event = converter.fromMessage( MessageBuilder.withPayload("{\"type\":\"typed\"}").build(), RemoteApplicationEvent.class); - assertTrue("event is wrong type", event instanceof TypedRemoteApplicationEvent); + assertThat(event instanceof TypedRemoteApplicationEvent).as("event is wrong type") + .isTrue(); } /** @@ -119,13 +124,15 @@ public class SubtypeModuleTests { public void testDeserializeAckRemoteApplicationEventWithKnownType() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(); converter.afterPropertiesSet(); - Object event = converter.fromMessage(MessageBuilder.withPayload( - "{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}") + Object event = converter.fromMessage(MessageBuilder + .withPayload("{\"type\":\"AckRemoteApplicationEvent\", " + + "\"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}") .build(), RemoteApplicationEvent.class); - assertTrue("event is no ack", event instanceof AckRemoteApplicationEvent); + assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack") + .isTrue(); AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); - assertEquals("inner ack event has wrong type", TestRemoteApplicationEvent.class, - ackEvent.getEvent()); + assertThat(ackEvent.getEvent()).as("inner ack event has wrong type") + .isEqualTo(TestRemoteApplicationEvent.class); } /** @@ -139,10 +146,11 @@ public class SubtypeModuleTests { Object event = converter.fromMessage(MessageBuilder.withPayload( "{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}") .build(), RemoteApplicationEvent.class); - assertTrue("event is no ack", event instanceof AckRemoteApplicationEvent); + assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack") + .isTrue(); AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); - assertEquals("inner ack event has wrong type", - UnknownRemoteApplicationEvent.class, ackEvent.getEvent()); + assertThat(ackEvent.getEvent()).as("inner ack event has wrong type") + .isEqualTo(UnknownRemoteApplicationEvent.class); } @SuppressWarnings("serial")