Skip to content

Commit

Permalink
Fix deprecation warnings
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
artembilan committed Jan 12, 2024
1 parent f27a641 commit 40d4150
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 63 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ configure(javaProjects) { subproject ->
reports.junitXml.required = false

enableAssertions = false

forkEvery = 1000
}

checkstyle {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -133,7 +134,7 @@ void messagesArePartitionedByCorrelationId() {

assertThat(receive).isNotNull()
.extracting(Message::getPayload)
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSize(5);

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;

Expand All @@ -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 {

Expand Down Expand Up @@ -167,7 +168,7 @@ public void testSplitterDiscard() {
.isInstanceOf(ArrayNode.class)
.extracting(new String[] {"_children"})
.element(0)
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSize(0);
}

Expand Down Expand Up @@ -207,7 +208,7 @@ public void testFluxAggregator() {
public static class ContextConfiguration {

@Bean
public TestSplitterPojo testSplitterData() {
TestSplitterPojo testSplitterData() {
List<String> first = new ArrayList<>();
first.add("1,2,3");
first.add("4,5,6");
Expand Down Expand Up @@ -324,26 +325,7 @@ public IntegrationFlow releaseBarrierFlow(MessageTriggerAction barrierTriggerAct

}

private static final class TestSplitterPojo {

final List<String> first;

final List<String> second;

TestSplitterPojo(List<String> first, List<String> second) {
this.first = first;
this.second = second;
}

@SuppressWarnings("unused")
public List<String> getFirst() {
return first;
}

@SuppressWarnings("unused")
public List<String> getSecond() {
return second;
}
record TestSplitterPojo(List<String> first, List<String> second) {

@SuppressWarnings("unused")
public List<List<String>> buildList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -39,8 +36,7 @@
*
* @since 4.1
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class ScatterGatherTests {

Expand All @@ -66,8 +62,7 @@ public void testAuction() {
assertThat(bestQuoteMessage)
.isNotNull()
.extracting(Message::getPayload)
.isInstanceOf(List.class)
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSizeGreaterThanOrEqualTo(1);
}

Expand All @@ -78,8 +73,7 @@ public void testDistribution() {
assertThat(bestQuoteMessage)
.isNotNull()
.extracting(Message::getPayload)
.isInstanceOf(List.class)
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSizeGreaterThanOrEqualTo(1);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 40d4150

Please sign in to comment.