diff --git a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java index fbfb32c19..a8a47883d 100644 --- a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java +++ b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 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. @@ -22,7 +22,6 @@ package org.springframework.cloud.stream.binder.rabbit.admin; * @author Gary Russell * @since 1.2 */ -@SuppressWarnings("serial") public class RabbitAdminException extends RuntimeException { public RabbitAdminException(String message, Throwable cause) { diff --git a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestContainer.java b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestContainer.java index c7de2b242..a2aeb73ac 100644 --- a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestContainer.java +++ b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2022 the original author or authors. + * Copyright 2022-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. @@ -24,8 +24,12 @@ import org.testcontainers.containers.RabbitMQContainer; * Provides a static {@link RabbitMQContainer} that can be shared across test classes. * * @author Chris Bono + * @author Omer Celik */ -public class RabbitTestContainer { +public final class RabbitTestContainer { + + private RabbitTestContainer() { + } private static final RabbitMQContainer RABBITMQ; static { diff --git a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java index 3188b12e6..f7e17ded9 100644 --- a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java +++ b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java @@ -193,7 +193,7 @@ class RabbitBinderModuleTests { private void checkCustomizedArgs() throws MalformedURLException, URISyntaxException, InterruptedException { List> bindings = RestUtils.getBindingsBySource(client, uri, "/", "process-in-0"); int n = 0; - while (n++ < 100 && bindings == null || bindings.size() < 1) { + while (n++ < 100 && bindings == null || bindings.isEmpty()) { Thread.sleep(100); bindings = RestUtils.getBindingsBySource(client, uri, "/", "process-in-0"); } diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinderTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinderTests.java index a0823f931..e1214b6ee 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinderTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2023-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. @@ -21,6 +21,7 @@ import java.time.Duration; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.validation.constraints.NotNull; import org.junit.jupiter.api.Test; import org.springframework.cloud.stream.provisioning.ConsumerDestination; @@ -44,6 +45,23 @@ public class AbstractMessageChannelBinderTests { @SuppressWarnings("unchecked") void serializeDurationOnObjectMapperInAMCB() throws Exception { + AbstractMessageChannelBinder binder = createBinderInstance(); + + Field objectMapperField = ReflectionUtils.findField(AbstractMessageChannelBinder.class, "objectMapper"); + assertThat(objectMapperField).isNotNull(); + ReflectionUtils.makeAccessible(objectMapperField); + final ObjectMapper objectMapper = (ObjectMapper) ReflectionUtils.getField(objectMapperField, binder); + assertThat(objectMapper).isNotNull(); + + Duration duration = Duration.ofHours(1); + Map properties = Map.of("foo", duration); + final Map convertedMap = objectMapper.convertValue(properties, Map.class); + + assertThat(convertedMap).isNotEmpty(); + } + + @NotNull + private static AbstractMessageChannelBinder createBinderInstance() throws Exception { AbstractMessageChannelBinder binder = new AbstractMessageChannelBinder<>(null, null) { @Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ProducerProperties producerProperties, MessageChannel errorChannel) { @@ -59,17 +77,6 @@ public class AbstractMessageChannelBinderTests { applicationContext.refresh(); binder.setApplicationContext(applicationContext); binder.onInit(); - - Field objectMapperField = ReflectionUtils.findField(AbstractMessageChannelBinder.class, "objectMapper"); - assertThat(objectMapperField).isNotNull(); - ReflectionUtils.makeAccessible(objectMapperField); - final ObjectMapper objectMapper = (ObjectMapper) ReflectionUtils.getField(objectMapperField, binder); - assertThat(objectMapper).isNotNull(); - - Duration duration = Duration.ofHours(1); - Map properties = Map.of("foo", duration); - final Map convertedMap = objectMapper.convertValue(properties, Map.class); - - assertThat(convertedMap).isNotEmpty(); + return binder; } } diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java index 06e4ed10d..315d14c6f 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java @@ -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. @@ -57,7 +57,7 @@ class InputOutputBindingOrderTest { verify(binder).bindConsumer(eq("processor-in-0"), isNull(), Mockito.any(MessageChannel.class), Mockito.any()); SomeLifecycle someLifecycle = applicationContext.getBean(SomeLifecycle.class); - assertThat(someLifecycle.isRunning()); + assertThat(someLifecycle.isRunning()).isTrue(); applicationContext.close(); assertThat(someLifecycle.isRunning()).isFalse(); applicationContext.close();