Skip to content

Migrate Spring Batch Infrastructure to JUnit Jupiter #4125

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

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 10 additions & 10 deletions spring-batch-infrastructure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down Expand Up @@ -303,7 +303,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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,19 +16,16 @@

package org.springframework.batch.config;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.annotation.Transactional;
import org.junit.runner.RunWith;
import org.junit.Test;
import org.junit.jupiter.api.Test;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
public class DatasourceTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2022 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,28 +16,25 @@

package org.springframework.batch.config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
public class MessagingTests {

@Autowired
private JmsTemplate jmsTemplate;

@Before
@BeforeEach
public void onSetUp() throws Exception {
Thread.sleep(100L);
getMessages(); // drain queue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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 @@ -15,8 +15,8 @@
*/
package org.springframework.batch.container.jms;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.SortedSet;
import java.util.TreeSet;
Expand All @@ -29,11 +29,10 @@
import jakarta.jms.MessageListener;
import jakarta.jms.TextMessage;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
Expand All @@ -44,16 +43,14 @@
import org.springframework.retry.support.DefaultRetryState;
import org.springframework.retry.support.RetryTemplate;
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;

/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
@DirtiesContext
public class BatchMessageListenerContainerIntegrationTests {

Expand All @@ -67,8 +64,8 @@ public class BatchMessageListenerContainerIntegrationTests {

private volatile BlockingQueue<String> processed = new LinkedBlockingQueue<>();

@After
@Before
@AfterEach
@BeforeEach
public void drainQueue() throws Exception {
container.stop();
while (jmsTemplate.receiveAndConvert("queue") != null) {
Expand All @@ -77,7 +74,7 @@ public void drainQueue() throws Exception {
processed.clear();
}

@AfterClass
@AfterAll
public static void giveContainerTimeToStop() throws Exception {
Thread.sleep(1000);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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 @@ -26,17 +26,17 @@
import jakarta.jms.Session;

import org.aopalliance.aop.Advice;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.batch.repeat.interceptor.RepeatOperationsInterceptor;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
import org.springframework.util.ReflectionUtils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -66,7 +66,7 @@ public void onMessage(Message arg0) {
when(consumer.receive(1000)).thenReturn(message);

boolean received = doExecute(session, consumer);
assertTrue("Message not received", received);
assertTrue(received, "Message not received");

}

Expand All @@ -86,7 +86,7 @@ public void testReceiveAndExecuteWithCallbackReturningNull() throws Exception {
when(session.getTransacted()).thenReturn(false);

boolean received = doExecute(session, consumer);
assertFalse("Message not received", received);
assertFalse(received, "Message not received");

}

Expand All @@ -98,7 +98,7 @@ public void testTransactionalReceiveAndExecuteWithCallbackThrowingException() th
container.setSessionTransacted(true);
try {
boolean received = doTestWithException(new IllegalStateException("No way!"), true, 2);
assertFalse("Message received", received);
assertFalse(received, "Message received");
fail("Expected IllegalStateException");
}
catch (IllegalStateException e) {
Expand All @@ -113,7 +113,7 @@ public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException()
container = getContainer(template);
container.setSessionTransacted(false);
boolean received = doTestWithException(new IllegalStateException("No way!"), false, 2);
assertTrue("Message not received but listener not transactional so this should be true", received);
assertTrue(received, "Message not received but listener not transactional so this should be true");
}

@Test
Expand All @@ -124,7 +124,7 @@ public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() thr
container.setSessionTransacted(false);
try {
boolean received = doTestWithException(new RuntimeException("No way!"), false, 2);
assertTrue("Message not received but listener not transactional so this should be true", received);
assertTrue(received, "Message not received but listener not transactional so this should be true");
}
catch (RuntimeException e) {
assertEquals("No way!", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2010 the original author or authors.
* Copyright 2009-2022 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 @@ -15,11 +15,11 @@
*/
package org.springframework.batch.item;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.batch.item.sample.Foo;

/**
Expand All @@ -35,7 +35,7 @@ public abstract class AbstractItemReaderTests {
*/
protected abstract ItemReader<Foo> getItemReader() throws Exception;

@Before
@BeforeEach
public void setUp() throws Exception {
tested = getItemReader();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2012 the original author or authors.
* Copyright 2009-2022 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 @@ -15,12 +15,12 @@
*/
package org.springframework.batch.item;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import org.springframework.batch.item.sample.Foo;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

/**
* Common tests for readers implementing both {@link ItemReader} and {@link ItemStream}.
Expand All @@ -38,13 +38,13 @@ protected ItemStream testedAsStream() {
}

@Override
@Before
@BeforeEach
public void setUp() throws Exception {
super.setUp();
testedAsStream().open(executionContext);
}

@After
@AfterEach
public void tearDown() throws Exception {
testedAsStream().close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
* Copyright 2006-2022 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 @@ -15,16 +15,16 @@
*/
package org.springframework.batch.item;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.Serializable;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils;

/**
Expand All @@ -36,7 +36,7 @@ public class ExecutionContextTests {

private ExecutionContext context;

@Before
@BeforeEach
public void setUp() throws Exception {
context = new ExecutionContext();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2022 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,11 +16,12 @@

package org.springframework.batch.item;

import org.junit.jupiter.api.Test;
import org.springframework.retry.interceptor.MethodInvocationRecoverer;

import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.fail;

public class ItemRecoveryHandlerTests extends TestCase {
public class ItemRecoveryHandlerTests {

MethodInvocationRecoverer<String> recoverer = new MethodInvocationRecoverer<String>() {
@Override
Expand All @@ -29,6 +30,7 @@ public String recover(Object[] data, Throwable cause) {
}
};

@Test
public void testRecover() throws Exception {
try {
recoverer.recover(new Object[] { "foo" }, null);
Expand Down
Loading