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.
This commit is contained in:
Rick Ossendrijver
2024-12-27 16:57:12 +01:00
committed by GitHub
parent adb66e4970
commit 510fe5bfbd
18 changed files with 79 additions and 81 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 the original author or authors.
* Copyright 2017-2024 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.
@@ -82,7 +82,7 @@ import static org.mockito.Mockito.verify;
*/
@SpringJUnitConfig
@DirtiesContext
public class KinesisMessageDrivenChannelAdapterTests {
class KinesisMessageDrivenChannelAdapterTests {
private static final String STREAM1 = "stream1";
@@ -118,7 +118,7 @@ public class KinesisMessageDrivenChannelAdapterTests {
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
void testKinesisMessageDrivenChannelAdapter() {
void kinesisMessageDrivenChannelAdapter() {
this.kinesisMessageDrivenChannelAdapter.start();
final Set<KinesisShardOffset> shardOffsets = TestUtils.getPropertyValue(this.kinesisMessageDrivenChannelAdapter,
"shardOffsets", Set.class);
@@ -168,11 +168,11 @@ public class KinesisMessageDrivenChannelAdapterTests {
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);
@@ -186,7 +186,7 @@ public class KinesisMessageDrivenChannelAdapterTests {
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(List.class);
List<String> payload = (List<String>) message.getPayload();
assertThat(payload).size().isEqualTo(1);
assertThat(payload).hasSize(1);
String record = payload.get(0);
assertThat(record).isEqualTo("bar");
@@ -219,7 +219,7 @@ public class KinesisMessageDrivenChannelAdapterTests {
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);
@@ -235,9 +235,7 @@ public class KinesisMessageDrivenChannelAdapterTests {
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).containsExactly("bar", "foobar");
this.kinesisMessageDrivenChannelAdapter.stop();
@@ -245,7 +243,7 @@ public class KinesisMessageDrivenChannelAdapterTests {
@Test
@SuppressWarnings("rawtypes")
void testResharding() throws InterruptedException {
void resharding() throws InterruptedException {
this.reshardingChannelAdapter.start();
assertThat(this.kinesisChannel.receive(10000)).isNotNull();

View File

@@ -57,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@SpringJUnitConfig
@DirtiesContext
public class S3InboundChannelAdapterTests implements LocalstackContainerTest {
class S3InboundChannelAdapterTests implements LocalstackContainerTest {
private static final ExpressionParser PARSER = new SpelExpressionParser();
@@ -84,12 +84,12 @@ public class S3InboundChannelAdapterTests implements LocalstackContainerTest {
}
@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");
@@ -98,7 +98,7 @@ public class S3InboundChannelAdapterTests implements LocalstackContainerTest {
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");

View File

@@ -56,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@SpringJUnitConfig
@DirtiesContext
public class S3StreamingChannelAdapterTests implements LocalstackContainerTest {
class S3StreamingChannelAdapterTests implements LocalstackContainerTest {
private static final String S3_BUCKET = "s3-bucket";
@@ -74,7 +74,7 @@ public class S3StreamingChannelAdapterTests implements LocalstackContainerTest {
}
@Test
void testS3InboundStreamingChannelAdapter() throws IOException {
void s3InboundStreamingChannelAdapter() throws IOException {
Message<?> message = this.s3FilesChannel.receive(10000);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(InputStream.class);

View File

@@ -55,7 +55,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@SpringJUnitWebConfig
@DirtiesContext
public class SnsInboundChannelAdapterTests {
class SnsInboundChannelAdapterTests {
@Autowired
private WebApplicationContext context;
@@ -83,7 +83,7 @@ public class SnsInboundChannelAdapterTests {
}
@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)
@@ -110,7 +110,7 @@ public class SnsInboundChannelAdapterTests {
@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)
@@ -121,12 +121,13 @@ public class SnsInboundChannelAdapterTests {
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)

View File

@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@SpringJUnitConfig
@DirtiesContext
public class SqsMessageDrivenChannelAdapterTests implements LocalstackContainerTest {
class SqsMessageDrivenChannelAdapterTests implements LocalstackContainerTest {
private static SqsAsyncClient AMAZON_SQS;
@@ -59,7 +59,7 @@ public class SqsMessageDrivenChannelAdapterTests implements LocalstackContainerT
}
@Test
void testSqsMessageDrivenChannelAdapter() {
void sqsMessageDrivenChannelAdapter() {
Map<String, MessageAttributeValue> attributes =
Map.of("someAttribute",
MessageAttributeValue.builder()

View File

@@ -53,8 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@SpringJUnitConfig
@DirtiesContext
public class KclMessageDrivenChannelAdapterMultiStreamTests implements LocalstackContainerTest {
class KclMessageDrivenChannelAdapterMultiStreamTests implements LocalstackContainerTest {
private static final String TEST_STREAM1 = "MultiStreamKcl1";
@@ -104,7 +103,7 @@ public class KclMessageDrivenChannelAdapterMultiStreamTests implements Localstac
}
@Test
public void kclChannelAdapterMultiStream() {
void kclChannelAdapterMultiStream() {
String testData = "test data";
AMAZON_KINESIS.putRecord(request -> request
.streamName(TEST_STREAM1)

View File

@@ -161,7 +161,7 @@ public class KclMessageDrivenChannelAdapterTests implements LocalstackContainerT
}
@Test
public void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
void metricsLevelOfMetricsConfigShouldBeSetToMetricsLevelOfAdapter() {
MetricsLevel metricsLevel =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.metricsConfig.metricsLevel",
@@ -170,7 +170,7 @@ public class KclMessageDrivenChannelAdapterTests implements LocalstackContainerT
}
@Test
public void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevelIsNone() {
void metricsFactoryOfSchedulerShouldBeSetNullMetricsFactoryIfMetricsLevelIsNone() {
MetricsFactory metricsFactory =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.metricsFactory",
@@ -179,7 +179,7 @@ public class KclMessageDrivenChannelAdapterTests implements LocalstackContainerT
}
@Test
public void maxLeasesForWorkerOverriddenByCustomizer() {
void maxLeasesForWorkerOverriddenByCustomizer() {
Integer maxLeasesForWorker =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.leaseCoordinator.leaseTaker.maxLeasesForWorker",
@@ -188,7 +188,7 @@ public class KclMessageDrivenChannelAdapterTests implements LocalstackContainerT
}
@Test
public void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
void shardConsumerDispatchPollIntervalMillisOverriddenByCustomizer() {
Long shardConsumerDispatchPollIntervalMillis =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.shardConsumerDispatchPollIntervalMillis",
@@ -197,7 +197,7 @@ public class KclMessageDrivenChannelAdapterTests implements LocalstackContainerT
}
@Test
public void pollingMaxRecordsIsPropagated() {
void pollingMaxRecordsIsPropagated() {
Integer maxRecords =
TestUtils.getPropertyValue(this.kclMessageDrivenChannelAdapter,
"scheduler.retrievalConfig.retrievalSpecificConfig.maxRecords",

View File

@@ -65,7 +65,7 @@ import static org.assertj.core.api.Assertions.entry;
*/
@SpringJUnitConfig
@DirtiesContext
public class KinesisIntegrationTests implements LocalstackContainerTest {
class KinesisIntegrationTests implements LocalstackContainerTest {
private static final String TEST_STREAM = "TestStream";
@@ -95,7 +95,7 @@ public class KinesisIntegrationTests implements LocalstackContainerTest {
}
@Test
void testKinesisInboundOutbound() {
void kinesisInboundOutbound() {
this.kinesisSendChannel
.send(MessageBuilder.withPayload("foo").setHeader(AwsHeaders.STREAM, TEST_STREAM).build());
@@ -138,7 +138,7 @@ public class KinesisIntegrationTests implements LocalstackContainerTest {
assertThat(receivedSequences.add(sequenceNumber)).isTrue();
}
assertThat(receivedSequences.size()).isEqualTo(2);
assertThat(receivedSequences).hasSize(2);
receive = this.kinesisReceiveChannel.receive(10);
assertThat(receive).isNull();

View File

@@ -68,7 +68,7 @@ import static org.assertj.core.api.Assertions.entry;
@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";
@@ -105,7 +105,7 @@ public class KplKclIntegrationTests implements LocalstackContainerTest {
}
@Test
void testKinesisInboundOutbound() {
void kinesisInboundOutbound() {
this.kinesisSendChannel
.send(MessageBuilder.withPayload("foo").setHeader(AwsHeaders.STREAM, TEST_STREAM).build());

View File

@@ -75,7 +75,7 @@ class DynamoDbLockRegistryLeaderInitiatorTests implements LocalstackContainerTes
}
@Test
void testDistributedLeaderElection() throws Exception {
void distributedLeaderElection() throws Exception {
CountDownLatch granted = new CountDownLatch(1);
CountingPublisher countingPublisher = new CountingPublisher(granted);
List<DynamoDbLockRepository> repositories = new ArrayList<>();
@@ -176,7 +176,7 @@ class DynamoDbLockRegistryLeaderInitiatorTests implements LocalstackContainerTes
}
@Test
void testLostConnection() throws Exception {
void lostConnection() throws Exception {
CountDownLatch granted = new CountDownLatch(1);
CountingPublisher countingPublisher = new CountingPublisher(granted);

View File

@@ -55,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThatNoException;
*/
@SpringJUnitConfig
@DirtiesContext
public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
class DynamoDbLockRegistryTests implements LocalstackContainerTest {
private static DynamoDbAsyncClient DYNAMO_DB;
@@ -98,7 +98,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
@Test
@SuppressWarnings("unchecked")
void testLock() {
void lock() {
for (int i = 0; i < 10; i++) {
Lock lock = this.dynamoDbLockRegistry.obtain("foo");
lock.lock();
@@ -113,7 +113,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
@Test
@SuppressWarnings("unchecked")
void testLockInterruptibly() throws Exception {
void lockInterruptibly() throws Exception {
for (int i = 0; i < 10; i++) {
Lock lock = this.dynamoDbLockRegistry.obtain("foo");
lock.lockInterruptibly();
@@ -127,7 +127,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
void testReentrantLock() {
void reentrantLock() {
for (int i = 0; i < 10; i++) {
Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
lock1.lock();
@@ -144,7 +144,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
void testReentrantLockInterruptibly() throws Exception {
void reentrantLockInterruptibly() throws Exception {
for (int i = 0; i < 10; i++) {
Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
lock1.lockInterruptibly();
@@ -161,7 +161,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
void testTwoLocks() throws Exception {
void twoLocks() throws Exception {
for (int i = 0; i < 10; i++) {
Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
lock1.lockInterruptibly();
@@ -178,7 +178,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
void testTwoThreadsSecondFailsToGetLock() throws Exception {
void twoThreadsSecondFailsToGetLock() throws Exception {
final Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
lock1.lockInterruptibly();
final AtomicBoolean locked = new AtomicBoolean();
@@ -212,7 +212,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
void testTwoThreads() throws Exception {
void twoThreads() throws Exception {
final Lock lock1 = this.dynamoDbLockRegistry.obtain("foo");
final AtomicBoolean locked = new AtomicBoolean();
final CountDownLatch latch1 = new CountDownLatch(1);
@@ -254,7 +254,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
void testTwoThreadsDifferentRegistries() throws Exception {
void twoThreadsDifferentRegistries() throws Exception {
DynamoDbLockRepository dynamoDbLockRepository = new DynamoDbLockRepository(DYNAMO_DB);
dynamoDbLockRepository.setLeaseDuration(Duration.ofSeconds(10));
dynamoDbLockRepository.afterPropertiesSet();
@@ -299,7 +299,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
void testTwoThreadsWrongOneUnlocks() throws Exception {
void twoThreadsWrongOneUnlocks() throws Exception {
final Lock lock = this.dynamoDbLockRegistry.obtain("foo");
lock.lockInterruptibly();
final AtomicBoolean locked = new AtomicBoolean();
@@ -343,7 +343,7 @@ public class DynamoDbLockRegistryTests implements LocalstackContainerTest {
}
@Test
public void testLockRenew() {
void lockRenew() {
final Lock lock = this.dynamoDbLockRegistry.obtain("foo");
assertThat(lock.tryLock()).isTrue();

View File

@@ -87,7 +87,7 @@ class DynamoDbMetadataStoreTests implements LocalstackContainerTest {
}
@Test
void testGetFromStore() {
void getFromStore() {
String fileID = store.get(this.file1);
assertThat(fileID).isNull();
@@ -99,7 +99,7 @@ class DynamoDbMetadataStoreTests implements LocalstackContainerTest {
}
@Test
void testPutIfAbsent() {
void putIfAbsent() {
String fileID = store.get(this.file1);
assertThat(fileID).describedAs("Get First time, Value must not exist").isNull();
@@ -114,7 +114,7 @@ class DynamoDbMetadataStoreTests implements LocalstackContainerTest {
}
@Test
void testRemove() {
void remove() {
String fileID = store.remove(this.file1);
assertThat(fileID).isNull();
@@ -130,7 +130,7 @@ class DynamoDbMetadataStoreTests implements LocalstackContainerTest {
}
@Test
void testReplace() {
void replace() {
boolean removedValue = store.replace(this.file1, this.file1Id, "4567");
assertThat(removedValue).isFalse();

View File

@@ -60,7 +60,7 @@ import static org.mockito.Mockito.verify;
*/
@SpringJUnitConfig
@DirtiesContext
public class KinesisMessageHandlerTests {
class KinesisMessageHandlerTests {
@Autowired
protected KinesisAsyncClient amazonKinesis;
@@ -73,7 +73,7 @@ public class KinesisMessageHandlerTests {
@Test
@SuppressWarnings("unchecked")
void testKinesisMessageHandler() {
void kinesisMessageHandler() {
final Message<?> message = MessageBuilder.withPayload("message").build();
assertThatExceptionOfType(MessageHandlingException.class)

View File

@@ -61,7 +61,7 @@ import static org.mockito.Mockito.mock;
*/
@SpringJUnitConfig
@DirtiesContext
public class KinesisProducingMessageHandlerTests {
class KinesisProducingMessageHandlerTests {
@Autowired
protected MessageChannel kinesisSendChannel;
@@ -76,7 +76,7 @@ public class KinesisProducingMessageHandlerTests {
protected PollableChannel successChannel;
@Test
public void testKinesisMessageHandler() {
void kinesisMessageHandler() {
final Message<?> message =
MessageBuilder.withPayload("message")
.setErrorChannel(this.errorChannel)

View File

@@ -80,7 +80,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
*/
@SpringJUnitConfig
@DirtiesContext
public class S3MessageHandlerTests implements LocalstackContainerTest {
class S3MessageHandlerTests implements LocalstackContainerTest {
private static S3AsyncClient S3;
@@ -137,7 +137,7 @@ public class S3MessageHandlerTests implements LocalstackContainerTest {
}
@Test
void testUploadFile() throws IOException, InterruptedException {
void uploadFile() throws IOException, InterruptedException {
File file = new File(temporaryFolder.toFile(), "foo.mp3");
file.createNewFile();
byte[] testData = "test data".getBytes();
@@ -172,7 +172,7 @@ public class S3MessageHandlerTests implements LocalstackContainerTest {
}
@Test
void testUploadInputStream() throws IOException, InterruptedException {
void uploadInputStream() throws IOException, InterruptedException {
Expression actualKeyExpression =
TestUtils.getPropertyValue(this.s3MessageHandler, "keyExpression", Expression.class);
@@ -221,7 +221,7 @@ public class S3MessageHandlerTests implements LocalstackContainerTest {
}
@Test
void testUploadByteArray() throws InterruptedException, IOException {
void uploadByteArray() throws InterruptedException, IOException {
CountDownLatch transferCompletedLatch = new CountDownLatch(1);
byte[] payload = "b".getBytes(StandardCharsets.UTF_8);
Message<?> message =
@@ -257,7 +257,7 @@ public class S3MessageHandlerTests implements LocalstackContainerTest {
}
@Test
void testDownloadDirectory() throws IOException {
void downloadDirectory() throws IOException {
CompletableFuture<PutObjectResponse> bb =
S3.putObject(request -> request.bucket(S3_BUCKET_NAME).key(S3_FILE_KEY_BAR),
AsyncRequestBody.fromString("bb"));
@@ -280,7 +280,7 @@ public class S3MessageHandlerTests implements LocalstackContainerTest {
assertThat(directoryArray.length).isEqualTo(1);
File subDirectory = directoryArray[0];
assertThat(subDirectory.getName()).isEqualTo("subdir");
assertThat(subDirectory).hasName("subdir");
// get the files we downloaded
File[] fileArray = subDirectory.listFiles();
@@ -291,16 +291,16 @@ public class S3MessageHandlerTests implements LocalstackContainerTest {
files.sort(Comparator.comparing(File::getName));
File file1 = files.get(0);
assertThat(file1.getName()).isEqualTo(S3_FILE_KEY_BAR.split("/", 2)[1]);
assertThat(file1).hasName(S3_FILE_KEY_BAR.split("/", 2)[1]);
assertThat(FileCopyUtils.copyToString(new FileReader(file1))).isEqualTo("bb");
File file2 = files.get(1);
assertThat(file2.getName()).isEqualTo(S3_FILE_KEY_FOO.split("/", 2)[1]);
assertThat(file2).hasName(S3_FILE_KEY_FOO.split("/", 2)[1]);
assertThat(FileCopyUtils.copyToString(new FileReader(file2))).isEqualTo("f");
}
@Test
void testCopy() throws IOException {
void copy() throws IOException {
byte[] testData = "ff".getBytes();
CompletableFuture<PutObjectResponse> mySource =
S3.putObject(request -> request.bucket(S3_BUCKET_NAME).key("mySource"),

View File

@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
class SnsBodyBuilderTests {
@Test
void testSnsBodyBuilder() {
void snsBodyBuilder() {
assertThatIllegalArgumentException()
.isThrownBy(() -> SnsBodyBuilder.withDefault(""))
.withMessageContaining("defaultMessage must not be empty.");

View File

@@ -59,7 +59,7 @@ import static org.mockito.Mockito.verify;
*/
@SpringJUnitConfig
@DirtiesContext
public class SnsMessageHandlerTests {
class SnsMessageHandlerTests {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
@@ -73,7 +73,7 @@ public class SnsMessageHandlerTests {
private PollableChannel resultChannel;
@Test
void testSnsMessageHandler() {
void snsMessageHandler() {
SnsBodyBuilder payload = SnsBodyBuilder.withDefault("foo").forProtocols("{\"foo\" : \"bar\"}", "sms");
Message<?> message = MessageBuilder.withPayload(payload).setHeader("topic", "topic")
@@ -99,9 +99,9 @@ public class SnsMessageHandlerTests {
Map<String, MessageAttributeValue> messageAttributes = publishRequest.messageAttributes();
assertThat(messageAttributes).doesNotContainKey(MessageHeaders.ID);
assertThat(messageAttributes).doesNotContainKey(MessageHeaders.TIMESTAMP);
assertThat(messageAttributes).containsKey("foo");
assertThat(messageAttributes)
.doesNotContainKeys(MessageHeaders.ID, MessageHeaders.TIMESTAMP)
.containsKey("foo");
assertThat(messageAttributes.get("foo").stringValue()).isEqualTo("bar");
assertThat(reply.getHeaders().get(AwsHeaders.MESSAGE_ID)).isEqualTo("111");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 the original author or authors.
* Copyright 2015-2024 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.
@@ -56,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Seth Kelly
*/
@SpringJUnitConfig
public class SqsMessageHandlerTests implements LocalstackContainerTest {
class SqsMessageHandlerTests implements LocalstackContainerTest {
private static final AtomicReference<String> fooUrl = new AtomicReference<>();
@@ -92,7 +92,7 @@ public class SqsMessageHandlerTests implements LocalstackContainerTest {
}
@Test
void testSqsMessageHandler() {
void sqsMessageHandler() {
final Message<String> message = MessageBuilder.withPayload("message").build();
assertThatExceptionOfType(MessageHandlingException.class)
@@ -139,14 +139,14 @@ public class SqsMessageHandlerTests implements LocalstackContainerTest {
Map<String, MessageAttributeValue> messageAttributes = message1.messageAttributes();
assertThat(messageAttributes).doesNotContainKey(MessageHeaders.ID);
assertThat(messageAttributes).doesNotContainKey(MessageHeaders.TIMESTAMP);
assertThat(messageAttributes).containsKey("foo");
assertThat(messageAttributes)
.doesNotContainKeys(MessageHeaders.ID, MessageHeaders.TIMESTAMP)
.containsKey("foo");
assertThat(messageAttributes.get("foo").stringValue()).isEqualTo("baz");
}
@Test
void testSqsMessageHandlerWithAutoQueueCreate() {
void sqsMessageHandlerWithAutoQueueCreate() {
Message<String> message = MessageBuilder.withPayload("message").build();
this.sqsSendChannelWithAutoCreate.send(message);