Skip to content

Migrate spring-integration-core tests from Junit 4 to Junit Jupiter #10009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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 @@ -22,8 +22,8 @@
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;
Expand Down Expand Up @@ -52,7 +52,7 @@ public class AggregatingMessageGroupProcessorHeaderTests {
private final MethodInvokingMessageGroupProcessor methodInvokingProcessor =
new MethodInvokingMessageGroupProcessor(new TestAggregatorBean(), "aggregate");

@Before
@BeforeEach
public void setup() {
this.defaultProcessor.setBeanFactory(mock(BeanFactory.class));
this.methodInvokingProcessor.setBeanFactory(mock(BeanFactory.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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 @@ -22,12 +22,11 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.support.MessageBuilder;
Expand All @@ -36,25 +35,23 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* @author Iwein Fuld
* @author Gary Russell
*/
@RunWith(MockitoJUnitRunner.class)
public class CorrelatingMessageBarrierTests {

private CorrelatingMessageBarrier barrier;

@Mock
private CorrelationStrategy correlationStrategy;
private final CorrelationStrategy correlationStrategy = mock();

@Mock
private ReleaseStrategy releaseStrategy;
private final ReleaseStrategy releaseStrategy = mock();

@Before
@BeforeEach
public void initializeBarrier() {
barrier = new CorrelatingMessageBarrier();
barrier.setCorrelationStrategy(correlationStrategy);
Expand Down Expand Up @@ -83,7 +80,8 @@ public void shouldRemoveKeyWithoutLockingOnEmptyQueue() throws InterruptedExcept
assertThat(barrier.receive()).isNull();
}

@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void shouldNotDropMessageOrBlockSendingThread() {
OneMessagePerKeyReleaseStrategy trackingReleaseStrategy = new OneMessagePerKeyReleaseStrategy();
barrier.setReleaseStrategy(trackingReleaseStrategy);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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,8 +16,8 @@

package org.springframework.integration.aggregator;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.store.MessageGroupStore;
Expand Down Expand Up @@ -49,7 +49,7 @@ public class CorrelatingMessageHandlerIntegrationTests {

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

@Before
@BeforeEach
public void setupHandler() {
when(outputChannel.send(isA(Message.class))).thenReturn(true);
defaultHandler.setOutputChannel(outputChannel);
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-2025 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,8 +16,8 @@

package org.springframework.integration.aggregator;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

private Message<?> message;

@Before
@BeforeEach
public void init() {
message = MessageBuilder.withPayload("foo").setHeader("a", "b").setHeader("c", "d").build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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,7 +16,7 @@

package org.springframework.integration.aggregator;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
Expand All @@ -31,6 +31,7 @@
import org.springframework.messaging.support.GenericMessage;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;

/**
Expand All @@ -43,15 +44,17 @@ public class ExpressionEvaluatingCorrelationStrategyTests {

private ExpressionEvaluatingCorrelationStrategy strategy;

@Test(expected = IllegalArgumentException.class)
public void testCreateInstanceWithEmptyExpressionFails() throws Exception {
strategy = new ExpressionEvaluatingCorrelationStrategy("");
@Test
public void testCreateInstanceWithEmptyExpressionFails() {
assertThatThrownBy(() -> strategy = new ExpressionEvaluatingCorrelationStrategy(""))
.isInstanceOf(IllegalArgumentException.class);
}

@Test(expected = IllegalArgumentException.class)
public void testCreateInstanceWithNullExpressionFails() throws Exception {
@Test
public void testCreateInstanceWithNullExpressionFails() {
Expression nullExpression = null;
strategy = new ExpressionEvaluatingCorrelationStrategy(nullExpression);
assertThatThrownBy(() -> strategy = new ExpressionEvaluatingCorrelationStrategy(nullExpression))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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,11 +20,8 @@
import java.util.Collection;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.store.MessageGroup;
Expand All @@ -42,17 +39,15 @@
* @author Gary Russell
* @author Artem Bilan
*/
@RunWith(MockitoJUnitRunner.class)
public class ExpressionEvaluatingMessageGroupProcessorTests {

private ExpressionEvaluatingMessageGroupProcessor processor;

@Mock
private MessageGroup group;
private final MessageGroup group = mock();

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

@Before
@BeforeEach
public void setup() {
messages.clear();
for (int i = 0; i < 5; i++) {
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-2025 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,8 +16,8 @@

package org.springframework.integration.aggregator;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

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

@Before
@BeforeEach
@SuppressWarnings({"unchecked", "rawtypes"})
public void setup() {
for (int i = 0; i < 5; i++) {
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-2025 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,7 +16,7 @@

package org.springframework.integration.aggregator;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
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-2025 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 @@ -18,7 +18,7 @@

import java.util.Comparator;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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,11 +23,8 @@
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanFactory;
Expand All @@ -49,6 +46,8 @@
import org.springframework.messaging.support.GenericMessage;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -62,15 +61,13 @@
* @author Gary Russell
* @author Artem Bilan
*/
@RunWith(MockitoJUnitRunner.class)
public class MethodInvokingMessageGroupProcessorTests {

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

@Mock
private MessageGroup messageGroupMock;
private final MessageGroup messageGroupMock = mock();

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

@Test(expected = IllegalArgumentException.class)
@Test
public void multipleAnnotations() {

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

MultipleAnnotationTestBean bean = new MultipleAnnotationTestBean();
new MethodInvokingMessageGroupProcessor(bean);
assertThatIllegalArgumentException()
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
}

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

@Test(expected = IllegalArgumentException.class)
@Test
public void multiplePublicMethods() {

@SuppressWarnings("unused")
Expand All @@ -551,10 +549,11 @@ public String lowerCase(String s) {
}

MultiplePublicMethodTestBean bean = new MultiplePublicMethodTestBean();
new MethodInvokingMessageGroupProcessor(bean);
assertThatIllegalArgumentException()
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
}

@Test(expected = IllegalStateException.class)
@Test
public void noPublicMethods() {

@SuppressWarnings("unused")
Expand All @@ -567,7 +566,8 @@ String lowerCase(String s) {
}

NoPublicMethodTestBean bean = new NoPublicMethodTestBean();
new MethodInvokingMessageGroupProcessor(bean);
assertThatIllegalStateException()
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
}

@Test
Expand Down
Loading