From 40d4150dae0281bf8007f77586644261044fd227 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 12 Jan 2024 12:38:33 -0500 Subject: [PATCH] Fix deprecation warnings * Remove `forkEvery = 1000` since where the build fails there is no way find the reason * Rework affected test classes to use JUnit 5 API * Use Java text block for JSON snippets in the test --- build.gradle | 2 -- .../FluxAggregatorMessageHandlerTests.java | 9 +++-- ...aultMessageAggregatorIntegrationTests.java | 8 ++--- .../channel/PartitionedChannelTests.java | 5 +-- .../correlation/CorrelationHandlerTests.java | 36 +++++-------------- .../json/JsonToObjectTransformerTests.java | 34 ++++++++++++++---- .../config/ScatterGatherTests.java | 26 +++++--------- 7 files changed, 57 insertions(+), 63 deletions(-) diff --git a/build.gradle b/build.gradle index 174725ad4b0..4fa265ba25b 100644 --- a/build.gradle +++ b/build.gradle @@ -345,8 +345,6 @@ configure(javaProjects) { subproject -> reports.junitXml.required = false enableAssertions = false - - forkEvery = 1000 } checkstyle { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandlerTests.java index 83316561cda..4907c88f85e 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * Copyright 2019-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. @@ -23,6 +23,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; import reactor.core.publisher.Flux; @@ -132,8 +133,7 @@ void testCustomCombineFunction() { Object payload = result.getPayload(); assertThat(payload) - .isInstanceOf(List.class) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .containsExactly( IntStream.iterate(0, i -> i + 2) .limit(10) @@ -145,8 +145,7 @@ void testCustomCombineFunction() { payload = result.getPayload(); assertThat(payload) - .isInstanceOf(List.class) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .containsExactly( IntStream.iterate(1, i -> i + 2) .limit(10) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java index a714f3cc47b..a8bc3274e65 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -17,8 +17,8 @@ package org.springframework.integration.aggregator.integration; import java.util.Arrays; -import java.util.List; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -56,8 +56,8 @@ public void testAggregation() { this.input.send(prepareSequenceMessage(i, 5, 1)); } Object payload = this.output.receive(20_000).getPayload(); - assertThat(payload).isInstanceOf(List.class) - .asList() + assertThat(payload) + .asInstanceOf(InstanceOfAssertFactories.LIST) .containsAll(Arrays.asList(0, 1, 2, 3, 4)); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/PartitionedChannelTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/PartitionedChannelTests.java index 77c2471952e..6aed78cf8ef 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/PartitionedChannelTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/PartitionedChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 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. @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; @@ -133,7 +134,7 @@ void messagesArePartitionedByCorrelationId() { assertThat(receive).isNotNull() .extracting(Message::getPayload) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .hasSize(5); @SuppressWarnings("unchecked") diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java index 8b63145d1bd..534c448bd59 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 the original author or authors. + * Copyright 2016-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. @@ -25,8 +25,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.TextNode; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -53,16 +53,17 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Artem Bilan * @author Gary Russell + * * @since 5.0 */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class CorrelationHandlerTests { @@ -167,7 +168,7 @@ public void testSplitterDiscard() { .isInstanceOf(ArrayNode.class) .extracting(new String[] {"_children"}) .element(0) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .hasSize(0); } @@ -207,7 +208,7 @@ public void testFluxAggregator() { public static class ContextConfiguration { @Bean - public TestSplitterPojo testSplitterData() { + TestSplitterPojo testSplitterData() { List first = new ArrayList<>(); first.add("1,2,3"); first.add("4,5,6"); @@ -324,26 +325,7 @@ public IntegrationFlow releaseBarrierFlow(MessageTriggerAction barrierTriggerAct } - private static final class TestSplitterPojo { - - final List first; - - final List second; - - TestSplitterPojo(List first, List second) { - this.first = first; - this.second = second; - } - - @SuppressWarnings("unused") - public List getFirst() { - return first; - } - - @SuppressWarnings("unused") - public List getSecond() { - return second; - } + record TestSplitterPojo(List first, List second) { @SuppressWarnings("unused") public List> buildList() { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerTests.java index 2050949d111..73c1634dc9c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; import org.springframework.core.ParameterizedTypeReference; @@ -49,13 +50,24 @@ public void objectPayload() { // Since DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES is disabled by default // (see Jackson2JsonObjectMapper) // the extra "foo" property is ignored. - String jsonString = "[{\"firstName\":\"John\",\"lastName\":\"Doe\",\"age\":42," + - "\"address\":{\"number\":123,\"street\":\"Main Street\"}, \"foo\":\"bar\"}]"; + // language=JSON + String jsonString = """ + [ + { + "firstName": "John", + "lastName": "Doe", + "age": 42, + "address": { + "number": 123, + "street": "Main Street" + }, + "foo": "bar" + } + ]"""; Message message = transformer.transform(new GenericMessage<>(jsonString)); assertThat(message) .extracting(Message::getPayload) - .isInstanceOf(List.class) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .hasSize(1) .element(0) .isInstanceOf(TestPerson.class) @@ -75,7 +87,17 @@ public void objectPayloadWithCustomMapper() { customMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, Boolean.TRUE); JsonToObjectTransformer transformer = new JsonToObjectTransformer(new Jackson2JsonObjectMapper(customMapper)); transformer.setValueTypeExpression(new ValueExpression<>(ResolvableType.forClass(TestPerson.class))); - String jsonString = "{firstName:'John', lastName:'Doe', age:42, address:{number:123, street:'Main Street'}}"; + // language=JSON + String jsonString = """ + { + "firstName": "John", + "lastName": "Doe", + "age": 42, + "address": { + "number": 123, + "street": "Main Street" + } + }"""; Message message = transformer.transform(new GenericMessage<>(jsonString)); TestPerson person = (TestPerson) message.getPayload(); assertThat(person.getFirstName()).isEqualTo("John"); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java index b80b307bf04..5c7bb4686bc 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-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. @@ -16,10 +16,8 @@ package org.springframework.integration.scattergather.config; -import java.util.List; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.gateway.RequestReplyExchanger; @@ -28,8 +26,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -39,8 +36,7 @@ * * @since 4.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class ScatterGatherTests { @@ -66,8 +62,7 @@ public void testAuction() { assertThat(bestQuoteMessage) .isNotNull() .extracting(Message::getPayload) - .isInstanceOf(List.class) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .hasSizeGreaterThanOrEqualTo(1); } @@ -78,8 +73,7 @@ public void testDistribution() { assertThat(bestQuoteMessage) .isNotNull() .extracting(Message::getPayload) - .isInstanceOf(List.class) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .hasSizeGreaterThanOrEqualTo(1); } @@ -89,16 +83,14 @@ public void testGatewayScatterGather() { assertThat(bestQuoteMessage) .isNotNull() .extracting(Message::getPayload) - .isInstanceOf(List.class) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .hasSizeGreaterThanOrEqualTo(1); bestQuoteMessage = this.gateway.exchange(new GenericMessage<>("bar")); assertThat(bestQuoteMessage) .isNotNull() .extracting(Message::getPayload) - .isInstanceOf(List.class) - .asList() + .asInstanceOf(InstanceOfAssertFactories.LIST) .hasSizeGreaterThanOrEqualTo(1); }