Added checkstyle for tests

This commit is contained in:
Marcin Grzejszczak
2019-02-03 18:52:46 +01:00
parent b10aaa7d2d
commit bbd87c3ece
12 changed files with 170 additions and 124 deletions

View File

@@ -34,6 +34,8 @@
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
</maven-checkstyle-plugin.failsOnViolation>
<maven-checkstyle-plugin.includeTestSourceDirectory>true
</maven-checkstyle-plugin.includeTestSourceDirectory>
</properties>
<build>

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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) {

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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");
}
}

View File

@@ -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);
}

View File

@@ -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();
}
}

View File

@@ -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")