Fix formatting

This commit is contained in:
Oleg Zhurakousky
2025-04-11 13:22:50 +02:00
committed by Ryan Baxter
parent 50d5ae512e
commit c643bd3ae1
7 changed files with 40 additions and 104 deletions

View File

@@ -30,8 +30,8 @@ import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler;
import org.apache.kafka.streams.kstream.KStream;
import org.assertj.core.api.Assertions;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

View File

@@ -20,12 +20,12 @@ package org.springframework.cloud.stream.binder.test.junit.rabbit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.util.Assert;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Abstract base class for JUnit {@link Rule}s that detect the presence of some external
@@ -64,68 +64,10 @@ public abstract class AbstractExternalResourceTestSupport<R> implements BeforeEa
catch (Exception e) {
maybeCleanup();
// failOrSkip(e);
fail();
Assertions.fail();
}
}
// @Override
// public Statement apply(final Statement base, Description description) {
// try {
// obtainResource();
// }
// catch (Exception e) {
// maybeCleanup();
//
// return failOrSkip(e);
// }
//
// return new Statement() {
//
// @Override
// public void evaluate() throws Throwable {
// try {
// base.evaluate();
// }
// finally {
// try {
// cleanupResource();
// }
// catch (Exception ignored) {
// AbstractExternalResourceTestSupport.this.logger.warn(
// "Exception while trying to cleanup proper resource",
// ignored);
// }
// }
// }
//
// };
// }
// private Statement failOrSkip(final Exception e) {
// String serversRequired = System.getenv(SCS_EXTERNAL_SERVERS_REQUIRED);
// if ("true".equalsIgnoreCase(serversRequired)) {
// this.logger.error(this.resourceDescription + " IS REQUIRED BUT NOT AVAILABLE",
// e);
// fail(this.resourceDescription + " IS NOT AVAILABLE");
// // Never reached, here to satisfy method signature
// return null;
// }
// else {
// this.logger.error(
// this.resourceDescription + " IS NOT AVAILABLE, SKIPPING TESTS", e);
// return new Statement() {
//
// @Override
// public void evaluate() throws Throwable {
// Assume.assumeTrue("Skipping test due to "
// + AbstractExternalResourceTestSupport.this.resourceDescription
// + " not being available " + e, false);
// }
// };
// }
// }
private void maybeCleanup() {
if (this.resource != null) {
try {

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.stream.binder.rabbit;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
@@ -41,13 +40,15 @@ class BatchCapableRejectAndDontRequeueRecovererTest {
Throwable expectedThrowable = new RuntimeException("test");
ListenerExecutionFailedException exception = Assertions.assertThrows(ListenerExecutionFailedException.class,
() -> messageBatchRecoverer.recover(messages, expectedThrowable));
assertThat(exception.getFailedMessages()).contains(expectedMessage1);
assertThat(exception.getFailedMessages()).contains(expectedMessage2);
assertThat(exception.getCause()).isInstanceOf(AmqpRejectAndDontRequeueException.class);
assertThat(expectedThrowable).isEqualTo(exception.getCause().getCause());
try {
messageBatchRecoverer.recover(messages, expectedThrowable);
}
catch (ListenerExecutionFailedException exception) {
assertThat(exception.getFailedMessages()).contains(expectedMessage1);
assertThat(exception.getFailedMessages()).contains(expectedMessage2);
assertThat(exception.getCause()).isInstanceOf(AmqpRejectAndDontRequeueException.class);
assertThat(expectedThrowable).isEqualTo(exception.getCause().getCause());
}
}
@Test
@@ -58,11 +59,13 @@ class BatchCapableRejectAndDontRequeueRecovererTest {
Throwable expectedThrowable = new RuntimeException("test");
ListenerExecutionFailedException exception = Assertions.assertThrows(ListenerExecutionFailedException.class,
() -> messageBatchRecoverer.recover(expectedMessage, expectedThrowable));
assertThat(expectedMessage).isEqualTo(exception.getFailedMessage());
assertThat(exception.getCause()).isInstanceOf(AmqpRejectAndDontRequeueException.class);
assertThat(expectedThrowable).isEqualTo(exception.getCause().getCause());
try {
messageBatchRecoverer.recover(expectedMessage, expectedThrowable);
}
catch (ListenerExecutionFailedException exception) {
assertThat(expectedMessage).isEqualTo(exception.getFailedMessage());
assertThat(exception.getCause()).isInstanceOf(AmqpRejectAndDontRequeueException.class);
assertThat(expectedThrowable).isEqualTo(exception.getCause().getCause());
}
}
}

View File

@@ -26,6 +26,7 @@ import java.util.UUID;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.containers.RabbitMQContainer;
@@ -48,7 +49,6 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
/**
* @author Gary Russell
@@ -127,7 +127,7 @@ class RabbitBinderCleanerTests {
try {
waitForConsumerState(queueName, 1);
doClean(cleaner, stream1, false);
fail("Expected exception");
Assertions.fail("Expected exception");
}
catch (RabbitAdminException e) {
assertThat(e)
@@ -137,7 +137,7 @@ class RabbitBinderCleanerTests {
waitForConsumerState(queueName, 0);
try {
doClean(cleaner, stream1, false);
fail("Expected exception");
Assertions.fail("Expected exception");
}
catch (RabbitAdminException e) {
assertThat(e).hasMessageContaining("Cannot delete exchange ");

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.stream.binder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
@@ -47,9 +46,12 @@ class BinderErrorChannelTests {
@Test
void exceptionIsThrownWhenNoSubscribers() {
BinderErrorChannel channel = new BinderErrorChannel();
Assertions.assertThrows(MessageDeliveryException.class, () -> {
try {
channel.send(new GenericMessage<String>("hello"));
});
}
catch (MessageDeliveryException e) {
// ignore
}
}
@Test

View File

@@ -31,6 +31,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -81,7 +82,6 @@ import org.springframework.messaging.support.GenericMessage;
import org.springframework.scheduling.support.PeriodicTrigger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
/**
*
@@ -213,7 +213,7 @@ class ImplicitFunctionBindingTests {
InputDestination input = context.getBean(InputDestination.class);
try {
input.send(new GenericMessage<byte[]>("hello".getBytes()));
fail(); // it should since there are no functions and no bindings
Assertions.fail(); // it should since there are no functions and no bindings
}
catch (Exception e) {
// good, we expected it
@@ -240,7 +240,7 @@ class ImplicitFunctionBindingTests {
InputDestination input = context.getBean(InputDestination.class);
try {
input.send(new GenericMessage<byte[]>("hello".getBytes()));
fail(); // it should since there are no functions and no bindings
Assertions.fail(); // it should since there are no functions and no bindings
}
catch (Exception e) {
// good, we expected it
@@ -265,7 +265,7 @@ class ImplicitFunctionBindingTests {
context.getBean(InputDestination.class);
}
catch (Exception e) { // should not fail
fail();
Assertions.fail();
}
}
@@ -525,17 +525,6 @@ class ImplicitFunctionBindingTests {
}
}
// @Test
// public void testFunctionConfigDisabledIfStreamListenerIsUsed() {
// System.clearProperty("spring.cloud.function.definition");
// try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
// TestChannelBinderConfiguration.getCompleteConfiguration(LegacyConfiguration.class))
// .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
//
// assertThat(context.getBean("supplierInitializer").getClass().getSimpleName()).isEqualTo("NullBean");
// }
// }
@Test
void declaredTypeVsActualInstance() {
System.clearProperty("spring.cloud.function.definition");
@@ -548,7 +537,7 @@ class ImplicitFunctionBindingTests {
Message<byte[]> inputMessageOne = MessageBuilder.withPayload("Hello".getBytes()).build();
inputDestination.send(inputMessageOne);
fail();
Assertions.fail();
}
catch (Exception ex) {
// good
@@ -672,7 +661,7 @@ class ImplicitFunctionBindingTests {
try {
context.getBean(FunctionConfiguration.class);
fail();
Assertions.fail();
}
catch (Exception e) {
// ignore

View File

@@ -37,7 +37,6 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -213,11 +212,12 @@ class StreamBridgeTests {
"--spring.cloud.stream.source=outputA",
"--spring.jmx.enabled=false")) {
StreamBridge streamBridge = context.getBean(StreamBridge.class);
var exception = Assertions.assertThrows(RuntimeException.class, () -> streamBridge.send("outputA-out-0",
new CodecException("invalidException")
));
assertThat(exception.getMessage()).isEqualTo("org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper returned null");
try {
streamBridge.send("outputA-out-0", new CodecException("invalidException"));
}
catch (RuntimeException exception) {
assertThat(exception.getMessage()).isEqualTo("org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper returned null");
}
}
}