Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply AssertJ and JUnit 5 best practices #251

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
*/
@SpringJUnitConfig
@DirtiesContext
public class KinesisMessageDrivenChannelAdapterTests {
class KinesisMessageDrivenChannelAdapterTests {
artembilan marked this conversation as resolved.
Show resolved Hide resolved

private static final String STREAM1 = "stream1";

Expand Down Expand Up @@ -118,7 +118,7 @@ void setup() {

@Test
@SuppressWarnings({"unchecked", "rawtypes"})
void testKinesisMessageDrivenChannelAdapter() {
void kinesisMessageDrivenChannelAdapter() {
artembilan marked this conversation as resolved.
Show resolved Hide resolved
this.kinesisMessageDrivenChannelAdapter.start();
final Set<KinesisShardOffset> shardOffsets = TestUtils.getPropertyValue(this.kinesisMessageDrivenChannelAdapter,
"shardOffsets", Set.class);
Expand Down Expand Up @@ -168,11 +168,11 @@ void testKinesisMessageDrivenChannelAdapter() {
Map<?, ?> forLocking = TestUtils.getPropertyValue(this.kinesisMessageDrivenChannelAdapter,
"shardConsumerManager.locks", Map.class);

await().untilAsserted(() -> assertThat(forLocking).hasSize(0));
await().untilAsserted(() -> assertThat(forLocking).isEmpty());

final List consumerInvokers = TestUtils.getPropertyValue(this.kinesisMessageDrivenChannelAdapter,
"consumerInvokers", List.class);
await().untilAsserted(() -> assertThat(consumerInvokers).hasSize(0));
await().untilAsserted(() -> assertThat(consumerInvokers).isEmpty());

this.kinesisMessageDrivenChannelAdapter.setListenerMode(ListenerMode.batch);
this.kinesisMessageDrivenChannelAdapter.setCheckpointMode(CheckpointMode.record);
Expand All @@ -186,8 +186,8 @@ void testKinesisMessageDrivenChannelAdapter() {
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(List.class);
List<String> payload = (List<String>) message.getPayload();
assertThat(payload).size().isEqualTo(1);
String record = payload.get(0);
assertThat(payload).hasSize(1);
String record = payload.getFirst();
rickie marked this conversation as resolved.
Show resolved Hide resolved
assertThat(record).isEqualTo("bar");

Object partitionKeyHeader = message.getHeaders().get(AwsHeaders.RECEIVED_PARTITION_KEY);
Expand Down Expand Up @@ -219,7 +219,7 @@ void testKinesisMessageDrivenChannelAdapter() {
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(List.class);
List<String> messagePayload = (List<String>) message.getPayload();
assertThat(messagePayload).size().isEqualTo(3);
assertThat(messagePayload).hasSize(3);

Object messageSequenceNumberHeader = message.getHeaders().get(AwsHeaders.RECEIVED_SEQUENCE_NUMBER);
assertThat(messageSequenceNumberHeader).isInstanceOf(List.class);
Expand All @@ -235,17 +235,16 @@ void testKinesisMessageDrivenChannelAdapter() {
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(List.class);
messagePayload = (List<String>) message.getPayload();
assertThat(messagePayload).size().isEqualTo(2);
assertThat(messagePayload).contains("bar");
assertThat(messagePayload).contains("foobar");
assertThat(messagePayload).hasSize(2);
assertThat(messagePayload).contains("bar", "foobar");
artembilan marked this conversation as resolved.
Show resolved Hide resolved

this.kinesisMessageDrivenChannelAdapter.stop();

}

@Test
@SuppressWarnings("rawtypes")
void testResharding() throws InterruptedException {
void resharding() throws InterruptedException {
this.reshardingChannelAdapter.start();

assertThat(this.kinesisChannel.receive(10000)).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*/
@SpringJUnitConfig
@DirtiesContext
public class S3InboundChannelAdapterTests implements LocalstackContainerTest {
class S3InboundChannelAdapterTests implements LocalstackContainerTest {

private static final ExpressionParser PARSER = new SpelExpressionParser();

Expand All @@ -84,12 +84,12 @@ static void setup() {
}

@Test
void testS3InboundChannelAdapter() throws IOException {
void s3InboundChannelAdapter() throws IOException {
Message<?> message = this.s3FilesChannel.receive(10000);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(File.class);
File localFile = (File) message.getPayload();
assertThat(localFile.getName()).isEqualTo("A.TEST.a");
assertThat(localFile).hasName("A.TEST.a");

String content = FileCopyUtils.copyToString(new FileReader(localFile));
assertThat(content).isEqualTo("Hello");
Expand All @@ -98,7 +98,7 @@ void testS3InboundChannelAdapter() throws IOException {
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(File.class);
localFile = (File) message.getPayload();
assertThat(localFile.getName()).isEqualTo("B.TEST.a");
assertThat(localFile).hasName("B.TEST.a");

content = FileCopyUtils.copyToString(new FileReader(localFile));
assertThat(content).isEqualTo("Bye");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*/
@SpringJUnitConfig
@DirtiesContext
public class S3StreamingChannelAdapterTests implements LocalstackContainerTest {
class S3StreamingChannelAdapterTests implements LocalstackContainerTest {

private static final String S3_BUCKET = "s3-bucket";

Expand All @@ -74,7 +74,7 @@ static void setup() {
}

@Test
void testS3InboundStreamingChannelAdapter() throws IOException {
void s3InboundStreamingChannelAdapter() throws IOException {
Message<?> message = this.s3FilesChannel.receive(10000);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(InputStream.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*/
@SpringJUnitWebConfig
@DirtiesContext
public class SnsInboundChannelAdapterTests {
class SnsInboundChannelAdapterTests {

@Autowired
private WebApplicationContext context;
Expand Down Expand Up @@ -83,7 +83,7 @@ void setUp() {
}

@Test
void testSubscriptionConfirmation() throws Exception {
void subscriptionConfirmation() throws Exception {
this.mockMvc
.perform(post("/mySampleTopic").header("x-amz-sns-message-type", "SubscriptionConfirmation")
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -110,7 +110,7 @@ void testSubscriptionConfirmation() throws Exception {

@Test
@SuppressWarnings("unchecked")
void testNotification() throws Exception {
void notification() throws Exception {
this.mockMvc
.perform(post("/mySampleTopic").header("x-amz-sns-message-type", "Notification")
.contentType(MediaType.TEXT_PLAIN)
Expand All @@ -121,12 +121,13 @@ void testNotification() throws Exception {
assertThat(receive).isNotNull();
Map<String, String> payload = (Map<String, String>) receive.getPayload();

assertThat(payload.get("Subject")).isEqualTo("foo");
assertThat(payload.get("Message")).isEqualTo("bar");
assertThat(payload)
.containsEntry("Subject", "foo")
.containsEntry("Message", "bar");
}

@Test
void testUnsubscribe() throws Exception {
void unsubscribe() throws Exception {
this.mockMvc
.perform(post("/mySampleTopic").header("x-amz-sns-message-type", "UnsubscribeConfirmation")
.contentType(MediaType.TEXT_PLAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
@SpringJUnitConfig
@DirtiesContext
public class SqsMessageDrivenChannelAdapterTests implements LocalstackContainerTest {
class SqsMessageDrivenChannelAdapterTests implements LocalstackContainerTest {

private static SqsAsyncClient AMAZON_SQS;

Expand All @@ -59,7 +59,7 @@ static void setup() {
}

@Test
void testSqsMessageDrivenChannelAdapter() {
void sqsMessageDrivenChannelAdapter() {
Map<String, MessageAttributeValue> attributes =
Map.of("someAttribute",
MessageAttributeValue.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
*/
@SpringJUnitConfig
@DirtiesContext

public class KclMessageDrivenChannelAdapterMultiStreamTests implements LocalstackContainerTest {
class KclMessageDrivenChannelAdapterMultiStreamTests implements LocalstackContainerTest {

private static final String TEST_STREAM1 = "MultiStreamKcl1";

Expand Down Expand Up @@ -104,7 +103,7 @@ static void tearDown() {
}

@Test
public void kclChannelAdapterMultiStream() {
void kclChannelAdapterMultiStream() {
String testData = "test data";
AMAZON_KINESIS.putRecord(request -> request
.streamName(TEST_STREAM1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private Message<?> verifyRecordReceived(String testData) {
}

@Test
public void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
MetricsLevel metricsLevel =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.metricsConfig.metricsLevel",
Expand All @@ -170,7 +170,7 @@ public void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
}

@Test
public void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevelIsNone() {
void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevelIsNone() {
MetricsFactory metricsFactory =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.metricsFactory",
Expand All @@ -179,7 +179,7 @@ public void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevel
}

@Test
public void maxLeasesForWorkerOverriddenByCustomizer() {
void maxLeasesForWorkerOverriddenByCustomizer() {
Integer maxLeasesForWorker =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.leaseCoordinator.leaseTaker.maxLeasesForWorker",
Expand All @@ -188,7 +188,7 @@ public void maxLeasesForWorkerOverriddenByCustomizer() {
}

@Test
public void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
Long shardConsumerDispatchPollIntervalMillis =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.shardConsumerDispatchPollIntervalMillis",
Expand All @@ -197,7 +197,7 @@ public void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
}

@Test
public void pollingMaxRecordsIsPropagated() {
void pollingMaxRecordsIsPropagated() {
Integer maxRecords =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.retrievalConfig.retrievalSpecificConfig.maxRecords",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*/
@SpringJUnitConfig
@DirtiesContext
public class KinesisIntegrationTests implements LocalstackContainerTest {
class KinesisIntegrationTests implements LocalstackContainerTest {

private static final String TEST_STREAM = "TestStream";

Expand Down Expand Up @@ -95,7 +95,7 @@ static void tearDown() {
}

@Test
void testKinesisInboundOutbound() {
void kinesisInboundOutbound() {
this.kinesisSendChannel
.send(MessageBuilder.withPayload("foo").setHeader(AwsHeaders.STREAM, TEST_STREAM).build());

Expand Down Expand Up @@ -138,7 +138,7 @@ void testKinesisInboundOutbound() {
assertThat(receivedSequences.add(sequenceNumber)).isTrue();
}

assertThat(receivedSequences.size()).isEqualTo(2);
assertThat(receivedSequences).hasSize(2);

receive = this.kinesisReceiveChannel.receive(10);
assertThat(receive).isNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
@Disabled("Depends on real call to http://169.254.169.254 through native library")
@SpringJUnitConfig
@DirtiesContext
public class KplKclIntegrationTests implements LocalstackContainerTest {
class KplKclIntegrationTests implements LocalstackContainerTest {

private static final String TEST_STREAM = "TestStreamKplKcl";

Expand Down Expand Up @@ -105,7 +105,7 @@ static void tearDown() {
}

@Test
void testKinesisInboundOutbound() {
void kinesisInboundOutbound() {
this.kinesisSendChannel
.send(MessageBuilder.withPayload("foo").setHeader(AwsHeaders.STREAM, TEST_STREAM).build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void destroy() {
}

@Test
void testDistributedLeaderElection() throws Exception {
void distributedLeaderElection() throws Exception {
CountDownLatch granted = new CountDownLatch(1);
CountingPublisher countingPublisher = new CountingPublisher(granted);
List<DynamoDbLockRepository> repositories = new ArrayList<>();
Expand Down Expand Up @@ -176,7 +176,7 @@ void testDistributedLeaderElection() throws Exception {
}

@Test
void testLostConnection() throws Exception {
void lostConnection() throws Exception {
CountDownLatch granted = new CountDownLatch(1);
CountingPublisher countingPublisher = new CountingPublisher(granted);

Expand Down
Loading
Loading