Skip to content

Commit 83d01fb

Browse files
hpoettkerfmbenhassine
authored andcommitted
Migrate Spring Batch Infrastructure to JUnit Jupiter
Issue #4125
1 parent 30166a8 commit 83d01fb

File tree

272 files changed

+2525
-2411
lines changed

Some content is hidden

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

272 files changed

+2525
-2411
lines changed

spring-batch-infrastructure/pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,16 @@
170170

171171
<!-- test dependencies -->
172172
<dependency>
173-
<groupId>junit</groupId>
174-
<artifactId>junit</artifactId>
175-
<version>${junit.version}</version>
173+
<groupId>org.junit.jupiter</groupId>
174+
<artifactId>junit-jupiter-engine</artifactId>
175+
<version>${junit-jupiter.version}</version>
176+
<scope>test</scope>
177+
</dependency>
178+
<dependency>
179+
<groupId>org.junit.jupiter</groupId>
180+
<artifactId>junit-jupiter-params</artifactId>
181+
<version>${junit-jupiter.version}</version>
176182
<scope>test</scope>
177-
<exclusions>
178-
<exclusion>
179-
<groupId>org.hamcrest</groupId>
180-
<artifactId>hamcrest-core</artifactId>
181-
</exclusion>
182-
</exclusions>
183183
</dependency>
184184
<dependency>
185185
<groupId>org.junit.jupiter</groupId>
@@ -315,7 +315,7 @@
315315
</dependency>
316316
<dependency>
317317
<groupId>org.mockito</groupId>
318-
<artifactId>mockito-core</artifactId>
318+
<artifactId>mockito-junit-jupiter</artifactId>
319319
<version>${mockito.version}</version>
320320
<scope>test</scope>
321321
</dependency>

spring-batch-infrastructure/src/test/java/org/springframework/batch/config/DatasourceTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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,19 +16,16 @@
1616

1717
package org.springframework.batch.config;
1818

19-
import static org.junit.Assert.*;
19+
import static org.junit.jupiter.api.Assertions.*;
2020

2121
import org.springframework.jdbc.core.JdbcTemplate;
22-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
23-
import org.springframework.test.context.ContextConfiguration;
22+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2423
import org.springframework.beans.factory.annotation.Autowired;
2524
import org.springframework.test.jdbc.JdbcTestUtils;
2625
import org.springframework.transaction.annotation.Transactional;
27-
import org.junit.runner.RunWith;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2927

