diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml
index 40957133e2..08cf0d5fe4 100644
--- a/spring-batch-samples/pom.xml
+++ b/spring-batch-samples/pom.xml
@@ -170,6 +170,11 @@
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit-jupiter.version}
+
org.hamcrest
hamcrest-library
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java
index bbbd58df1e..ff17b7796c 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 the original author or authors.
+ * Copyright 2012-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.
@@ -15,15 +15,13 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
*
@@ -39,10 +37,9 @@
*
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/amqp-example-job.xml", "/job-runner-context.xml" })
-public class AMQPJobFunctionalTests {
+class AMQPJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -51,7 +48,7 @@ public class AMQPJobFunctionalTests {
private JobExplorer jobExplorer;
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
jobLauncherTestUtils.launchJob();
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java
index b78110164b..b5d16a584b 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java
@@ -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.
@@ -16,23 +16,20 @@
package org.springframework.batch.sample;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-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 = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml",
+@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml",
"/job-runner-context.xml" })
-public class BeanWrapperMapperSampleJobFunctionalTests {
+class BeanWrapperMapperSampleJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testJobLaunch() throws Exception {
+ void testJobLaunch() throws Exception {
jobLauncherTestUtils.launchJob();
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java
index 05bfb1ad5e..ce31eda863 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2021 the original author or authors.
+ * Copyright 2008-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.
@@ -25,24 +25,21 @@
import javax.sql.DataSource;
import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.sample.domain.trade.Trade;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml",
+@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml",
"/job-runner-context.xml" })
-public class CompositeItemWriterSampleFunctionalTests {
+class CompositeItemWriterSampleFunctionalTests {
private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM TRADE order by isin";
@@ -63,7 +60,7 @@ public void setDataSource(DataSource dataSource) {
}
@Test
- public void testJobLaunch() throws Exception {
+ void testJobLaunch() throws Exception {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
@@ -75,7 +72,6 @@ public void testJobLaunch() throws Exception {
}
private void checkOutputTable(int before) {
- @SuppressWarnings("serial")
final List trades = new ArrayList() {
{
add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"));
@@ -107,7 +103,6 @@ public void processRow(ResultSet rs) throws SQLException {
}
private void checkOutputFile(String fileName) throws IOException {
- @SuppressWarnings("resource")
List outputLines = IOUtils.readLines(new FileInputStream(fileName), "UTF-8");
String output = "";
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java
index fd963336e0..69110d385c 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java
@@ -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.
@@ -16,7 +16,7 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -27,23 +27,20 @@
import javax.sql.DataSource;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/customerFilterJob.xml", "/job-runner-context.xml" })
-public class CustomerFilterJobFunctionalTests {
+class CustomerFilterJobFunctionalTests {
private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME";
@@ -53,7 +50,7 @@ public class CustomerFilterJobFunctionalTests {
private JdbcTemplate jdbcTemplate;
- private Map credits = new HashMap<>();
+ private final Map credits = new HashMap<>();
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -63,8 +60,8 @@ public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
- @Before
- public void onSetUp() throws Exception {
+ @BeforeEach
+ void onSetUp() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4");
jdbcTemplate.update("update CUSTOMER set credit=100000");
@@ -76,14 +73,14 @@ public void onSetUp() throws Exception {
}
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4");
}
@Test
- public void testFilterJob() throws Exception {
+ void testFilterJob() throws Exception {
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
customers = Arrays.asList(new Customer("customer1", (credits.get("customer1"))),
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java
index 2e3d3fca42..a85443cd02 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java
@@ -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.
@@ -16,22 +16,20 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* Functional test for graceful shutdown. A batch container is started in a new thread,
@@ -41,10 +39,9 @@
* @author Mahmoud Ben Hassine
*
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml", "/job-runner-context.xml" })
-public class DatabaseShutdownFunctionalTests {
+class DatabaseShutdownFunctionalTests {
/** Logger */
protected final Log logger = LogFactory.getLog(getClass());
@@ -56,7 +53,7 @@ public class DatabaseShutdownFunctionalTests {
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
@@ -75,7 +72,7 @@ public void testLaunchJob() throws Exception {
count++;
}
- assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
+ assertFalse(jobExecution.isRunning(), "Timed out waiting for job to end.");
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java
index b4bea1cd4d..4ca1283e49 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2009 the original author or authors.
+ * Copyright 2007-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.
@@ -15,21 +15,18 @@
*/
package org.springframework.batch.sample;
-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 org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.sample.domain.person.PersonService;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-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(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/delegatingJob.xml", "/job-runner-context.xml" })
-public class DelegatingJobFunctionalTests {
+class DelegatingJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -38,7 +35,7 @@ public class DelegatingJobFunctionalTests {
private PersonService personService;
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
jobLauncherTestUtils.launchJob();
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java
index 64619f9190..283cf70dbb 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2021 the original author or authors.
+ * Copyright 2007-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.
@@ -15,23 +15,20 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.sql.DataSource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/footballJob.xml", "/job-runner-context.xml" })
-public class FootballJobFunctionalTests {
+class FootballJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -44,7 +41,7 @@ public void setDataSource(DataSource dataSource) {
}
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS", "GAMES", "PLAYER_SUMMARY");
jobLauncherTestUtils.launchJob();
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java
index 60bfd5494b..9f0b9d2694 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java
@@ -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.
@@ -16,14 +16,13 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
@@ -31,8 +30,7 @@
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* Functional test for graceful shutdown. A batch container is started in a new thread,
@@ -42,10 +40,9 @@
* @author Parikshit Dutta
*
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml", "/job-runner-context.xml" })
-public class GracefulShutdownFunctionalTests {
+class GracefulShutdownFunctionalTests {
/** Logger */
private final Log logger = LogFactory.getLog(getClass());
@@ -57,7 +54,7 @@ public class GracefulShutdownFunctionalTests {
private JobOperator jobOperator;
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
final JobParameters jobParameters = new JobParametersBuilder().addLong("timestamp", System.currentTimeMillis())
.toJobParameters();
@@ -78,7 +75,7 @@ public void testLaunchJob() throws Exception {
count++;
}
- assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
+ assertFalse(jobExecution.isRunning(), "Timed out waiting for job to end.");
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java
index ddbe20d9a4..09afcd451c 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java
@@ -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.
@@ -16,36 +16,32 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
-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.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-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 = { "/simple-job-launcher-context.xml", "/jobs/groovyJob.xml", "/job-runner-context.xml" })
-public class GroovyJobFunctionalTests {
+@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/groovyJob.xml", "/job-runner-context.xml" })
+class GroovyJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
- @Before
- public void removeOldData() throws IOException {
+ @BeforeEach
+ void removeOldData() throws IOException {
FileUtils.deleteDirectory(new File("target/groovyJob"));
}
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
assertFalse(new File("target/groovyJob/output/files.zip").exists());
jobLauncherTestUtils.launchJob();
assertTrue(new File("target/groovyJob/output/files.zip").exists());
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java
index c19e807907..ec55a4510c 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2014 the original author or authors.
+ * Copyright 2008-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.
@@ -15,24 +15,21 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.BufferedReader;
import java.io.FileReader;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.Resource;
-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(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/headerFooterSample.xml", "/job-runner-context.xml" })
-public class HeaderFooterSampleFunctionalTests {
+class HeaderFooterSampleFunctionalTests {
@Autowired
@Qualifier("inputResource")
@@ -46,7 +43,7 @@ public class HeaderFooterSampleFunctionalTests {
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testJob() throws Exception {
+ void testJob() throws Exception {
jobLauncherTestUtils.launchJob();
BufferedReader inputReader = new BufferedReader(new FileReader(input.getFile()));
@@ -60,7 +57,7 @@ public void testJob() throws Exception {
int lineCount = 0;
while ((line = inputReader.readLine()) != null) {
lineCount++;
- assertTrue("input line should correspond to output line", outputReader.readLine().contains(line));
+ assertTrue(outputReader.readLine().contains(line), "input line should correspond to output line");
}
// footer contains the item count
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java
index 6215d12fbb..d429200d94 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2021 the original author or authors.
+ * Copyright 2007-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.
@@ -15,8 +15,8 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.math.BigDecimal;
import java.sql.ResultSet;
@@ -26,8 +26,7 @@
import javax.sql.DataSource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
@@ -40,8 +39,7 @@
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.orm.hibernate5.HibernateJdbcException;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
@@ -54,10 +52,9 @@
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/hibernate-context.xml",
- "/jobs/hibernateJob.xml", "/job-runner-context.xml" })
-public class HibernateFailureJobFunctionalTests {
+@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/hibernate-context.xml", "/jobs/hibernateJob.xml",
+ "/job-runner-context.xml" })
+class HibernateFailureJobFunctionalTests {
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT;
@@ -65,7 +62,7 @@ public class HibernateFailureJobFunctionalTests {
private static final String CREDIT_COLUMN = "CREDIT";
- private static String[] customers = {
+ private static final String[] customers = {
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)",
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)",
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)",
@@ -78,6 +75,7 @@ public class HibernateFailureJobFunctionalTests {
private JdbcTemplate jdbcTemplate;
+ @Autowired
private PlatformTransactionManager transactionManager;
private List creditsBeforeUpdate;
@@ -90,13 +88,8 @@ public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
- @Autowired
- public void setTransactionManager(PlatformTransactionManager transactionManager) {
- this.transactionManager = transactionManager;
- }
-
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
validatePreConditions();
JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters();
@@ -126,7 +119,7 @@ public void testLaunchJob() throws Exception {
/**
* All customers have the same credit
*/
- protected void validatePreConditions() throws Exception {
+ protected void validatePreConditions() {
ensureState();
creditsBeforeUpdate = new TransactionTemplate(transactionManager)
.execute(new TransactionCallback>() {
@@ -163,7 +156,7 @@ public Void doInTransaction(TransactionStatus status) {
/**
* Credit was increased by CREDIT_INCREASE
*/
- protected void validatePostConditions() throws Exception {
+ protected void validatePostConditions() {
final List matches = new ArrayList<>();
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java
index ce0f86d5ef..a411c087b4 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2009 the original author or authors.
+ * Copyright 2008-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.
@@ -15,9 +15,10 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Map;
@@ -25,9 +26,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-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.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersBuilder;
@@ -35,12 +35,10 @@
import org.springframework.batch.core.configuration.support.ReferenceJobFactory;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.beans.factory.annotation.Autowired;
-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 = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml" })
-public class JobOperatorFunctionalTests {
+@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml" })
+class JobOperatorFunctionalTests {
private static final Log LOG = LogFactory.getLog(JobOperatorFunctionalTests.class);
@@ -53,15 +51,15 @@ public class JobOperatorFunctionalTests {
@Autowired
private JobRegistry jobRegistry;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
if (!jobRegistry.getJobNames().contains(job.getName())) {
jobRegistry.register(new ReferenceJobFactory(job));
}
}
@Test
- public void testStartStopResumeJob() throws Exception {
+ void testStartStopResumeJob() throws Exception {
String params = new JobParametersBuilder().addLong("jobOperatorTestParam", 7L).toJobParameters().toString();
long executionId = operator.start(job.getName(), params);
@@ -91,10 +89,10 @@ private void stopAndCheckStatus(long executionId) throws Exception {
Thread.sleep(1000);
Set runningExecutions = operator.getRunningExecutions(job.getName());
- assertTrue("Wrong executions: " + runningExecutions + " expected: " + executionId,
- runningExecutions.contains(executionId));
- assertTrue("Wrong summary: " + operator.getSummary(executionId),
- operator.getSummary(executionId).contains(BatchStatus.STARTED.toString()));
+ assertTrue(runningExecutions.contains(executionId),
+ "Wrong executions: " + runningExecutions + " expected: " + executionId);
+ assertTrue(operator.getSummary(executionId).contains(BatchStatus.STARTED.toString()),
+ "Wrong summary: " + operator.getSummary(executionId));
operator.stop(executionId);
@@ -106,10 +104,10 @@ private void stopAndCheckStatus(long executionId) throws Exception {
}
runningExecutions = operator.getRunningExecutions(job.getName());
- assertFalse("Wrong executions: " + runningExecutions + " expected: " + executionId,
- runningExecutions.contains(executionId));
- assertTrue("Wrong summary: " + operator.getSummary(executionId),
- operator.getSummary(executionId).contains(BatchStatus.STOPPED.toString()));
+ assertFalse(runningExecutions.contains(executionId),
+ "Wrong executions: " + runningExecutions + " expected: " + executionId);
+ assertTrue(operator.getSummary(executionId).contains(BatchStatus.STOPPED.toString()),
+ "Wrong summary: " + operator.getSummary(executionId));
// there is just a single step in the test job
Map summaries = operator.getStepExecutionSummaries(executionId);
@@ -118,7 +116,7 @@ private void stopAndCheckStatus(long executionId) throws Exception {
}
@Test
- public void testMultipleSimultaneousInstances() throws Exception {
+ void testMultipleSimultaneousInstances() throws Exception {
String jobName = job.getName();
Set names = operator.getJobNames();
@@ -129,7 +127,7 @@ public void testMultipleSimultaneousInstances() throws Exception {
long exec2 = operator.startNextInstance(jobName);
assertTrue(exec1 != exec2);
- assertTrue(!operator.getParameters(exec1).equals(operator.getParameters(exec2)));
+ assertNotEquals(operator.getParameters(exec1), operator.getParameters(exec2));
// Give the asynchronous task executor a chance to start executions
Thread.sleep(1000);
@@ -147,8 +145,8 @@ public void testMultipleSimultaneousInstances() throws Exception {
running = operator.getSummary(exec1).contains("STARTED") && operator.getSummary(exec2).contains("STARTED");
}
- assertTrue(String.format("Jobs not started: [%s] and [%s]", operator.getSummary(exec1),
- operator.getSummary(exec1)), running);
+ assertTrue(running, String.format("Jobs not started: [%s] and [%s]", operator.getSummary(exec1),
+ operator.getSummary(exec1)));
operator.stop(exec1);
operator.stop(exec2);
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java
index 2cc6d95b57..4d6e5ce24f 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java
@@ -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.
@@ -16,19 +16,17 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import javax.sql.DataSource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
import org.springframework.batch.support.PropertiesConverter;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
/**
@@ -37,9 +35,8 @@
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration
-public class JobStepFunctionalTests {
+@SpringJUnitConfig
+class JobStepFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -52,7 +49,7 @@ public void setDataSource(DataSource dataSource) {
}
@Test
- public void testJobLaunch() throws Exception {
+ void testJobLaunch() throws Exception {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
jobLauncherTestUtils
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java
index 390cae1efe..fa66a651d3 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2021 the original author or authors.
+ * Copyright 2018-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.
@@ -23,9 +23,8 @@
import javax.sql.DataSource;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
@@ -52,23 +51,25 @@
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.util.DigestUtils;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* @author Mahmoud Ben Hassine
*/
-public class JsonSupportIntegrationTests {
+class JsonSupportIntegrationTests {
private static final String INPUT_FILE_DIRECTORY = "src/test/resources/org/springframework/batch/item/json/";
private static final String OUTPUT_FILE_DIRECTORY = "target/";
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
Files.deleteIfExists(Paths.get("build", "trades.json"));
}
@Configuration
@EnableBatchProcessing
- public static class JobConfiguration {
+ static class JobConfiguration {
@Autowired
private JobBuilderFactory jobs;
@@ -109,13 +110,13 @@ public DataSource dataSource() {
}
@Test
- public void testJsonReadingAndWriting() throws Exception {
+ void testJsonReadingAndWriting() throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(JobConfiguration.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
- Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode());
+ assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode());
assertFileEquals(new File(INPUT_FILE_DIRECTORY + "trades.json"),
new File(OUTPUT_FILE_DIRECTORY + "trades.json"));
}
@@ -123,7 +124,7 @@ public void testJsonReadingAndWriting() throws Exception {
private void assertFileEquals(File expected, File actual) throws Exception {
String expectedHash = DigestUtils.md5DigestAsHex(new FileInputStream(expected));
String actualHash = DigestUtils.md5DigestAsHex(new FileInputStream(actual));
- Assert.assertEquals(expectedHash, actualHash);
+ assertEquals(expectedHash, actualHash);
}
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java
index 9e6c76fdbb..082cc22c86 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java
@@ -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.
@@ -15,15 +15,13 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* Checks that expected number of items have been processed.
@@ -31,10 +29,9 @@
* @author Dan Garrette
* @since 2.0
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/loopFlowSample.xml", "/job-runner-context.xml" })
-public class LoopFlowSampleFunctionalTests {
+class LoopFlowSampleFunctionalTests {
@Autowired
private ItemTrackingTradeItemWriter itemWriter;
@@ -43,7 +40,7 @@ public class LoopFlowSampleFunctionalTests {
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testJobLaunch() throws Exception {
+ void testJobLaunch() throws Exception {
jobLauncherTestUtils.launchJob();
// items processed = items read + 2 exceptions
assertEquals(10, itemWriter.getItems().size());
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java
index 1ecf4d3a66..4abc32f5ed 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java
@@ -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.
@@ -15,17 +15,16 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Iterator;
import java.util.List;
import javax.sql.DataSource;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.sample.domain.mail.internal.TestMailErrorHandler;
@@ -35,20 +34,17 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.mail.MailMessage;
import org.springframework.mail.SimpleMailMessage;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
/**
* @author Dan Garrette
* @author Dave Syer
* @author Mahmoud Ben Hassine
- * @Since 2.1
+ * @since 2.1
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- locations = { "/simple-job-launcher-context.xml", "/jobs/mailJob.xml", "/job-runner-context.xml" })
-public class MailJobFunctionalTests {
+@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/mailJob.xml", "/job-runner-context.xml" })
+class MailJobFunctionalTests {
private static final String email = "to@company.com";
@@ -84,20 +80,20 @@ public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
mailSender.clear();
errorHandler.clear();
jdbcTemplate.update("create table USERS (ID INTEGER, NAME VARCHAR(40), EMAIL VARCHAR(20))");
}
- @After
- public void after() throws Exception {
+ @AfterEach
+ void after() {
JdbcTestUtils.dropTables(jdbcTemplate, "USERS");
}
@Test
- public void testSkip() throws Exception {
+ void testSkip() throws Exception {
this.createUsers(new Object[][] { USER1, USER2_SKIP, USER3, USER4_SKIP, USER5, USER6, USER7, USER8 });
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java
index a840312191..c38a896f56 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java
@@ -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.
@@ -17,23 +17,20 @@
package org.springframework.batch.sample;
import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.StringUtils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/multilineJob.xml", "/job-runner-context.xml" })
-public class MultilineJobFunctionalTests {
+class MultilineJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -43,10 +40,10 @@ public class MultilineJobFunctionalTests {
private static final String EXPECTED_RESULT = "[Trade: [isin=UK21341EAH45,quantity=978,price=98.34,customer=customer1], Trade: [isin=UK21341EAH46,quantity=112,price=18.12,customer=customer2]]"
+ "[Trade: [isin=UK21341EAH47,quantity=245,price=12.78,customer=customer2], Trade: [isin=UK21341EAH48,quantity=108,price=9.25,customer=customer3], Trade: [isin=UK21341EAH49,quantity=854,price=23.39,customer=customer4]]";
- private Resource output = new FileSystemResource("target/test-outputs/20070122.testStream.multilineStep.txt");
+ private final Resource output = new FileSystemResource("target/test-outputs/20070122.testStream.multilineStep.txt");
@Test
- public void testJobLaunch() throws Exception {
+ void testJobLaunch() throws Exception {
jobLauncherTestUtils.launchJob();
assertEquals(EXPECTED_RESULT, StringUtils.replace(IOUtils.toString(output.getInputStream(), "UTF-8"),
System.getProperty("line.separator"), ""));
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java
index ef9458cb47..e900de9095 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java
@@ -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.
@@ -18,19 +18,16 @@
import static org.springframework.batch.test.AssertFile.assertFileEquals;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
-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(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/multilineOrderJob.xml", "/job-runner-context.xml" })
-public class MultilineOrderJobFunctionalTests {
+class MultilineOrderJobFunctionalTests {
private static final String ACTUAL = "target/test-outputs/multilineOrderOutput.txt";
@@ -40,7 +37,7 @@ public class MultilineOrderJobFunctionalTests {
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testJobLaunch() throws Exception {
+ void testJobLaunch() throws Exception {
jobLauncherTestUtils.launchJob();
assertFileEquals(new ClassPathResource(EXPECTED), new FileSystemResource(ACTUAL));
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java
index 1ee733c2c5..024af43b90 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2012 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.
@@ -16,25 +16,22 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import javax.sql.DataSource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
-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(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/parallelJob.xml", "/job-runner-context.xml" })
-public class ParallelJobFunctionalTests {
+class ParallelJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -47,7 +44,7 @@ public void setDataSource(DataSource dataSource) {
}
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING");
JobExecution execution = jobLauncherTestUtils.launchJob();
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING");
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java
index d3ec636436..123c0557c0 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2014 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.
@@ -16,16 +16,15 @@
package org.springframework.batch.sample;
-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.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.item.ExecutionContext;
@@ -39,13 +38,11 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
-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(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/partitionFileJob.xml", "/job-runner-context.xml" })
-public class PartitionFileJobFunctionalTests implements ApplicationContextAware {
+class PartitionFileJobFunctionalTests implements ApplicationContextAware {
@Autowired
@Qualifier("inputTestReader")
@@ -65,9 +62,9 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
* Check the resulting credits correspond to inputs increased by fixed amount.
*/
@Test
- public void testUpdateCredit() throws Exception {
- assertTrue("Define a prototype bean called 'outputTestReader' to check the output",
- applicationContext.containsBeanDefinition("outputTestReader"));
+ void testUpdateCredit() throws Exception {
+ assertTrue(applicationContext.containsBeanDefinition("outputTestReader"),
+ "Define a prototype bean called 'outputTestReader' to check the output");
open(inputReader);
List inputs = new ArrayList<>(getCredits(inputReader));
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java
index 33ec74b773..7adeaffae9 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2014 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.
@@ -16,16 +16,15 @@
package org.springframework.batch.sample;
-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.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.item.ExecutionContext;
@@ -39,13 +38,11 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
-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(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/partitionJdbcJob.xml", "/job-runner-context.xml" })
-public class PartitionJdbcJobFunctionalTests implements ApplicationContextAware {
+class PartitionJdbcJobFunctionalTests implements ApplicationContextAware {
@Autowired
@Qualifier("inputTestReader")
@@ -65,9 +62,9 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
* Check the resulting credits correspond to inputs increased by fixed amount.
*/
@Test
- public void testUpdateCredit() throws Exception {
- assertTrue("Define a prototype bean called 'outputTestReader' to check the output",
- applicationContext.containsBeanDefinition("outputTestReader"));
+ void testUpdateCredit() throws Exception {
+ assertTrue(applicationContext.containsBeanDefinition("outputTestReader"),
+ "Define a prototype bean called 'outputTestReader' to check the output");
open(inputReader);
List inputs = new ArrayList<>(getCredits(inputReader));
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java
index 424942de06..144ded6491 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2021 the original author or authors.
+ * Copyright 2018-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.
@@ -18,12 +18,9 @@
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
-import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
@@ -32,11 +29,11 @@
import org.springframework.batch.sample.remotechunking.WorkerConfiguration;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.PropertySource;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The manager step of the job under test will read data and send chunks to the worker
@@ -45,22 +42,19 @@
*
* @author Mahmoud Ben Hassine
*/
-@RunWith(SpringRunner.class)
-@ContextConfiguration(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class })
+@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class })
@PropertySource("classpath:remote-chunking.properties")
-public class RemoteChunkingJobFunctionalTests {
-
- private static final String BROKER_DATA_DIRECTORY = "target/activemq-data";
+class RemoteChunkingJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
- private static EmbeddedActiveMQ brokerService;
+ private EmbeddedActiveMQ brokerService;
private AnnotationConfigApplicationContext workerApplicationContext;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
Configuration configuration = new ConfigurationImpl().addAcceptorConfiguration("jms", "tcp://localhost:61616")
.setPersistenceEnabled(false).setSecurityEnabled(false).setJMXManagementEnabled(false)
.setJournalDatasync(false);
@@ -68,21 +62,21 @@ public void setUp() throws Exception {
this.workerApplicationContext = new AnnotationConfigApplicationContext(WorkerConfiguration.class);
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
this.workerApplicationContext.close();
this.brokerService.stop();
}
@Test
- public void testRemoteChunkingJob() throws Exception {
+ void testRemoteChunkingJob() throws Exception {
// when
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob();
// then
- Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode());
- Assert.assertEquals("Waited for 2 results.", // the manager sent 2 chunks ({1, 2,
- // 3} and {4, 5, 6}) to workers
+ assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode());
+ assertEquals("Waited for 2 results.", // the manager sent 2 chunks ({1, 2,
+ // 3} and {4, 5, 6}) to workers
jobExecution.getExitStatus().getExitDescription());
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java
index 163bb898c1..969e6c5d49 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2021 the original author or authors.
+ * Copyright 2018-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.
@@ -20,11 +20,9 @@
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
@@ -35,14 +33,14 @@
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
-import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Base class for remote partitioning tests.
*
* @author Mahmoud Ben Hassine
*/
-@RunWith(SpringRunner.class)
@PropertySource("classpath:remote-partitioning.properties")
public abstract class RemotePartitioningJobFunctionalTests {
@@ -63,8 +61,8 @@ public abstract class RemotePartitioningJobFunctionalTests {
protected abstract Class> getWorkerConfigurationClass();
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
Configuration configuration = new ConfigurationImpl().addAcceptorConfiguration("jms", "tcp://localhost:61617")
.setPersistenceEnabled(false).setSecurityEnabled(false).setJMXManagementEnabled(false)
.setJournalDatasync(false);
@@ -77,18 +75,18 @@ public void setUp() throws Exception {
}
@Test
- public void testRemotePartitioningJob() throws Exception {
+ void testRemotePartitioningJob() throws Exception {
// when
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob();
// then
- Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode());
- Assert.assertEquals(4, jobExecution.getStepExecutions().size()); // manager + 3
- // workers
+ assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode());
+ assertEquals(4, jobExecution.getStepExecutions().size()); // manager + 3
+ // workers
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
this.workerApplicationContext.close();
this.brokerService.stop();
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java
index 8fa4950a48..c6e8378149 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2019 the original author or authors.
+ * Copyright 2018-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.
@@ -18,15 +18,15 @@
import org.springframework.batch.sample.config.JobRunnerConfiguration;
import org.springframework.batch.sample.remotepartitioning.aggregating.ManagerConfiguration;
import org.springframework.batch.sample.remotepartitioning.aggregating.WorkerConfiguration;
-import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* The manager step of the job under test will create 3 partitions for workers to process.
*
* @author Mahmoud Ben Hassine
*/
-@ContextConfiguration(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class })
-public class RemotePartitioningJobWithMessageAggregationFunctionalTests extends RemotePartitioningJobFunctionalTests {
+@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class })
+class RemotePartitioningJobWithMessageAggregationFunctionalTests extends RemotePartitioningJobFunctionalTests {
@Override
protected Class getWorkerConfigurationClass() {
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java
index 4e7e9e0de7..db404d4c8c 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2019 the original author or authors.
+ * Copyright 2018-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.
@@ -18,15 +18,15 @@
import org.springframework.batch.sample.config.JobRunnerConfiguration;
import org.springframework.batch.sample.remotepartitioning.polling.ManagerConfiguration;
import org.springframework.batch.sample.remotepartitioning.polling.WorkerConfiguration;
-import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* The manager step of the job under test will create 3 partitions for workers to process.
*
* @author Mahmoud Ben Hassine
*/
-@ContextConfiguration(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class })
-public class RemotePartitioningJobWithRepositoryPollingFunctionalTests extends RemotePartitioningJobFunctionalTests {
+@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class })
+class RemotePartitioningJobWithRepositoryPollingFunctionalTests extends RemotePartitioningJobFunctionalTests {
@Override
protected Class getWorkerConfigurationClass() {
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java
index 53139af2d0..494f846fd6 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java
@@ -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.
@@ -16,12 +16,11 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
@@ -31,17 +30,15 @@
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dan Garrette
* @since 2.0
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/restartFileSampleJob.xml", "/job-runner-context.xml" })
-public class RestartFileSampleFunctionalTests {
+class RestartFileSampleFunctionalTests {
@Autowired
private Resource outputResource;
@@ -50,7 +47,7 @@ public class RestartFileSampleFunctionalTests {
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void runTest() throws Exception {
+ void runTest() throws Exception {
JobParameters jobParameters = jobLauncherTestUtils.getUniqueJobParameters();
JobExecution je1 = jobLauncherTestUtils.launchJob(jobParameters);
@@ -62,7 +59,7 @@ public void runTest() throws Exception {
AssertFile.assertLineCount(20, outputResource);
}
- public static class CustomerCreditFlatFileItemWriter extends FlatFileItemWriter {
+ static class CustomerCreditFlatFileItemWriter extends FlatFileItemWriter {
private boolean failed = false;
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java
index adea0bc078..ef826f45b4 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java
@@ -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.
@@ -16,12 +16,12 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.sql.DataSource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
@@ -29,8 +29,7 @@
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.jdbc.JdbcTestUtils;
@@ -41,10 +40,9 @@
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/restartSample.xml", "/job-runner-context.xml" })
-public class RestartFunctionalTests {
+class RestartFunctionalTests {
private JdbcTemplate jdbcTemplate;
@@ -57,7 +55,7 @@ public void setDataSource(DataSource dataSource) {
}
@BeforeTransaction
- public void onTearDown() throws Exception {
+ void onTearDown() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
}
@@ -69,19 +67,14 @@ public void onTearDown() throws Exception {
* @throws Exception
*/
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
JobExecution jobExecution = runJobForRestartTest();
assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
Throwable ex = jobExecution.getAllFailureExceptions().get(0);
- if (ex.getMessage().toLowerCase().indexOf("planned") < 0) {
- if (ex instanceof Exception) {
- throw (Exception) ex;
- }
- throw new RuntimeException(ex);
- }
+ assertTrue(ex.getMessage().toLowerCase().contains("planned"));
int medium = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
// assert based on commit interval = 2
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java
index c1b55d9230..02020fee2d 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 the original author or authors.
+ * Copyright 2012-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.
@@ -15,10 +15,9 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.sample.config.DataSourceConfiguration;
import org.springframework.batch.sample.config.JobRunnerConfiguration;
import org.springframework.batch.sample.config.RetrySampleConfiguration;
@@ -26,8 +25,7 @@
import org.springframework.batch.sample.support.RetrySampleItemWriter;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* Checks that expected number of items have been processed.
@@ -35,10 +33,9 @@
* @author Robert Kasanicky
* @author Dave Syer
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
classes = { DataSourceConfiguration.class, RetrySampleConfiguration.class, JobRunnerConfiguration.class })
-public class RetrySampleConfigurationTests {
+class RetrySampleConfigurationTests {
@Autowired
private GeneratingTradeItemReader itemGenerator;
@@ -50,7 +47,7 @@ public class RetrySampleConfigurationTests {
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
jobLauncherTestUtils.launchJob();
// items processed = items read + 2 exceptions
assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter());
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java
index 3359d5907c..8c5cbc07ed 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2009 the original author or authors.
+ * Copyright 2008-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.
@@ -15,26 +15,23 @@
*/
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.sample.domain.trade.internal.GeneratingTradeItemReader;
import org.springframework.batch.sample.support.RetrySampleItemWriter;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* Checks that expected number of items have been processed.
*
* @author Robert Kasanicky
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/retrySample.xml", "/job-runner-context.xml" })
-public class RetrySampleFunctionalTests {
+class RetrySampleFunctionalTests {
@Autowired
private GeneratingTradeItemReader itemGenerator;
@@ -46,7 +43,7 @@ public class RetrySampleFunctionalTests {
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
jobLauncherTestUtils.launchJob();
// items processed = items read + 2 exceptions
assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter());
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java
index 1a47cf9b39..89407584c2 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2021 the original author or authors.
+ * Copyright 2008-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.
@@ -15,17 +15,18 @@
*/
package org.springframework.batch.sample;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
import java.util.Map;
import javax.sql.DataSource;
-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.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
@@ -54,8 +55,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* Error is encountered during writing - transaction is rolled back and the error item is
@@ -65,9 +65,8 @@
* @author Dan Garrette
* @author Mahmoud Ben Hassine
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "/skipSample-job-launcher-context.xml" })
-public class SkipSampleFunctionalTests {
+@SpringJUnitConfig(locations = { "/skipSample-job-launcher-context.xml" })
+class SkipSampleFunctionalTests {
private JdbcTemplate jdbcTemplate;
@@ -86,8 +85,8 @@ public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE", "CUSTOMER");
for (int i = 1; i < 10; i++) {
jdbcTemplate.update("INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (" + incrementer.nextIntValue()
@@ -155,7 +154,7 @@ public void setUp() {
*
*/
@Test
- public void testJobIncrementing() {
+ void testJobIncrementing() {
//
// Launch 1
//
@@ -184,7 +183,7 @@ public void testJobIncrementing() {
// instances
//
assertTrue(id1 != id2);
- assertTrue(!execution1.getJobId().equals(execution2.getJobId()));
+ assertNotEquals(execution1.getJobId(), execution2.getJobId());
}
/*
@@ -193,7 +192,7 @@ public void testJobIncrementing() {
* written).
*/
@Test
- public void testSkippableExceptionDuringRead() throws Exception {
+ void testSkippableExceptionDuringRead() throws Exception {
// given
ApplicationContext context = new AnnotationConfigApplicationContext(SkippableExceptionDuringReadSample.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
@@ -216,7 +215,7 @@ public void testSkippableExceptionDuringRead() throws Exception {
* the writer).
*/
@Test
- public void testSkippableExceptionDuringProcess() throws Exception {
+ void testSkippableExceptionDuringProcess() throws Exception {
// given
ApplicationContext context = new AnnotationConfigApplicationContext(
SkippableExceptionDuringProcessSample.class);
@@ -242,7 +241,7 @@ public void testSkippableExceptionDuringProcess() throws Exception {
* re-processed/re-written in its own transaction).
*/
@Test
- public void testSkippableExceptionDuringWrite() throws Exception {
+ void testSkippableExceptionDuringWrite() throws Exception {
// given
ApplicationContext context = new AnnotationConfigApplicationContext(SkippableExceptionDuringWriteSample.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java
index c75f29734b..ac2b85e471 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java
@@ -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.
@@ -16,36 +16,33 @@
package org.springframework.batch.sample;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
-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(
+@SpringJUnitConfig(
locations = { "/simple-job-launcher-context.xml", "/jobs/taskletJob.xml", "/job-runner-context.xml" })
-public class TaskletJobFunctionalTests {
+class TaskletJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
- public void testLaunchJob() throws Exception {
+ void testLaunchJob() throws Exception {
JobExecution jobExecution = jobLauncherTestUtils
.launchJob(new JobParametersBuilder().addString("value", "foo").toJobParameters());
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals("yes", jobExecution.getExecutionContext().getString("done"));
}
- public static class TestBean {
+ static class TestBean {
private String value;
@@ -62,7 +59,7 @@ public void execute(String strValue, Integer integerValue, double doubleValue) {
}
- public static class Task {
+ static class Task {
public boolean doWork(ChunkContext chunkContext) {
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("done", "yes");
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java
index 421f314c98..64d978bf95 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java
@@ -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.
@@ -16,8 +16,8 @@
package org.springframework.batch.sample;
-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.math.BigDecimal;
import java.sql.ResultSet;
@@ -29,23 +29,19 @@
import javax.sql.DataSource;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.sample.domain.trade.Trade;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- locations = { "/simple-job-launcher-context.xml", "/jobs/tradeJob.xml", "/job-runner-context.xml" })
-public class TradeJobFunctionalTests {
+@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/tradeJob.xml", "/job-runner-context.xml" })
+class TradeJobFunctionalTests {
private static final String GET_TRADES = "select ISIN, QUANTITY, PRICE, CUSTOMER, ID, VERSION from TRADE order by ISIN";
@@ -59,7 +55,7 @@ public class TradeJobFunctionalTests {
private JdbcTemplate jdbcTemplate;
- private Map credits = new HashMap<>();
+ private final Map credits = new HashMap<>();
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -69,8 +65,8 @@ public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
- @Before
- public void onSetUp() throws Exception {
+ @BeforeEach
+ void onSetUp() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
List