Skip to content

Commit ab350fb

Browse files
rickieTeamModerne
andcommitted
refactor: AssertJ best practices
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.testing.assertj.Assertj?organizationId=U3ByaW5n Co-authored-by: Moderne <[email protected]>
1 parent adb66e4 commit ab350fb

18 files changed

+79
-76
lines changed

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -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);
@@ -236,16 +236,17 @@ void testKinesisMessageDrivenChannelAdapter() {
236236
assertThat(message.getPayload()).isInstanceOf(List.class);
237237
messagePayload = (List<String>) message.getPayload();
238238
assertThat(messagePayload).size().isEqualTo(2);
239-
assertThat(messagePayload).contains("bar");
240-
assertThat(messagePayload).contains("foobar");
239+
assertThat(messagePayload)
240+
.contains("bar")
241+
.contains("foobar");
241242

242243
this.kinesisMessageDrivenChannelAdapter.stop();
243244

244245
}
245246

246247
@Test
247248
@SuppressWarnings("rawtypes")
248-
void testResharding() throws InterruptedException {
249+
void resharding() throws InterruptedException {
249250
this.reshardingChannelAdapter.start();
250251

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

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

+4-4
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

+2-2
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

+7-6
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

+2-2
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

+2-3
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

+5-5
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

+3-3
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

+2-2
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

+2-2
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

src/test/java/org/springframework/integration/aws/lock/DynamoDbLockRegistryTests.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*/
5656
@SpringJUnitConfig
5757
@DirtiesContext
58-
public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
58+
class DynamoDbLockRegistryTests implements LocalstackContainerTest {
5959

6060
private static DynamoDbAsyncClient DYNAMO_DB;
6161

@@ -98,7 +98,7 @@ void clear() throws InterruptedException {
9898

9999
@Test
100100
@SuppressWarnings("unchecked")
101-
void testLock() {
101+
void lock() {
102102
for (int i = 0; i < 10; i++) {
103103
Lock lock = this.dynamoDbLockRegistry.obtain("foo");
104104
lock.lock();
@@ -113,7 +113,7 @@ void testLock() {
113113

114114
@Test
115115
@SuppressWarnings("unchecked")
116-
void testLockInterruptibly() throws Exception {
116+
void lockInterruptibly() throws Exception {
117117
for (int i = 0; i < 10; i++) {
118118
Lock lock = this.dynamoDbLockRegistry.obtain("foo");
119119
lock.lockInterruptibly();
@@ -127,7 +127,7 @@ void testLockInterruptibly() throws Exception {
127127
}
128128

129129
@Test
130-
void testReentrantLock() {
130+
void reentrantLock() {
131131
for (int i = 0; i < 10; i++) {
132132
Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
133133
lock1.lock();
@@ -144,7 +144,7 @@ void testReentrantLock() {
144144
}
145145

146146
@Test
147-
void testReentrantLockInterruptibly() throws Exception {
147+
void reentrantLockInterruptibly() throws Exception {
148148
for (int i = 0; i < 10; i++) {
149149
Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
150150
lock1.lockInterruptibly();
@@ -161,7 +161,7 @@ void testReentrantLockInterruptibly() throws Exception {
161161
}
162162

163163
@Test
164-
void testTwoLocks() throws Exception {
164+
void twoLocks() throws Exception {
165165
for (int i = 0; i < 10; i++) {
166166
Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
167167
lock1.lockInterruptibly();
@@ -178,7 +178,7 @@ void testTwoLocks() throws Exception {
178178
}
179179

180180
@Test
181-
void testTwoThreadsSecondFailsToGetLock() throws Exception {
181+
void twoThreadsSecondFailsToGetLock() throws Exception {
182182
final Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
183183
lock1.lockInterruptibly();
184184
final AtomicBoolean locked = new AtomicBoolean();
@@ -212,7 +212,7 @@ void testTwoThreadsSecondFailsToGetLock() throws Exception {
212212
}
213213

214214
@Test
215-
void testTwoThreads() throws Exception {
215+
void twoThreads() throws Exception {
216216
final Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
217217
final AtomicBoolean locked = new AtomicBoolean();
218218
final CountDownLatch latch1 = new CountDownLatch(1);
@@ -254,7 +254,7 @@ void testTwoThreads() throws Exception {
254254
}
255255

256256
@Test
257-
void testTwoThreadsDifferentRegistries() throws Exception {
257+
void twoThreadsDifferentRegistries() throws Exception {
258258
DynamoDbLockRepository dynamoDbLockRepository = new DynamoDbLockRepository(DYNAMO_DB);
259259
dynamoDbLockRepository.setLeaseDuration(Duration.ofSeconds(10));
260260
dynamoDbLockRepository.afterPropertiesSet();
@@ -299,7 +299,7 @@ void testTwoThreadsDifferentRegistries() throws Exception {
299299
}
300300

301301
@Test
302-
void testTwoThreadsWrongOneUnlocks() throws Exception {
302+
void twoThreadsWrongOneUnlocks() throws Exception {
303303
final Lock lock = this.dynamoDbLockRegistry.obtain("foo");
304304
lock.lockInterruptibly();
305305
final AtomicBoolean locked = new AtomicBoolean();
@@ -343,7 +343,7 @@ void abandonedLock() throws Exception {
343343
}
344344

345345
@Test
346-
public void testLockRenew() {
346+
void lockRenew() {
347347
final Lock lock = this.dynamoDbLockRegistry.obtain("foo");
348348

349349
assertThat(lock.tryLock()).isTrue();

0 commit comments

Comments
 (0)