From dcaa621b3c72bfcce2423622a0e272513cb463c5 Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Fri, 11 Mar 2022 12:27:47 -0500 Subject: [PATCH] JUnit 5 migration for core tests --- .../binder/tck/ContentTypeTckTests.java | 10 +- .../stream/binder/tck/ErrorHandlingTests.java | 6 +- .../stream/binding/BindingLifecycleTests.java | 4 +- .../stream/binding/BindingServiceTests.java | 4 +- .../CustomPartitionedProducerTest.java | 4 +- .../MessageConverterConfigurerTests.java | 8 +- .../stream/config/ArgumentResolversTests.java | 4 +- .../stream/config/BinderPropertiesTests.java | 8 +- .../config/BindingHandlerAdviseTests.java | 20 ++-- .../BindingServiceConfigurationTests.java | 4 +- .../stream/config/RetryTemplateTests.java | 2 +- ...ExpressionConverterConfigurationTests.java | 8 +- .../DynamicDestinationFunctionTests.java | 14 +-- .../function/FunctionBatchingTests.java | 4 +- .../GreenfieldFunctionEnableBindingTests.java | 4 +- .../ImplicitFunctionBindingTests.java | 2 +- .../MultipleInputOutputFunctionTests.java | 96 +++++++++---------- .../stream/function/RoutingFunctionTests.java | 10 +- .../stream/function/StreamBridgeTests.java | 29 +++--- .../stream/function/edgecases/GH1801Test.java | 4 +- .../partitioning/PartitionedConsumerTest.java | 8 +- 21 files changed, 122 insertions(+), 131 deletions(-) diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java index e8fdce5fb..3925b8fda 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2022 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,8 +22,8 @@ import java.util.List; import java.util.Map; import java.util.function.Function; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -426,7 +426,7 @@ public class ContentTypeTckTests { } @Test - @Ignore + @Disabled public void _toStringDefaultContentTypePropertyUnknownContentType() { ApplicationContext context = new SpringApplicationBuilder( StringToStringConfiguration.class).web(WebApplicationType.NONE).run( @@ -498,7 +498,7 @@ public class ContentTypeTckTests { } @Test - @Ignore // TODO fix it. We can recognize MessageHeaders and parse it out of the message properly + @Disabled // TODO fix it. We can recognize MessageHeaders and parse it out of the message properly public void testWithMessageHeadersInputParameter() { ApplicationContext context = new SpringApplicationBuilder( MessageHeadersInputConfiguration.class).web(WebApplicationType.NONE) diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ErrorHandlingTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ErrorHandlingTests.java index 5a6ffa701..2726fe667 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ErrorHandlingTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ErrorHandlingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2019 the original author or authors. + * Copyright 2019-2022 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. @@ -18,7 +18,7 @@ package org.springframework.cloud.stream.binder.tck; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -34,8 +34,6 @@ import org.springframework.messaging.support.GenericMessage; import static org.assertj.core.api.Assertions.assertThat; - - /** * @author Oleg Zhurakousky * diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingLifecycleTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingLifecycleTests.java index 2976a0a25..67e256e8a 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingLifecycleTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingLifecycleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2022 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,7 +21,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.cloud.stream.binder.Binding; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java index 2ca4cb74c..5752b1b5a 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2022 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. @@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java index 271b04fa1..9ba2d9678 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2022 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. @@ -18,7 +18,7 @@ package org.springframework.cloud.stream.binding; import java.lang.reflect.Field; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/MessageConverterConfigurerTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/MessageConverterConfigurerTests.java index 561976a41..fac0f76e9 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/MessageConverterConfigurerTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/MessageConverterConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2022 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. @@ -18,8 +18,8 @@ package org.springframework.cloud.stream.binding; import java.util.Collections; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.cloud.stream.config.BindingProperties; import org.springframework.cloud.stream.config.BindingServiceProperties; @@ -64,7 +64,7 @@ public class MessageConverterConfigurerTests { } @Test - @Ignore + @Disabled public void testConfigureOutputChannelCannotConvert() { BindingServiceProperties props = new BindingServiceProperties(); BindingProperties bindingProps = new BindingProperties(); diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/ArgumentResolversTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/ArgumentResolversTests.java index fec048fba..45742fc45 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/ArgumentResolversTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/ArgumentResolversTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2019 the original author or authors. + * Copyright 2019-2022 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. @@ -20,7 +20,7 @@ import java.lang.reflect.Method; import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.messaging.Message; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BinderPropertiesTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BinderPropertiesTests.java index bd791ae27..e8286f187 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BinderPropertiesTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BinderPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2022 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. @@ -20,8 +20,8 @@ import java.util.Collections; import java.util.Map; import java.util.Properties; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint; @@ -42,7 +42,7 @@ public class BinderPropertiesTests { @SuppressWarnings("unchecked") @Test - @Ignore + @Disabled public void testSerializationWithNonStringValues() { StaticApplicationContext context = new StaticApplicationContext(); DefaultListableBeanFactory bf = (DefaultListableBeanFactory) context diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingHandlerAdviseTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingHandlerAdviseTests.java index bb9cf2dcc..3cb3a6d78 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingHandlerAdviseTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingHandlerAdviseTests.java @@ -21,7 +21,7 @@ import java.util.function.Function; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.WebApplicationType; @@ -36,7 +36,7 @@ import org.springframework.context.annotation.Import; import org.springframework.validation.annotation.Validated; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; // see https://github.com/spring-cloud/spring-cloud-stream/issues/1573 for more details /** @@ -46,10 +46,11 @@ import static org.junit.jupiter.api.Assertions.fail; */ public class BindingHandlerAdviseTests { - @Test(expected = BeanCreationException.class) + @Test public void testFailureWithWrongValue() { - new SpringApplicationBuilder(SampleConfiguration.class).web(WebApplicationType.NONE).run("--props.value=-1", - "--spring.jmx.enabled=false"); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new SpringApplicationBuilder(SampleConfiguration.class).web(WebApplicationType.NONE).run("--props.value=-1", + "--spring.jmx.enabled=false")); } @Test @@ -67,12 +68,11 @@ public class BindingHandlerAdviseTests { // simply should not fail } - @Test(expected = ConfigurationPropertiesBindException.class) + @Test public void validatedConfigProperties() { - new SpringApplicationBuilder(ValidatedConfiguration.class).web(WebApplicationType.NONE) - .run("--spring.jmx.enabled=false"); - - fail(); + assertThatExceptionOfType(ConfigurationPropertiesBindException.class) + .isThrownBy(() -> new SpringApplicationBuilder(ValidatedConfiguration.class).web(WebApplicationType.NONE) + .run("--spring.jmx.enabled=false")); } @Import(TestChannelBinderConfiguration.class) diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingServiceConfigurationTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingServiceConfigurationTests.java index 79a4fcb02..ae8b533da 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingServiceConfigurationTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/BindingServiceConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2022 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. @@ -19,7 +19,7 @@ package org.springframework.cloud.stream.config; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/RetryTemplateTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/RetryTemplateTests.java index faea2f40b..02ea3ace6 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/RetryTemplateTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/RetryTemplateTests.java @@ -21,7 +21,7 @@ import java.lang.reflect.Method; import java.util.Map; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java index 38b982fdd..c9ef390fd 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java @@ -20,8 +20,8 @@ import java.util.List; import javax.annotation.PostConstruct; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; @@ -39,7 +39,7 @@ import org.springframework.expression.PropertyAccessor; import org.springframework.integration.expression.ExpressionUtils; import org.springframework.integration.json.JsonPropertyAccessor; import org.springframework.integration.test.util.TestUtils; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan * @author Soby Chacko */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = SpelExpressionConverterConfigurationTests.Config.class, properties = { "expression: a.b" }) public class SpelExpressionConverterConfigurationTests { diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/DynamicDestinationFunctionTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/DynamicDestinationFunctionTests.java index 9514a992d..3d333a93c 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/DynamicDestinationFunctionTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/DynamicDestinationFunctionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 the original author or authors. + * Copyright 2019-2022 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. @@ -16,9 +16,9 @@ package org.springframework.cloud.stream.function; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.stream.binder.PartitionKeyExtractorStrategy; @@ -42,14 +42,14 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class DynamicDestinationFunctionTests { - @After - public void after() { + @AfterAll + public static void after() { System.clearProperty("spring.cloud.stream.function.definition"); System.clearProperty("spring.cloud.function.definition"); } @Test - @Ignore + @Disabled public void testEmptyConfiguration() { TestChannelBinderConfiguration.applicationContextRunner(SampleConfiguration.class) .withPropertyValues( diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/FunctionBatchingTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/FunctionBatchingTests.java index d0284fb06..d75ac1d4c 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/FunctionBatchingTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/FunctionBatchingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 the original author or authors. + * Copyright 2019-2022 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,7 +21,7 @@ import java.util.List; import java.util.function.Function; import org.assertj.core.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.stream.binder.test.InputDestination; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/GreenfieldFunctionEnableBindingTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/GreenfieldFunctionEnableBindingTests.java index 581e65814..4d2cb3210 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/GreenfieldFunctionEnableBindingTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/GreenfieldFunctionEnableBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2022 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,7 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/ImplicitFunctionBindingTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/ImplicitFunctionBindingTests.java index fd141486a..810459322 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/ImplicitFunctionBindingTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/ImplicitFunctionBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 the original author or authors. + * Copyright 2019-2022 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. diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/MultipleInputOutputFunctionTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/MultipleInputOutputFunctionTests.java index 80bff1bfb..f123d22d3 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/MultipleInputOutputFunctionTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/MultipleInputOutputFunctionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2019 the original author or authors. + * Copyright 2019-2022 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,7 +21,7 @@ import java.time.Duration; import java.util.function.Consumer; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.UnicastProcessor; import reactor.util.function.Tuple2; @@ -45,7 +45,7 @@ import org.springframework.messaging.converter.MessageConverter; import org.springframework.util.MimeType; import static org.assertj.core.api.Assertions.assertThat; - +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @@ -54,76 +54,70 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class MultipleInputOutputFunctionTests { - @Test(expected = BeanCreationException.class) + @Test public void testFailureWithNonReactiveFunction() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder( + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( - ReactiveFunctionConfiguration.class)) - .web(WebApplicationType.NONE) - .run("--spring.jmx.enabled=false", - "--spring.cloud.function.definition=multipleInputNonReactive")) { - context.getBean(InputDestination.class); - } + ReactiveFunctionConfiguration.class)) + .web(WebApplicationType.NONE) + .run("--spring.jmx.enabled=false", + "--spring.cloud.function.definition=multipleInputNonReactive")); } - @Test(expected = BeanCreationException.class) + @Test public void testFailureWithReactiveArrayOutput() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder( + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( - ReactiveFunctionConfiguration.class)) - .web(WebApplicationType.NONE) - .run("--spring.jmx.enabled=false", - "--spring.cloud.function.definition=multiReactiveInputReactiveArrayOutput")) { - context.getBean(InputDestination.class); - } + ReactiveFunctionConfiguration.class)) + .web(WebApplicationType.NONE) + .run("--spring.jmx.enabled=false", + "--spring.cloud.function.definition=multiReactiveInputReactiveArrayOutput")); } - @Test(expected = BeanCreationException.class) + @Test public void testFailureWithReactiveArrayOutputNonGeneric() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder( + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( - ReactiveFunctionConfiguration.class)) - .web(WebApplicationType.NONE) - .run("--spring.jmx.enabled=false", - "--spring.cloud.function.definition=multiReactiveInputReactiveArrayOutputNoGeneric")) { - context.getBean(InputDestination.class); - } + ReactiveFunctionConfiguration.class)) + .web(WebApplicationType.NONE) + .run("--spring.jmx.enabled=false", + "--spring.cloud.function.definition=multiReactiveInputReactiveArrayOutputNoGeneric")); } - @Test(expected = BeanCreationException.class) + @Test public void testFailureWithReactiveArrayInput() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder( + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( - ReactiveFunctionConfiguration.class)) - .web(WebApplicationType.NONE) - .run("--spring.jmx.enabled=false", - "--spring.cloud.function.definition=genericReactiveArrayInput")) { - context.getBean(InputDestination.class); - } + ReactiveFunctionConfiguration.class)) + .web(WebApplicationType.NONE) + .run("--spring.jmx.enabled=false", + "--spring.cloud.function.definition=genericReactiveArrayInput")); } - @Test(expected = BeanCreationException.class) + @Test public void testFailureWithReactiveArrayInputNonGeneric() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder( + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( - ReactiveFunctionConfiguration.class)) - .web(WebApplicationType.NONE) - .run("--spring.jmx.enabled=false", - "--spring.cloud.function.definition=nonGenericReactiveArrayInput")) { - context.getBean(InputDestination.class); - } + ReactiveFunctionConfiguration.class)) + .web(WebApplicationType.NONE) + .run("--spring.jmx.enabled=false", + "--spring.cloud.function.definition=nonGenericReactiveArrayInput")); } - @Test(expected = BeanCreationException.class) + @Test public void testFailureWithConsumer() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder( + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( - ReactiveFunctionConfiguration.class)) - .web(WebApplicationType.NONE) - .run("--spring.jmx.enabled=false", - "--spring.cloud.function.definition=multiInputConsumer")) { - context.getBean(InputDestination.class); - } + ReactiveFunctionConfiguration.class)) + .web(WebApplicationType.NONE) + .run("--spring.jmx.enabled=false", + "--spring.cloud.function.definition=multiInputConsumer")); } @Test diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/RoutingFunctionTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/RoutingFunctionTests.java index ef2ff54d1..b5126de95 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/RoutingFunctionTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/RoutingFunctionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2019 the original author or authors. + * Copyright 2019-2022 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,8 +21,8 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.Function; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import org.springframework.boot.WebApplicationType; @@ -53,8 +53,8 @@ import static org.assertj.core.api.Assertions.assertThat; public class RoutingFunctionTests { - @Before - public void before() { + @BeforeAll + public static void before() { System.getProperties().remove("spring.cloud.function.routing.enabled"); System.getProperties().remove("spring.cloud.stream.function.definition"); System.getProperties().remove("spring.cloud.function.definition"); diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java index 5e6801350..cfdef9a15 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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. @@ -27,8 +27,8 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.WebApplicationType; @@ -63,7 +63,7 @@ import org.springframework.util.MimeTypeUtils; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @@ -73,8 +73,8 @@ import static org.junit.Assert.fail; */ public class StreamBridgeTests { - @Before - public void before() { + @BeforeAll + public static void before() { System.clearProperty("spring.cloud.function.definition"); } @@ -285,16 +285,15 @@ public class StreamBridgeTests { } } - @Test(expected = NoSuchBeanDefinitionException.class) + @Test public void testNoBridgeIfNoSourcePropertyDefined() { - - try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration - .getCompleteConfiguration()) - .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) { - - context.getBean(StreamBridge.class); - fail(); - } + assertThatExceptionOfType(NoSuchBeanDefinitionException.class) + .isThrownBy(() -> { + ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration + .getCompleteConfiguration()) + .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false"); + context.getBean(StreamBridge.class); + }); } @Test diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java index 4ec03c009..2e2aaafe2 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2019 the original author or authors. + * Copyright 2019-2022 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. @@ -18,7 +18,7 @@ package org.springframework.cloud.stream.function.edgecases; import java.util.function.Consumer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java index 23426e318..d090a16ec 100644 --- a/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java +++ b/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java @@ -18,8 +18,8 @@ package org.springframework.cloud.stream.partitioning; import java.util.function.Consumer; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +34,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; import org.springframework.messaging.MessageChannel; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.eq; @@ -48,7 +48,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Janne Valkealahti * @author Soby Chacko */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = PartitionedConsumerTest.TestSink.class, properties = "spring.cloud.stream.default-binder=mock") public class PartitionedConsumerTest {