30-
@RunWith(SpringJUnit4ClassRunner.class)
31-
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
28+
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
3229
public class DatasourceTests {
3330

3431
@Autowired

spring-batch-infrastructure/src/test/java/org/springframework/batch/config/MessagingTests.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 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,28 +16,25 @@
1616

1717
package org.springframework.batch.config;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.util.ArrayList;
2323
import java.util.List;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.jms.core.JmsTemplate;
30-
import org.springframework.test.context.ContextConfiguration;
31-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
29+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3230

33-
@RunWith(SpringJUnit4ClassRunner.class)
34-
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
31+
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
3532
public class MessagingTests {
3633

3734
@Autowired
3835
private JmsTemplate jmsTemplate;
3936

40-
@Before
37+
@BeforeEach
4138
public void onSetUp() throws Exception {
4239
Thread.sleep(100L);
4340
getMessages(); // drain queue

spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -15,8 +15,8 @@
1515
*/
1616
package org.springframework.batch.container.jms;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2020

2121
import java.util.SortedSet;
2222
import java.util.TreeSet;
@@ -29,11 +29,10 @@
2929
import jakarta.jms.MessageListener;
3030
import jakarta.jms.TextMessage;
3131

32-
import org.junit.After;
33-
import org.junit.AfterClass;
34-
import org.junit.Before;
35-
import org.junit.Test;
36-
import org.junit.runner.RunWith;
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.AfterAll;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
3736

3837
import org.springframework.beans.factory.annotation.Autowired;
3938
import org.springframework.jms.core.JmsTemplate;
@@ -44,16 +43,14 @@
4443
import org.springframework.retry.support.DefaultRetryState;
4544
import org.springframework.retry.support.RetryTemplate;
4645
import org.springframework.test.annotation.DirtiesContext;
47-
import org.springframework.test.context.ContextConfiguration;
48-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
46+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4947

5048
/**
5149
* @author Dave Syer
5250
* @author Mahmoud Ben Hassine
5351
*
5452
*/
55-
@RunWith(SpringJUnit4ClassRunner.class)
56-
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
53+
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
5754
@DirtiesContext
5855
public class BatchMessageListenerContainerIntegrationTests {
5956

@@ -67,8 +64,8 @@ public class BatchMessageListenerContainerIntegrationTests {
6764

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

70-
@After
71-
@Before
67+
@AfterEach
68+
@BeforeEach
7269
public void drainQueue() throws Exception {
7370
container.stop();
7471
while (jmsTemplate.receiveAndConvert("queue") != null) {
@@ -77,7 +74,7 @@ public void drainQueue() throws Exception {
7774
processed.clear();
7875
}
7976

80-
@AfterClass
77+
@AfterAll
8178
public static void giveContainerTimeToStop() throws Exception {
8279
Thread.sleep(1000);
8380
}

spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -26,17 +26,17 @@
2626
import jakarta.jms.Session;
2727

2828
import org.aopalliance.aop.Advice;
29-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3030

3131
import org.springframework.batch.repeat.interceptor.RepeatOperationsInterceptor;
3232
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
3333
import org.springframework.batch.repeat.support.RepeatTemplate;
3434
import org.springframework.util.ReflectionUtils;
3535

36-
import static org.junit.Assert.assertEquals;
37-
import static org.junit.Assert.assertFalse;
38-
import static org.junit.Assert.assertTrue;
39-
import static org.junit.Assert.fail;
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertFalse;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
39+
import static org.junit.jupiter.api.Assertions.fail;
4040
import static org.mockito.Mockito.mock;
4141
import static org.mockito.Mockito.when;
4242

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

6868
boolean received = doExecute(session, consumer);
69-
assertTrue("Message not received", received);
69+
assertTrue(received, "Message not received");
7070

7171
}
7272

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

8888
boolean received = doExecute(session, consumer);
89-
assertFalse("Message not received", received);
89+
assertFalse(received, "Message not received");
9090

9191
}
9292

@@ -98,7 +98,7 @@ public void testTransactionalReceiveAndExecuteWithCallbackThrowingException() th
9898
container.setSessionTransacted(true);
9999
try {
100100
boolean received = doTestWithException(new IllegalStateException("No way!"), true, 2);
101-
assertFalse("Message received", received);
101+
assertFalse(received, "Message received");
102102
fail("Expected IllegalStateException");
103103
}
104104
catch (IllegalStateException e) {
@@ -113,7 +113,7 @@ public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException()
113113
container = getContainer(template);
114114
container.setSessionTransacted(false);
115115
boolean received = doTestWithException(new IllegalStateException("No way!"), false, 2);
116-
assertTrue("Message not received but listener not transactional so this should be true", received);
116+
assertTrue(received, "Message not received but listener not transactional so this should be true");
117117
}
118118

119119
@Test
@@ -124,7 +124,7 @@ public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() thr
124124
container.setSessionTransacted(false);
125125
try {
126126
boolean received = doTestWithException(new RuntimeException("No way!"), false, 2);
127-
assertTrue("Message not received but listener not transactional so this should be true", received);
127+
assertTrue(received, "Message not received but listener not transactional so this should be true");
128128
}
129129
catch (RuntimeException e) {
130130
assertEquals("No way!", e.getMessage());

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemReaderTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2010 the original author or authors.
2+
* Copyright 2009-2022 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.
@@ -15,11 +15,11 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertNull;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
2020

21-
import org.junit.Before;
22-
import org.junit.Test;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
2323
import org.springframework.batch.item.sample.Foo;
2424

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

38-
@Before
38+
@BeforeEach
3939
public void setUp() throws Exception {
4040
tested = getItemReader();
4141
}

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemStreamItemReaderTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2012 the original author or authors.
2+
* Copyright 2009-2022 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.
@@ -15,12 +15,12 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18-
import static org.junit.Assert.*;
18+
import static org.junit.jupiter.api.Assertions.*;
1919

2020
import org.springframework.batch.item.sample.Foo;
21-
import org.junit.Before;
22-
import org.junit.After;
23-
import org.junit.Test;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.Test;
2424

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

4040
@Override
41-
@Before
41+
@BeforeEach
4242
public void setUp() throws Exception {
4343
super.setUp();
4444
testedAsStream().open(executionContext);
4545
}
4646

47-
@After
47+
@AfterEach
4848
public void tearDown() throws Exception {
4949
testedAsStream().close();
5050
}

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertNull;
21-
import static org.junit.Assert.assertTrue;
22-
import static org.junit.Assert.fail;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.fail;
2323

2424
import java.io.Serializable;
2525

26-
import org.junit.Before;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2828
import org.springframework.util.SerializationUtils;
2929

3030
/**
@@ -36,7 +36,7 @@ public class ExecutionContextTests {
3636

3737
private ExecutionContext context;
3838

39-
@Before
39+
@BeforeEach
4040
public void setUp() throws Exception {
4141
context = new ExecutionContext();
4242
}

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 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,11 +16,12 @@
1616

1717
package org.springframework.batch.item;
1818

19+
import org.junit.jupiter.api.Test;
1920
import org.springframework.retry.interceptor.MethodInvocationRecoverer;
2021

21-
import junit.framework.TestCase;
22+
import static org.junit.jupiter.api.Assertions.fail;
2223

23-
public class ItemRecoveryHandlerTests extends TestCase {
24+
public class ItemRecoveryHandlerTests {
2425

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

33+
@Test
3234
public void testRecover() throws Exception {
3335
try {
3436
recoverer.recover(new Object[] { "foo" }, null);

0 commit comments

Comments
 (0)