Skip to content

Commit 1e4a23e

Browse files
hpoettkerfmbenhassine
authored andcommitted
Migrate Spring Batch Samples to JUnit Jupiter
1 parent 6117c04 commit 1e4a23e

File tree

91 files changed

+773
-1036
lines changed

Some content is hidden

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

91 files changed

+773
-1036
lines changed

spring-batch-samples/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
</exclusion>
171171
</exclusions>
172172
</dependency>
173+
<dependency>
174+
<groupId>org.junit.jupiter</groupId>
175+
<artifactId>junit-jupiter-engine</artifactId>
176+
<version>${junit-jupiter.version}</version>
177+
</dependency>
173178
<dependency>
174179
<groupId>org.hamcrest</groupId>
175180
<artifactId>hamcrest-library</artifactId>

spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java

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

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

20-
import org.junit.Test;
21-
import org.junit.runner.RunWith;
20+
import org.junit.jupiter.api.Test;
2221
import org.springframework.batch.core.explore.JobExplorer;
2322
import org.springframework.batch.test.JobLauncherTestUtils;
2423
import org.springframework.beans.factory.annotation.Autowired;
25-
import org.springframework.test.context.ContextConfiguration;
26-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2725

2826
/**
2927
* <p>
@@ -39,10 +37,9 @@
3937
* </p>
4038
*/
4139

