Skip to content

Commit 648aeb8

Browse files
committed
Unable ImportOrder Checkstyle rule for tests
* Fix wrong import order in tests * Polishing for not closed application contexts * Use diamonds * Use proper assertion operators * Remove redundant classes * Improve performance in JPA tests * Fix typos
1 parent 76c6700 commit 648aeb8

File tree

110 files changed

+1533
-1130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1533
-1130
lines changed

spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategyTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@
2424
import org.junit.Test;
2525

2626
import org.springframework.beans.factory.BeanFactory;
27-
import org.springframework.messaging.support.GenericMessage;
2827
import org.springframework.integration.store.SimpleMessageGroup;
28+
import org.springframework.messaging.support.GenericMessage;
2929

3030
/**
3131
* @author Alex Peters
@@ -49,21 +49,21 @@ public void setup() {
4949
}
5050

5151
@Test
52-
public void testCompletedWithSizeSpelEvaluated() throws Exception {
52+
public void testCompletedWithSizeSpelEvaluated() {
5353
strategy = new ExpressionEvaluatingReleaseStrategy("#root.size()==5");
5454
strategy.setBeanFactory(mock(BeanFactory.class));
5555
assertThat(strategy.canRelease(messages), is(true));
5656
}
5757

5858
@Test
59-
public void testCompletedWithFilterSpelEvaluated() throws Exception {
59+
public void testCompletedWithFilterSpelEvaluated() {
6060
strategy = new ExpressionEvaluatingReleaseStrategy("!messages.?[payload==5].empty");
6161
strategy.setBeanFactory(mock(BeanFactory.class));
6262
assertThat(strategy.canRelease(messages), is(true));
6363
}
6464

6565
@Test
66-
public void testCompletedWithFilterSpelReturnsNotCompleted() throws Exception {
66+
public void testCompletedWithFilterSpelReturnsNotCompleted() {
6767
strategy = new ExpressionEvaluatingReleaseStrategy("!messages.?[payload==6].empty");
6868
strategy.setBeanFactory(mock(BeanFactory.class));
6969
assertThat(strategy.canRelease(messages), is(false));

spring-integration-core/src/test/java/org/springframework/integration/aggregator/MessageSequenceComparatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@
2222

2323
import org.junit.Test;
2424

25-
import org.springframework.messaging.Message;
2625
import org.springframework.integration.support.MessageBuilder;
26+
import org.springframework.messaging.Message;
2727

2828
/**
2929
* @author Mark Fisher

spring-integration-core/src/test/java/org/springframework/integration/aggregator/SequenceSizeReleaseStrategyTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,14 +20,16 @@
2020
import static org.junit.Assert.assertTrue;
2121

2222
import org.junit.Test;
23-
import org.springframework.messaging.Message;
23+
2424
import org.springframework.integration.store.MessageGroup;
2525
import org.springframework.integration.store.SimpleMessageGroup;
2626
import org.springframework.integration.support.MessageBuilder;
27+
import org.springframework.messaging.Message;
2728

2829
/**
2930
* @author Mark Fisher
3031
* @author Iwein Fuld
32+
* @author Artem Bilan
3133
*/
3234
public class SequenceSizeReleaseStrategyTests {
3335

spring-integration-core/src/test/java/org/springframework/integration/aggregator/TimeoutCountSequenceSizeReleaseStrategyTests.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,12 +20,14 @@
2020
import static org.junit.Assert.assertTrue;
2121

2222
import org.junit.Test;
23-
import org.springframework.messaging.Message;
23+
2424
import org.springframework.integration.store.SimpleMessageGroup;
2525
import org.springframework.integration.support.MessageBuilder;
26+
import org.springframework.messaging.Message;
2627

2728
/**
2829
* @author Dave Syer
30+
* @author Artme Bilan
2931
*/
3032
public class TimeoutCountSequenceSizeReleaseStrategyTests {
3133

@@ -45,7 +47,9 @@ public void testIncompleteListWithTimeout() {
4547
.setSequenceSize(2).build();
4648
SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
4749
messages.add(message);
48-
TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = new TimeoutCountSequenceSizeReleaseStrategy(TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_THRESHOLD, -100);
50+
TimeoutCountSequenceSizeReleaseStrategy releaseStrategy =
51+
new TimeoutCountSequenceSizeReleaseStrategy(TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_THRESHOLD,
52+
-100);
4953
assertTrue(releaseStrategy.canRelease(messages));
5054
}
5155

@@ -55,7 +59,9 @@ public void testIncompleteListWithCount() {
5559
.setSequenceSize(2).build();
5660
SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
5761
messages.add(message);
58-
TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = new TimeoutCountSequenceSizeReleaseStrategy(1, TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_TIMEOUT);
62+
TimeoutCountSequenceSizeReleaseStrategy releaseStrategy =
63+
new TimeoutCountSequenceSizeReleaseStrategy(1,
64+
TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_TIMEOUT);
5965
assertTrue(releaseStrategy.canRelease(messages));
6066
}
6167

spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/AggregatorExpressionIntegrationTests.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,19 +23,21 @@
2323

2424
import org.junit.Test;
2525
import org.junit.runner.RunWith;
26+
2627
import org.springframework.beans.factory.annotation.Autowired;
2728
import org.springframework.beans.factory.annotation.Qualifier;
2829
import org.springframework.integration.IntegrationMessageHeaderAccessor;
29-
import org.springframework.messaging.support.GenericMessage;
3030
import org.springframework.messaging.MessageChannel;
3131
import org.springframework.messaging.PollableChannel;
32+
import org.springframework.messaging.support.GenericMessage;
3233
import org.springframework.test.context.ContextConfiguration;
3334
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3435

3536
/**
3637
* @author Iwein Fuld
3738
* @author Alex Peters
3839
* @author Oleg Zhurakousky
40+
* @author Artem Bilan
3941
*/
4042
@RunWith(SpringJUnit4ClassRunner.class)
4143
@ContextConfiguration
@@ -50,16 +52,16 @@ public class AggregatorExpressionIntegrationTests {
5052
private PollableChannel output;
5153

5254
@Test//(timeout=5000)
53-
public void testVanillaAggregation() throws Exception {
55+
public void testVanillaAggregation() {
5456
for (int i = 0; i < 5; i++) {
5557
Map<String, Object> headers = stubHeaders(i, 5, 1);
56-
input.send(new GenericMessage<Integer>(i, headers));
58+
this.input.send(new GenericMessage<>(i, headers));
5759
}
58-
assertEquals("[0, 1, 2, 3, 4]", output.receive().getPayload());
60+
assertEquals("[0, 1, 2, 3, 4]", this.output.receive().getPayload());
5961
}
6062

6163
private Map<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) {
62-
Map<String, Object> headers = new HashMap<String, Object>();
64+
Map<String, Object> headers = new HashMap<>();
6365
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber);
6466
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, sequenceSize);
6567
headers.put(IntegrationMessageHeaderAccessor.CORRELATION_ID, correllationId);

spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,19 +28,21 @@
2828

2929
import org.junit.Test;
3030
import org.junit.runner.RunWith;
31+
3132
import org.springframework.beans.factory.annotation.Autowired;
3233
import org.springframework.beans.factory.annotation.Qualifier;
3334
import org.springframework.integration.IntegrationMessageHeaderAccessor;
34-
import org.springframework.messaging.support.GenericMessage;
3535
import org.springframework.messaging.MessageChannel;
3636
import org.springframework.messaging.PollableChannel;
37+
import org.springframework.messaging.support.GenericMessage;
3738
import org.springframework.test.context.ContextConfiguration;
3839
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3940

4041
/**
4142
* @author Alex Peters
4243
* @author Iwein Fuld
4344
* @author Gunnar Hillert
45+
* @author Artem Bilan
4446
*/
4547
@RunWith(SpringJUnit4ClassRunner.class)
4648
@ContextConfiguration
@@ -56,20 +58,20 @@ public class DefaultMessageAggregatorIntegrationTests {
5658

5759
@SuppressWarnings({ "unchecked", "rawtypes" })
5860
@Test(timeout = 10000)
59-
public void testAggregation() throws Exception {
61+
public void testAggregation() {
6062
for (int i = 0; i < 5; i++) {
6163
Map<String, Object> headers = stubHeaders(i, 5, 1);
62-
input.send(new GenericMessage<Integer>(i, headers));
64+
this.input.send(new GenericMessage<>(i, headers));
6365
}
64-
Object payload = output.receive().getPayload();
66+
Object payload = this.output.receive().getPayload();
6567
assertThat(payload, is(instanceOf(List.class)));
6668
assertTrue(payload + " doesn't contain all of {0,1,2,3,4}",
6769
((List) payload).containsAll(Arrays.asList(0, 1, 2, 3, 4)));
6870
}
6971

7072

7173
private Map<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) {
72-
Map<String, Object> headers = new HashMap<String, Object>();
74+
Map<String, Object> headers = new HashMap<>();
7375
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber);
7476
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, sequenceSize);
7577
headers.put(IntegrationMessageHeaderAccessor.CORRELATION_ID, correllationId);

spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/MethodInvokingAggregatorReturningMessageTests.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,16 +23,18 @@
2323

2424
import org.junit.Test;
2525
import org.junit.runner.RunWith;
26+
2627
import org.springframework.beans.factory.annotation.Autowired;
27-
import org.springframework.messaging.Message;
2828
import org.springframework.integration.channel.DirectChannel;
29-
import org.springframework.messaging.PollableChannel;
3029
import org.springframework.integration.support.MessageBuilder;
30+
import org.springframework.messaging.Message;
31+
import org.springframework.messaging.PollableChannel;
3132
import org.springframework.test.context.ContextConfiguration;
3233
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3334

3435
/**
3536
* @author Mark Fisher
37+
* @author Artem Bilan
3638
*/
3739
@ContextConfiguration
3840
@RunWith(SpringJUnit4ClassRunner.class)
@@ -54,16 +56,16 @@ public class MethodInvokingAggregatorReturningMessageTests {
5456
@Test // INT-1107
5557
public void messageReturningPojoAggregatorResultIsNotWrappedInAnotherMessage() {
5658
List<String> payload = Collections.singletonList("test");
57-
pojoInput.send(MessageBuilder.withPayload(payload).build());
58-
Message<?> result = pojoOutput.receive();
59+
this.pojoInput.send(MessageBuilder.withPayload(payload).build());
60+
Message<?> result = this.pojoOutput.receive();
5961
assertFalse(Message.class.isAssignableFrom(result.getPayload().getClass()));
6062
}
6163

6264
@Test
6365
public void defaultAggregatorResultIsNotWrappedInAnotherMessage() {
6466
List<String> payload = Collections.singletonList("test");
65-
defaultInput.send(MessageBuilder.withPayload(payload).build());
66-
Message<?> result = defaultOutput.receive();
67+
this.defaultInput.send(MessageBuilder.withPayload(payload).build());
68+
Message<?> result = this.defaultOutput.receive();
6769
assertFalse(Message.class.isAssignableFrom(result.getPayload().getClass()));
6870
}
6971

@@ -75,6 +77,7 @@ public Message<?> aggregate(final List<Message<?>> messages) {
7577
List<String> payload = Collections.singletonList("foo");
7678
return MessageBuilder.withPayload(payload).setHeader("bar", 123).build();
7779
}
80+
7881
}
7982

8083
}

spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregationResendTests.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,16 +20,15 @@
2020
import java.util.List;
2121

2222
import org.junit.Assert;
23-
2423
import org.junit.Ignore;
2524
import org.junit.Test;
2625
import org.junit.runner.RunWith;
2726

2827
import org.springframework.beans.factory.annotation.Autowired;
29-
import org.springframework.messaging.Message;
3028
import org.springframework.integration.channel.DirectChannel;
3129
import org.springframework.integration.channel.QueueChannel;
3230
import org.springframework.integration.support.MessageBuilder;
31+
import org.springframework.messaging.Message;
3332
import org.springframework.test.context.ContextConfiguration;
3433
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3534

@@ -38,6 +37,7 @@
3837
*
3938
* @author Iwein Fuld
4039
* @author Gunnar Hillert
40+
* @author Artem Bilan
4141
*/
4242
@ContextConfiguration
4343
@RunWith(SpringJUnit4ClassRunner.class)
@@ -62,8 +62,8 @@ public class AggregationResendTests {
6262
*/
6363
@Test
6464
@Ignore // timeout is no longer supported
65-
public void testAggregatorWithoutExplicitTimeoutReturnsOnlyOneMessage() throws Exception {
66-
sendMessage(input_for_aggregator_with_explicit_timeout, 2000);
65+
public void testAggregatorWithoutExplicitTimeoutReturnsOnlyOneMessage() {
66+
sendMessage(this.input_for_aggregator_with_explicit_timeout, 2000);
6767
}
6868

6969
/**
@@ -76,17 +76,17 @@ public void testAggregatorWithoutExplicitTimeoutReturnsOnlyOneMessage() throws E
7676
*/
7777
@Test
7878
@Ignore // disabling from normal testing, should be the same behavior whether explicit or default
79-
public void testAggregatorWithTimeoutReturnsOnlyOneMessage() throws Exception {
80-
sendMessage(input_for_aggregator_without_explicit_timeout, 62000);
79+
public void testAggregatorWithTimeoutReturnsOnlyOneMessage() {
80+
sendMessage(this.input_for_aggregator_without_explicit_timeout, 62000);
8181
}
8282

8383
private void sendMessage(DirectChannel channel, int waitSeconds) {
84-
List<String> list = new ArrayList<String>();
84+
List<String> list = new ArrayList<>();
8585
list.add("foo");
8686
list.add("bar");
8787
list.add("baz");
8888

89-
reply.purge(null);
89+
this.reply.purge(null);
9090
channel.send(MessageBuilder.withPayload(list).setReplyChannel(reply).build());
9191

9292
Message<?> replyMessage;
@@ -96,8 +96,10 @@ private void sendMessage(DirectChannel channel, int waitSeconds) {
9696
if (null != replyMessage) {
9797
messageCount++;
9898
}
99-
} while (null != replyMessage);
99+
}
100+
while (null != replyMessage);
100101

101102
Assert.assertEquals(1, messageCount);
102103
}
104+
103105
}

0 commit comments

Comments
 (0)