Skip to content

Commit 510fe5b

Browse files
authored
Apply AssertJ and JUnit 5 best practices
For details on the recipe, see https://docs.openrewrite.org/recipes/java/testing/assertj/assertj-best-practices Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.testing.assertj.Assertj?organizationId=U3ByaW5n The AssertJ best practices is quite a large recipe that contains many others. See a full list here: https://docs.openrewrite.org/recipes/java/testing/assertj/assertj-best-practices. As part of migrating JUnit assertions to AssertJ there is the JUnit5BestPractices PR. This was an automated change.
1 parent adb66e4 commit 510fe5b

18 files changed

+79
-81
lines changed

src/test/java/org/springframework/integration/aws/inbound/KinesisMessageDrivenChannelAdapterTests.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2023 the original author or authors.
2+
* Copyright 2017-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@
8282
*/
8383
@SpringJUnitConfig
8484
@DirtiesContext
85-
public class KinesisMessageDrivenChannelAdapterTests {
85+
class KinesisMessageDrivenChannelAdapterTests {
8686

8787
private static final String STREAM1 = "stream1";
8888

@@ -118,7 +118,7 @@ void setup() {
118118

119119
@Test
120120
@SuppressWarnings({"unchecked", "rawtypes"})
121-
void testKinesisMessageDrivenChannelAdapter() {
121+
void kinesisMessageDrivenChannelAdapter() {
122122
this.kinesisMessageDrivenChannelAdapter.start();
123123
final Set<KinesisShardOffset> shardOffsets = TestUtils.getPropertyValue(this.kinesisMessageDrivenChannelAdapter,
124124
"shardOffsets", Set.class);
@@ -168,11 +168,11 @@ void testKinesisMessageDrivenChannelAdapter() {
168168
Map<?, ?> forLocking = TestUtils.getPropertyValue(this.kinesisMessageDrivenChannelAdapter,
169169
"shardConsumerManager.locks", Map.class);
170170

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

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

177177
this.kinesisMessageDrivenChannelAdapter.setListenerMode(ListenerMode.batch);
178178
this.kinesisMessageDrivenChannelAdapter.setCheckpointMode(CheckpointMode.record);
@@ -186,7 +186,7 @@ void testKinesisMessageDrivenChannelAdapter() {
186186
assertThat(message).isNotNull();
187187
assertThat(message.getPayload()).isInstanceOf(List.class);
188188
List<String> payload = (List<String>) message.getPayload();
189-
assertThat(payload).size().isEqualTo(1);
189+
assertThat(payload).hasSize(1);
190190
String record = payload.get(0);
191191
assertThat(record).isEqualTo("bar");
192192

@@ -219,7 +219,7 @@ void testKinesisMessageDrivenChannelAdapter() {
219219
assertThat(message).isNotNull();
220220
assertThat(message.getPayload()).isInstanceOf(List.class);
221221
List<String> messagePayload = (List<String>) message.getPayload();
222-
assertThat(messagePayload).size().isEqualTo(3);
222+
assertThat(messagePayload).hasSize(3);
223223

224224
Object messageSequenceNumberHeader = message.getHeaders().get(AwsHeaders.RECEIVED_SEQUENCE_NUMBER);
225225
assertThat(messageSequenceNumberHeader).isInstanceOf(List.class);
@@ -235,17 +235,15 @@ void testKinesisMessageDrivenChannelAdapter() {
235235
assertThat(message).isNotNull();
236236
assertThat(message.getPayload()).isInstanceOf(List.class);
237237
messagePayload = (List<String>) message.getPayload();
238-
assertThat(messagePayload).size().isEqualTo(2);
239-
assertThat(messagePayload).contains("bar");
240-
assertThat(messagePayload).contains("foobar");
238+
assertThat(messagePayload).containsExactly("bar", "foobar");
241239

242240
this.kinesisMessageDrivenChannelAdapter.stop();
243241

244242
}
245243

246244
@Test
247245
@SuppressWarnings("rawtypes")
248-
void testResharding() throws InterruptedException {
246+
void resharding() throws InterruptedException {
249247
this.reshardingChannelAdapter.start();
250248

251249
assertThat(this.kinesisChannel.receive(10000)).isNotNull();

src/test/java/org/springframework/integration/aws/inbound/S3InboundChannelAdapterTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
*/
5858
@SpringJUnitConfig
5959
@DirtiesContext
60-
public class S3InboundChannelAdapterTests implements LocalstackContainerTest {
60+
class S3InboundChannelAdapterTests implements LocalstackContainerTest {
6161

6262
private static final ExpressionParser PARSER = new SpelExpressionParser();
6363

@@ -84,12 +84,12 @@ static void setup() {
8484
}
8585

8686
@Test
87-
void testS3InboundChannelAdapter() throws IOException {
87+
void s3InboundChannelAdapter() throws IOException {
8888
Message<?> message = this.s3FilesChannel.receive(10000);
8989
assertThat(message).isNotNull();
9090
assertThat(message.getPayload()).isInstanceOf(File.class);
9191
File localFile = (File) message.getPayload();
92-
assertThat(localFile.getName()).isEqualTo("A.TEST.a");
92+
assertThat(localFile).hasName("A.TEST.a");
9393

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

103103
content = FileCopyUtils.copyToString(new FileReader(localFile));
104104
assertThat(content).isEqualTo("Bye");

src/test/java/org/springframework/integration/aws/inbound/S3StreamingChannelAdapterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*/
5757
@SpringJUnitConfig
5858
@DirtiesContext
59-
public class S3StreamingChannelAdapterTests implements LocalstackContainerTest {
59+
class S3StreamingChannelAdapterTests implements LocalstackContainerTest {
6060

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

@@ -74,7 +74,7 @@ static void setup() {
7474
}
7575

7676
@Test
77-
void testS3InboundStreamingChannelAdapter() throws IOException {
77+
void s3InboundStreamingChannelAdapter() throws IOException {
7878
Message<?> message = this.s3FilesChannel.receive(10000);
7979
assertThat(message).isNotNull();
8080
assertThat(message.getPayload()).isInstanceOf(InputStream.class);

src/test/java/org/springframework/integration/aws/inbound/SnsInboundChannelAdapterTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*/
5656
@SpringJUnitWebConfig
5757
@DirtiesContext
58-
public class SnsInboundChannelAdapterTests {
58+
class SnsInboundChannelAdapterTests {
5959

6060
@Autowired
6161
private WebApplicationContext context;
@@ -83,7 +83,7 @@ void setUp() {
8383
}
8484

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

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

124-
assertThat(payload.get("Subject")).isEqualTo("foo");
125-
assertThat(payload.get("Message")).isEqualTo("bar");
124+
assertThat(payload)
125+
.containsEntry("Subject", "foo")
126+
.containsEntry("Message", "bar");
126127
}
127128

128129
@Test
129-
void testUnsubscribe() throws Exception {
130+
void unsubscribe() throws Exception {
130131
this.mockMvc
131132
.perform(post("/mySampleTopic").header("x-amz-sns-message-type", "UnsubscribeConfirmation")
132133
.contentType(MediaType.TEXT_PLAIN)

src/test/java/org/springframework/integration/aws/inbound/SqsMessageDrivenChannelAdapterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
@SpringJUnitConfig
4545
@DirtiesContext
46-
public class SqsMessageDrivenChannelAdapterTests implements LocalstackContainerTest {
46+
class SqsMessageDrivenChannelAdapterTests implements LocalstackContainerTest {
4747

4848
private static SqsAsyncClient AMAZON_SQS;
4949

@@ -59,7 +59,7 @@ static void setup() {
5959
}
6060

6161
@Test
62-
void testSqsMessageDrivenChannelAdapter() {
62+
void sqsMessageDrivenChannelAdapter() {
6363
Map<String, MessageAttributeValue> attributes =
6464
Map.of("someAttribute",
6565
MessageAttributeValue.builder()

src/test/java/org/springframework/integration/aws/kinesis/KclMessageDrivenChannelAdapterMultiStreamTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
*/
5454
@SpringJUnitConfig
5555
@DirtiesContext
56-
57-
public class KclMessageDrivenChannelAdapterMultiStreamTests implements LocalstackContainerTest {
56+
class KclMessageDrivenChannelAdapterMultiStreamTests implements LocalstackContainerTest {
5857

5958
private static final String TEST_STREAM1 = "MultiStreamKcl1";
6059

@@ -104,7 +103,7 @@ static void tearDown() {
104103
}
105104

106105
@Test
107-
public void kclChannelAdapterMultiStream() {
106+
void kclChannelAdapterMultiStream() {
108107
String testData = "test data";
109108
AMAZON_KINESIS.putRecord(request -> request
110109
.streamName(TEST_STREAM1)

src/test/java/org/springframework/integration/aws/kinesis/KclMessageDrivenChannelAdapterTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private Message<?> verifyRecordReceived(String testData) {
161161
}
162162

163163
@Test
164-
public void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
164+
void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
165165
MetricsLevel metricsLevel =
166166
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
167167
"scheduler.metricsConfig.metricsLevel",
@@ -170,7 +170,7 @@ public void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
170170
}
171171

172172
@Test
173-
public void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevelIsNone() {
173+
void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevelIsNone() {
174174
MetricsFactory metricsFactory =
175175
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
176176
"scheduler.metricsFactory",
@@ -179,7 +179,7 @@ public void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevel
179179
}
180180

181181
@Test
182-
public void maxLeasesForWorkerOverriddenByCustomizer() {
182+
void maxLeasesForWorkerOverriddenByCustomizer() {
183183
Integer maxLeasesForWorker =
184184
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
185185
"scheduler.leaseCoordinator.leaseTaker.maxLeasesForWorker",
@@ -188,7 +188,7 @@ public void maxLeasesForWorkerOverriddenByCustomizer() {
188188
}
189189

190190
@Test
191-
public void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
191+
void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
192192
Long shardConsumerDispatchPollIntervalMillis =
193193
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
194194
"scheduler.shardConsumerDispatchPollIntervalMillis",
@@ -197,7 +197,7 @@ public void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
197197
}
198198

199199
@Test
200-
public void pollingMaxRecordsIsPropagated() {
200+
void pollingMaxRecordsIsPropagated() {
201201
Integer maxRecords =
202202
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
203203
"scheduler.retrievalConfig.retrievalSpecificConfig.maxRecords",

src/test/java/org/springframework/integration/aws/kinesis/KinesisIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
*/
6666
@SpringJUnitConfig
6767
@DirtiesContext
68-
public class KinesisIntegrationTests implements LocalstackContainerTest {
68+
class KinesisIntegrationTests implements LocalstackContainerTest {
6969

7070
private static final String TEST_STREAM = "TestStream";
7171

@@ -95,7 +95,7 @@ static void tearDown() {
9595
}
9696

9797
@Test
98-
void testKinesisInboundOutbound() {
98+
void kinesisInboundOutbound() {
9999
this.kinesisSendChannel
100100
.send(MessageBuilder.withPayload("foo").setHeader(AwsHeaders.STREAM, TEST_STREAM).build());
101101

@@ -138,7 +138,7 @@ void testKinesisInboundOutbound() {
138138
assertThat(receivedSequences.add(sequenceNumber)).isTrue();
139139
}
140140

141-
assertThat(receivedSequences.size()).isEqualTo(2);
141+
assertThat(receivedSequences).hasSize(2);
142142

143143
receive = this.kinesisReceiveChannel.receive(10);
144144
assertThat(receive).isNull();

src/test/java/org/springframework/integration/aws/kinesis/KplKclIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
@Disabled("Depends on real call to http://169.254.169.254 through native library")
6969
@SpringJUnitConfig
7070
@DirtiesContext
71-
public class KplKclIntegrationTests implements LocalstackContainerTest {
71+
class KplKclIntegrationTests implements LocalstackContainerTest {
7272

7373
private static final String TEST_STREAM = "TestStreamKplKcl";
7474

@@ -105,7 +105,7 @@ static void tearDown() {
105105
}
106106

107107
@Test
108-
void testKinesisInboundOutbound() {
108+
void kinesisInboundOutbound() {
109109
this.kinesisSendChannel
110110
.send(MessageBuilder.withPayload("foo").setHeader(AwsHeaders.STREAM, TEST_STREAM).build());
111111

src/test/java/org/springframework/integration/aws/leader/DynamoDbLockRegistryLeaderInitiatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void destroy() {
7575
}
7676

7777
@Test
78-
void testDistributedLeaderElection() throws Exception {
78+
void distributedLeaderElection() throws Exception {
7979
CountDownLatch granted = new CountDownLatch(1);
8080
CountingPublisher countingPublisher = new CountingPublisher(granted);
8181
List<DynamoDbLockRepository> repositories = new ArrayList<>();
@@ -176,7 +176,7 @@ void testDistributedLeaderElection() throws Exception {
176176
}
177177

178178
@Test
179-
void testLostConnection() throws Exception {
179+
void lostConnection() throws Exception {
180180
CountDownLatch granted = new CountDownLatch(1);
181181
CountingPublisher countingPublisher = new CountingPublisher(granted);
182182

0 commit comments

Comments
 (0)