42-
@RunWith(SpringJUnit4ClassRunner.class)
43-
@ContextConfiguration(
40+
@SpringJUnitConfig(
4441
locations = { "/simple-job-launcher-context.xml", "/jobs/amqp-example-job.xml", "/job-runner-context.xml" })
45-
public class AMQPJobFunctionalTests {
42+
class AMQPJobFunctionalTests {
4643

4744
@Autowired
4845
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -51,7 +48,7 @@ public class AMQPJobFunctionalTests {
5148
private JobExplorer jobExplorer;
5249

5350
@Test
54-
public void testLaunchJob() throws Exception {
51+
void testLaunchJob() throws Exception {
5552

5653
jobLauncherTestUtils.launchJob();
5754

spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java

Lines changed: 6 additions & 9 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,23 +16,20 @@
1616

1717
package org.springframework.batch.sample;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Test;
2120
import org.springframework.batch.test.JobLauncherTestUtils;
2221
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.test.context.ContextConfiguration;
24-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
22+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2523

26-
@RunWith(SpringJUnit4ClassRunner.class)
27-
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml",
24+
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml",
2825
"/job-runner-context.xml" })
29-
public class BeanWrapperMapperSampleJobFunctionalTests {
26+
class BeanWrapperMapperSampleJobFunctionalTests {
3027

3128
@Autowired
3229
private JobLauncherTestUtils jobLauncherTestUtils;
3330

3431
@Test
35-
public void testJobLaunch() throws Exception {
32+
void testJobLaunch() throws Exception {
3633

3734
jobLauncherTestUtils.launchJob();
3835

spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-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.
@@ -25,24 +25,21 @@
2525
import javax.sql.DataSource;
2626

2727
import org.apache.commons.io.IOUtils;
28-
import org.junit.Test;
29-
import org.junit.runner.RunWith;
28+
import org.junit.jupiter.api.Test;
3029

3130
import org.springframework.batch.sample.domain.trade.Trade;
3231
import org.springframework.batch.test.JobLauncherTestUtils;
3332
import org.springframework.beans.factory.annotation.Autowired;
3433
import org.springframework.jdbc.core.JdbcTemplate;
3534
import org.springframework.jdbc.core.RowCallbackHandler;
36-
import org.springframework.test.context.ContextConfiguration;
37-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
35+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3836
import org.springframework.test.jdbc.JdbcTestUtils;
3937

40-
import static org.junit.Assert.assertEquals;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
4139

42-
@RunWith(SpringJUnit4ClassRunner.class)
43-
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml",
40+
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml",
4441
"/job-runner-context.xml" })
45-
public class CompositeItemWriterSampleFunctionalTests {
42+
class CompositeItemWriterSampleFunctionalTests {
4643

4744
private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM TRADE order by isin";
4845

@@ -63,7 +60,7 @@ public void setDataSource(DataSource dataSource) {
6360
}
6461

6562
@Test
66-
public void testJobLaunch() throws Exception {
63+
void testJobLaunch() throws Exception {
6764
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
6865
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
6966

@@ -75,7 +72,6 @@ public void testJobLaunch() throws Exception {
7572
}
7673

7774
private void checkOutputTable(int before) {
78-
@SuppressWarnings("serial")
7975
final List<Trade> trades = new ArrayList<Trade>() {
8076
{
8177
add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"));
@@ -107,7 +103,6 @@ public void processRow(ResultSet rs) throws SQLException {
107103
}
108104

109105
private void checkOutputFile(String fileName) throws IOException {
110-
@SuppressWarnings("resource")
111106
List<String> outputLines = IOUtils.readLines(new FileInputStream(fileName), "UTF-8");
112107

113108
String output = "";

spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java

Lines changed: 14 additions & 17 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,7 +16,7 @@
1616

1717
package org.springframework.batch.sample;
1818

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

2121
import java.sql.ResultSet;
2222
import java.sql.SQLException;
@@ -27,23 +27,20 @@
2727

2828
import javax.sql.DataSource;
2929

30-
import org.junit.After;
31-
import org.junit.Before;
32-
import org.junit.Test;
33-
import org.junit.runner.RunWith;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3433
import org.springframework.batch.core.JobExecution;
3534
import org.springframework.batch.test.JobLauncherTestUtils;
3635
import org.springframework.beans.factory.annotation.Autowired;
3736
import org.springframework.jdbc.core.JdbcTemplate;
3837
import org.springframework.jdbc.core.RowCallbackHandler;
39-
import org.springframework.test.context.ContextConfiguration;
40-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4139
import org.springframework.test.jdbc.JdbcTestUtils;
4240

43-
@RunWith(SpringJUnit4ClassRunner.class)
44-
@ContextConfiguration(
41+
@SpringJUnitConfig(
4542
locations = { "/simple-job-launcher-context.xml", "/jobs/customerFilterJob.xml", "/job-runner-context.xml" })
46-
public class CustomerFilterJobFunctionalTests {
43+
class CustomerFilterJobFunctionalTests {
4744

4845
private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME";
4946

@@ -53,7 +50,7 @@ public class CustomerFilterJobFunctionalTests {
5350

5451
private JdbcTemplate jdbcTemplate;
5552

56-
private Map<String, Double> credits = new HashMap<>();
53+
private final Map<String, Double> credits = new HashMap<>();
5754

5855
@Autowired
5956
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -63,8 +60,8 @@ public void setDataSource(DataSource dataSource) {
6360
this.jdbcTemplate = new JdbcTemplate(dataSource);
6461
}
6562

66-
@Before
67-
public void onSetUp() throws Exception {
63+
@BeforeEach
64+
void onSetUp() {
6865
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
6966
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4");
7067
jdbcTemplate.update("update CUSTOMER set credit=100000");
@@ -76,14 +73,14 @@ public void onSetUp() throws Exception {
7673
}
7774
}
7875

79-
@After
80-
public void tearDown() throws Exception {
76+
@AfterEach
77+
void tearDown() {
8178
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
8279
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4");
8380
}
8481

8582
@Test
86-
public void testFilterJob() throws Exception {
83+
void testFilterJob() throws Exception {
8784
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
8885

8986
customers = Arrays.asList(new Customer("customer1", (credits.get("customer1"))),

spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java

Lines changed: 11 additions & 14 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,22 +16,20 @@
1616

1717
package org.springframework.batch.sample;
1818

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

2424
import org.apache.commons.logging.Log;
2525
import org.apache.commons.logging.LogFactory;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
26+
import org.junit.jupiter.api.Test;
2827
import org.springframework.batch.core.BatchStatus;
2928
import org.springframework.batch.core.JobExecution;
3029
import org.springframework.batch.core.launch.JobOperator;
3130
import org.springframework.batch.test.JobLauncherTestUtils;
3231
import org.springframework.beans.factory.annotation.Autowired;
33-
import org.springframework.test.context.ContextConfiguration;
34-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
32+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3533

3634
/**
3735
* Functional test for graceful shutdown. A batch container is started in a new thread,
@@ -41,10 +39,9 @@
4139
* @author Mahmoud Ben Hassine
4240
*
4341
*/
44-
@RunWith(SpringJUnit4ClassRunner.class)
45-
@ContextConfiguration(
42+
@SpringJUnitConfig(
4643
locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml", "/job-runner-context.xml" })
47-
public class DatabaseShutdownFunctionalTests {
44+
class DatabaseShutdownFunctionalTests {
4845

4946
/** Logger */
5047
protected final Log logger = LogFactory.getLog(getClass());
@@ -56,7 +53,7 @@ public class DatabaseShutdownFunctionalTests {
5653
private JobLauncherTestUtils jobLauncherTestUtils;
5754

5855
@Test
59-
public void testLaunchJob() throws Exception {
56+
void testLaunchJob() throws Exception {
6057

6158
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
6259

@@ -75,7 +72,7 @@ public void testLaunchJob() throws Exception {
7572
count++;
7673
}
7774

78-
assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
75+
assertFalse(jobExecution.isRunning(), "Timed out waiting for job to end.");
7976
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
8077

8178
}

spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java

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

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

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322
import org.springframework.batch.sample.domain.person.PersonService;
2423
import org.springframework.batch.test.JobLauncherTestUtils;
2524
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.test.context.ContextConfiguration;
27-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
25+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2826

29-
@RunWith(SpringJUnit4ClassRunner.class)
30-
@ContextConfiguration(
27+
@SpringJUnitConfig(
3128
locations = { "/simple-job-launcher-context.xml", "/jobs/delegatingJob.xml", "/job-runner-context.xml" })
32-
public class DelegatingJobFunctionalTests {
29+
class DelegatingJobFunctionalTests {
3330

3431
@Autowired
3532
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -38,7 +35,7 @@ public class DelegatingJobFunctionalTests {
3835
private PersonService personService;
3936

4037
@Test
41-
public void testLaunchJob() throws Exception {
38+
void testLaunchJob() throws Exception {
4239

4340
jobLauncherTestUtils.launchJob();
4441

spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java

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

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

2020
import javax.sql.DataSource;
2121

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

31-
@RunWith(SpringJUnit4ClassRunner.class)
32-
@ContextConfiguration(
29+
@SpringJUnitConfig(
3330
locations = { "/simple-job-launcher-context.xml", "/jobs/footballJob.xml", "/job-runner-context.xml" })
34-
public class FootballJobFunctionalTests {
31+
class FootballJobFunctionalTests {
3532

3633
@Autowired
3734
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -44,7 +41,7 @@ public void setDataSource(DataSource dataSource) {
4441
}
4542

4643
@Test
47-
public void testLaunchJob() throws Exception {
44+
void testLaunchJob() throws Exception {
4845
JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS", "GAMES", "PLAYER_SUMMARY");
4946

5047
jobLauncherTestUtils.launchJob();

0 commit comments

Comments
 (0)