Skip to content

Commit 587693f

Browse files
mjd507artembilan
andauthored
Migrate spring-integration-core tests from Junit 4 to Junit Jupiter
* Remove redundant assert from lambda in test Signed-off-by: Jiandong Ma <[email protected]> Signed-off-by: Artem Bilan <[email protected]> Co-authored-by: Artem Bilan <[email protected]>
1 parent 2467370 commit 587693f

File tree

112 files changed

+583
-612
lines changed

Some content is hidden

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

112 files changed

+583
-612
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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
import java.util.List;
2323
import java.util.Map;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

2828
import org.springframework.beans.DirectFieldAccessor;
2929
import org.springframework.beans.factory.BeanFactory;
@@ -52,7 +52,7 @@ public class AggregatingMessageGroupProcessorHeaderTests {
5252
private final MethodInvokingMessageGroupProcessor methodInvokingProcessor =
5353
new MethodInvokingMessageGroupProcessor(new TestAggregatorBean(), "aggregate");
5454

55-
@Before
55+
@BeforeEach
5656
public void setup() {
5757
this.defaultProcessor.setBeanFactory(mock(BeanFactory.class));
5858
this.methodInvokingProcessor.setBeanFactory(mock(BeanFactory.class));

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

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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,12 +22,11 @@
2222
import java.util.concurrent.ExecutorService;
2323
import java.util.concurrent.Executors;
2424
import java.util.concurrent.Semaphore;
25+
import java.util.concurrent.TimeUnit;
2526

26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
29-
import org.mockito.Mock;
30-
import org.mockito.junit.MockitoJUnitRunner;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.Timeout;
3130

3231
import org.springframework.integration.store.MessageGroup;
3332
import org.springframework.integration.support.MessageBuilder;
@@ -36,25 +35,23 @@
3635

3736
import static org.assertj.core.api.Assertions.assertThat;
3837
import static org.mockito.ArgumentMatchers.isA;
38+
import static org.mockito.Mockito.mock;
3939
import static org.mockito.Mockito.verify;
4040
import static org.mockito.Mockito.when;
4141

4242
/**
4343
* @author Iwein Fuld
4444
* @author Gary Russell
4545
*/
46-
@RunWith(MockitoJUnitRunner.class)
4746
public class CorrelatingMessageBarrierTests {
4847

4948
private CorrelatingMessageBarrier barrier;
5049

51-
@Mock
52-
private CorrelationStrategy correlationStrategy;
50+
private final CorrelationStrategy correlationStrategy = mock();
5351

54-
@Mock
55-
private ReleaseStrategy releaseStrategy;
52+
private final ReleaseStrategy releaseStrategy = mock();
5653

57-
@Before
54+
@BeforeEach
5855
public void initializeBarrier() {
5956
barrier = new CorrelatingMessageBarrier();
6057
barrier.setCorrelationStrategy(correlationStrategy);
@@ -83,7 +80,8 @@ public void shouldRemoveKeyWithoutLockingOnEmptyQueue() throws InterruptedExcept
8380
assertThat(barrier.receive()).isNull();
8481
}
8582

86-
@Test(timeout = 10000)
83+
@Test
84+
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
8785
public void shouldNotDropMessageOrBlockSendingThread() {
8886
OneMessagePerKeyReleaseStrategy trackingReleaseStrategy = new OneMessagePerKeyReleaseStrategy();
8987
barrier.setReleaseStrategy(trackingReleaseStrategy);

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.integration.aggregator;
1818

19-
import org.junit.Before;
20-
import org.junit.Test;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.beans.factory.BeanFactory;
2323
import org.springframework.integration.store.MessageGroupStore;
@@ -49,7 +49,7 @@ public class CorrelatingMessageHandlerIntegrationTests {
4949

5050
private final AggregatingMessageHandler defaultHandler = new AggregatingMessageHandler(processor, store);
5151

52-
@Before
52+
@BeforeEach
5353
public void setupHandler() {
5454
when(outputChannel.send(isA(Message.class))).thenReturn(true);
5555
defaultHandler.setOutputChannel(outputChannel);

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.integration.aggregator;
1818

19-
import org.junit.Before;
20-
import org.junit.Test;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.beans.factory.BeanFactory;
2323
import org.springframework.integration.support.MessageBuilder;
@@ -37,7 +37,7 @@ public class CorrelationStrategyAdapterTests {
3737

3838
private Message<?> message;
3939

40-
@Before
40+
@BeforeEach
4141
public void init() {
4242
message = MessageBuilder.withPayload("foo").setHeader("a", "b").setHeader("c", "d").build();
4343
}

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.integration.aggregator;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.beans.factory.BeanFactory;
2222
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -31,6 +31,7 @@
3131
import org.springframework.messaging.support.GenericMessage;
3232

3333
import static org.assertj.core.api.Assertions.assertThat;
34+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3435
import static org.mockito.Mockito.mock;
3536

3637
/**
@@ -43,15 +44,17 @@ public class ExpressionEvaluatingCorrelationStrategyTests {
4344

4445
private ExpressionEvaluatingCorrelationStrategy strategy;
4546

46-
@Test(expected = IllegalArgumentException.class)
47-
public void testCreateInstanceWithEmptyExpressionFails() throws Exception {
48-
strategy = new ExpressionEvaluatingCorrelationStrategy("");
47+
@Test
48+
public void testCreateInstanceWithEmptyExpressionFails() {
49+
assertThatThrownBy(() -> strategy = new ExpressionEvaluatingCorrelationStrategy(""))
50+
.isInstanceOf(IllegalArgumentException.class);
4951
}
5052

51-
@Test(expected = IllegalArgumentException.class)
52-
public void testCreateInstanceWithNullExpressionFails() throws Exception {
53+
@Test
54+
public void testCreateInstanceWithNullExpressionFails() {
5355
Expression nullExpression = null;
54-
strategy = new ExpressionEvaluatingCorrelationStrategy(nullExpression);
56+
assertThatThrownBy(() -> strategy = new ExpressionEvaluatingCorrelationStrategy(nullExpression))
57+
.isInstanceOf(IllegalArgumentException.class);
5558
}
5659

5760
@Test

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

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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,11 +20,8 @@
2020
import java.util.Collection;
2121
import java.util.List;
2222

23-
import org.junit.Before;
24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
26-
import org.mockito.Mock;
27-
import org.mockito.junit.MockitoJUnitRunner;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2825

2926
import org.springframework.beans.factory.BeanFactory;
3027
import org.springframework.integration.store.MessageGroup;
@@ -42,17 +39,15 @@
4239
* @author Gary Russell
4340
* @author Artem Bilan
4441
*/
45-
@RunWith(MockitoJUnitRunner.class)
4642
public class ExpressionEvaluatingMessageGroupProcessorTests {
4743

4844
private ExpressionEvaluatingMessageGroupProcessor processor;
4945

50-
@Mock
51-
private MessageGroup group;
46+
private final MessageGroup group = mock();
5247

5348
private final List<Message<?>> messages = new ArrayList<>();
5449

55-
@Before
50+
@BeforeEach
5651
public void setup() {
5752
messages.clear();
5853
for (int i = 0; i < 5; i++) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.integration.aggregator;
1818

19-
import org.junit.Before;
20-
import org.junit.Test;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.beans.factory.BeanFactory;
2323
import org.springframework.integration.store.SimpleMessageGroup;
@@ -39,7 +39,7 @@ public class ExpressionEvaluatingReleaseStrategyTests {
3939

4040
private final SimpleMessageGroup messages = new SimpleMessageGroup("foo");
4141

42-
@Before
42+
@BeforeEach
4343
@SuppressWarnings({"unchecked", "rawtypes"})
4444
public void setup() {
4545
for (int i = 0; i < 5; i++) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.integration.aggregator;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.integration.support.MessageBuilder;
2222
import org.springframework.messaging.Message;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -18,7 +18,7 @@
1818

1919
import java.util.Comparator;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.springframework.integration.support.MessageBuilder;
2424
import org.springframework.messaging.Message;

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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,11 +23,8 @@
2323
import java.util.List;
2424
import java.util.Map;
2525

26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
29-
import org.mockito.Mock;
30-
import org.mockito.junit.MockitoJUnitRunner;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
3128

3229
import org.springframework.aop.framework.ProxyFactory;
3330
import org.springframework.beans.factory.BeanFactory;
@@ -49,6 +46,8 @@
4946
import org.springframework.messaging.support.GenericMessage;
5047

5148
import static org.assertj.core.api.Assertions.assertThat;
49+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
50+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
5251
import static org.assertj.core.api.Assertions.fail;
5352
import static org.mockito.Mockito.mock;
5453
import static org.mockito.Mockito.when;
@@ -62,15 +61,13 @@
6261
* @author Gary Russell
6362
* @author Artem Bilan
6463
*/
65-
@RunWith(MockitoJUnitRunner.class)
6664
public class MethodInvokingMessageGroupProcessorTests {
6765

6866
private final List<Message<?>> messagesUpForProcessing = new ArrayList<>(3);
6967

70-
@Mock
71-
private MessageGroup messageGroupMock;
68+
private final MessageGroup messageGroupMock = mock();
7269

73-
@Before
70+
@BeforeEach
7471
public void initializeMessagesUpForProcessing() {
7572
this.messagesUpForProcessing.add(MessageBuilder.withPayload(1).build());
7673
this.messagesUpForProcessing.add(MessageBuilder.withPayload(2).build());
@@ -488,7 +485,7 @@ public String method1(List<String> input, @Headers Map<String, ?> map) {
488485
assertThat(aggregator.aggregatePayloads(group, aggregator.aggregateHeaders(group))).isEqualTo("foobar");
489486
}
490487

491-
@Test(expected = IllegalArgumentException.class)
488+
@Test
492489
public void multipleAnnotations() {
493490

494491
class MultipleAnnotationTestBean {
@@ -506,7 +503,8 @@ public String method2(List<String> input) {
506503
}
507504

508505
MultipleAnnotationTestBean bean = new MultipleAnnotationTestBean();
509-
new MethodInvokingMessageGroupProcessor(bean);
506+
assertThatIllegalArgumentException()
507+
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
510508
}
511509

512510
@Test
@@ -534,7 +532,7 @@ String method2(List<String> input) {
534532
assertThat(aggregator.aggregatePayloads(group, null)).isEqualTo("foo");
535533
}
536534

537-
@Test(expected = IllegalArgumentException.class)
535+
@Test
538536
public void multiplePublicMethods() {
539537

540538
@SuppressWarnings("unused")
@@ -551,10 +549,11 @@ public String lowerCase(String s) {
551549
}
552550

553551
MultiplePublicMethodTestBean bean = new MultiplePublicMethodTestBean();
554-
new MethodInvokingMessageGroupProcessor(bean);
552+
assertThatIllegalArgumentException()
553+
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
555554
}
556555

557-
@Test(expected = IllegalStateException.class)
556+
@Test
558557
public void noPublicMethods() {
559558

560559
@SuppressWarnings("unused")
@@ -567,7 +566,8 @@ String lowerCase(String s) {
567566
}
568567

569568
NoPublicMethodTestBean bean = new NoPublicMethodTestBean();
570-
new MethodInvokingMessageGroupProcessor(bean);
569+
assertThatIllegalStateException()
570+
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
571571
}
572572

573573
@Test

0 commit comments

Comments
 (0)