Skip to content

Commit 8ca9802

Browse files
cppwfsfmbenhassine
authored andcommitted
Remove the JUnit dependency in AssertFile
The side effect is a breaking change in that it will now throw IllegalStateException instead of the Compare and AssertExceptions provided by JUnit. Resolves #4111
1 parent c425137 commit 8ca9802

File tree

82 files changed

+682
-525
lines changed

Some content is hidden

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

82 files changed

+682
-525
lines changed

spring-batch-samples/pom.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,11 @@
158158
<artifactId>spring-batch-test</artifactId>
159159
<scope>test</scope>
160160
</dependency>
161-
<dependency>
162-
<groupId>junit</groupId>
163-
<artifactId>junit</artifactId>
164-
<version>${junit.version}</version>
165-
<scope>test</scope>
166-
<exclusions>
167-
<exclusion>
168-
<groupId>org.hamcrest</groupId>
169-
<artifactId>hamcrest-core</artifactId>
170-
</exclusion>
171-
</exclusions>
172-
</dependency>
173161
<dependency>
174162
<groupId>org.junit.jupiter</groupId>
175163
<artifactId>junit-jupiter-engine</artifactId>
176164
<version>${junit-jupiter.version}</version>
165+
<scope>test</scope>
177166
</dependency>
178167
<dependency>
179168
<groupId>org.hamcrest</groupId>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

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

22+
import org.junit.jupiter.api.extension.ExtendWith;
2223
import org.springframework.batch.core.Job;
2324
import org.springframework.batch.core.explore.JobExplorer;
2425
import org.springframework.batch.test.JobLauncherTestUtils;
2526
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
27+
import org.springframework.test.context.ContextConfiguration;
28+
import org.springframework.test.context.junit.jupiter.SpringExtension;
2729

2830
/**
2931
* <p>
@@ -39,7 +41,8 @@
3941
* </p>
4042
*/
4143

42-
@SpringJUnitConfig(
44+
@ExtendWith(SpringExtension.class)
45+
@ContextConfiguration(
4346
locations = { "/simple-job-launcher-context.xml", "/jobs/amqp-example-job.xml", "/job-runner-context.xml" })
4447
class AMQPJobFunctionalTests {
4548

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package org.springframework.batch.sample;
1818

1919
import org.junit.jupiter.api.Test;
20-
20+
import org.junit.jupiter.api.extension.ExtendWith;
2121
import org.springframework.batch.core.Job;
2222
import org.springframework.batch.test.JobLauncherTestUtils;
2323
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
24+
import org.springframework.test.context.ContextConfiguration;
25+
import org.springframework.test.context.junit.jupiter.SpringExtension;
2526

26-
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml",
27+
@ExtendWith(SpringExtension.class)
28+
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml",
2729
"/job-runner-context.xml" })
2830
class BeanWrapperMapperSampleJobFunctionalTests {
2931

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,32 @@
1515
*/
1616
package org.springframework.batch.sample;
1717

18-
import java.io.FileInputStream;
19-
import java.io.IOException;
20-
import java.math.BigDecimal;
21-
import java.sql.ResultSet;
22-
import java.sql.SQLException;
23-
import java.util.ArrayList;
24-
import java.util.List;
25-
import javax.sql.DataSource;
26-
2718
import org.apache.commons.io.IOUtils;
2819
import org.junit.jupiter.api.Test;
29-
20+
import org.junit.jupiter.api.extension.ExtendWith;
3021
import org.springframework.batch.core.Job;
3122
import org.springframework.batch.sample.domain.trade.Trade;
3223
import org.springframework.batch.test.JobLauncherTestUtils;
3324
import org.springframework.beans.factory.annotation.Autowired;
3425
import org.springframework.jdbc.core.JdbcTemplate;
3526
import org.springframework.jdbc.core.RowCallbackHandler;
36-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
27+
import org.springframework.test.context.ContextConfiguration;
28+
import org.springframework.test.context.junit.jupiter.SpringExtension;
3729
import org.springframework.test.jdbc.JdbcTestUtils;
3830

31+
import javax.sql.DataSource;
32+
import java.io.FileInputStream;
33+
import java.io.IOException;
34+
import java.math.BigDecimal;
35+
import java.sql.ResultSet;
36+
import java.sql.SQLException;
37+
import java.util.ArrayList;
38+
import java.util.List;
39+
3940
import static org.junit.jupiter.api.Assertions.assertEquals;
4041

41-
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml",
42+
@ExtendWith(SpringExtension.class)
43+
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml",
4244
"/job-runner-context.xml" })
4345
class CompositeItemWriterSampleFunctionalTests {
4446

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,32 @@
1616

1717
package org.springframework.batch.sample;
1818

19-
import static org.junit.jupiter.api.Assertions.assertEquals;
20-
21-
import java.sql.ResultSet;
22-
import java.sql.SQLException;
23-
import java.util.Arrays;
24-
import java.util.HashMap;
25-
import java.util.List;
26-
import java.util.Map;
27-
28-
import javax.sql.DataSource;
29-
3019
import org.junit.jupiter.api.AfterEach;
3120
import org.junit.jupiter.api.BeforeEach;
3221
import org.junit.jupiter.api.Test;
33-
22+
import org.junit.jupiter.api.extension.ExtendWith;
3423
import org.springframework.batch.core.Job;
3524
import org.springframework.batch.core.JobExecution;
3625
import org.springframework.batch.test.JobLauncherTestUtils;
3726
import org.springframework.beans.factory.annotation.Autowired;
3827
import org.springframework.jdbc.core.JdbcTemplate;
3928
import org.springframework.jdbc.core.RowCallbackHandler;
40-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
29+
import org.springframework.test.context.ContextConfiguration;
30+
import org.springframework.test.context.junit.jupiter.SpringExtension;
4131
import org.springframework.test.jdbc.JdbcTestUtils;
4232

43-
@SpringJUnitConfig(
33+
import javax.sql.DataSource;
34+
import java.sql.ResultSet;
35+
import java.sql.SQLException;
36+
import java.util.Arrays;
37+
import java.util.HashMap;
38+
import java.util.List;
39+
import java.util.Map;
40+
41+
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
43+
@ExtendWith(SpringExtension.class)
44+
@ContextConfiguration(
4445
locations = { "/simple-job-launcher-context.xml", "/jobs/customerFilterJob.xml", "/job-runner-context.xml" })
4546
class CustomerFilterJobFunctionalTests {
4647

@@ -95,7 +96,7 @@ void testFilterJob(@Autowired Job job) throws Exception {
9596
jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() {
9697
@Override
9798
public void processRow(ResultSet rs) throws SQLException {
98-
Customer customer = customers.get(activeRow++);
99+
CustomerFilterJobFunctionalTests.Customer customer = customers.get(activeRow++);
99100
assertEquals(customer.getName(), rs.getString(1));
100101
assertEquals(customer.getCredit(), rs.getDouble(2), .01);
101102
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@
1616

1717
package org.springframework.batch.sample;
1818

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;
23-
2419
import org.apache.commons.logging.Log;
2520
import org.apache.commons.logging.LogFactory;
2621
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.ExtendWith;
2723
import org.springframework.batch.core.BatchStatus;
2824
import org.springframework.batch.core.Job;
2925
import org.springframework.batch.core.JobExecution;
3026
import org.springframework.batch.core.launch.JobOperator;
3127
import org.springframework.batch.test.JobLauncherTestUtils;
3228
import org.springframework.beans.factory.annotation.Autowired;
33-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
29+
import org.springframework.test.context.ContextConfiguration;
30+
import org.springframework.test.context.junit.jupiter.SpringExtension;
31+
32+
import static org.junit.jupiter.api.Assertions.*;
3433

3534
/**
3635
* Functional test for graceful shutdown. A batch container is started in a new thread,
3736
* then it's stopped using {@link JobOperator#stop(long)}}.
3837
*
3938
* @author Lucas Ward
4039
* @author Mahmoud Ben Hassine
40+
* @author Glenn Renfro
4141
*
4242
*/
43-
@SpringJUnitConfig(
43+
44+
@ExtendWith(SpringExtension.class)
45+
@ContextConfiguration(
4446
locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml", "/job-runner-context.xml" })
4547
class DatabaseShutdownFunctionalTests {
4648

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

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

18-
import static org.junit.jupiter.api.Assertions.assertEquals;
19-
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
2118
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.extension.ExtendWith;
2220

2321
import org.springframework.batch.core.Job;
2422
import org.springframework.batch.sample.domain.person.PersonService;
2523
import org.springframework.batch.test.JobLauncherTestUtils;
2624
import org.springframework.beans.factory.annotation.Autowired;
27-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
25+
import org.springframework.test.context.ContextConfiguration;
26+
import org.springframework.test.context.junit.jupiter.SpringExtension;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertTrue;
2830

29-
@SpringJUnitConfig(
31+
@ExtendWith(SpringExtension.class)
32+
@ContextConfiguration(
3033
locations = { "/simple-job-launcher-context.xml", "/jobs/delegatingJob.xml", "/job-runner-context.xml" })
3134
class DelegatingJobFunctionalTests {
3235

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
*/
1616
package org.springframework.batch.sample;
1717

18-
import static org.junit.jupiter.api.Assertions.assertTrue;
19-
20-
import javax.sql.DataSource;
21-
2218
import org.junit.jupiter.api.Test;
23-
19+
import org.junit.jupiter.api.extension.ExtendWith;
2420
import org.springframework.batch.core.Job;
2521
import org.springframework.batch.test.JobLauncherTestUtils;
2622
import org.springframework.beans.factory.annotation.Autowired;
2723
import org.springframework.jdbc.core.JdbcTemplate;
28-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
24+
import org.springframework.test.context.ContextConfiguration;
25+
import org.springframework.test.context.junit.jupiter.SpringExtension;
2926
import org.springframework.test.jdbc.JdbcTestUtils;
3027

31-
@SpringJUnitConfig(
28+
import javax.sql.DataSource;
29+
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
31+
32+
@ExtendWith(SpringExtension.class)
33+
@ContextConfiguration(
3234
locations = { "/simple-job-launcher-context.xml", "/jobs/footballJob.xml", "/job-runner-context.xml" })
3335
class FootballJobFunctionalTests {
3436

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,30 @@
1616

1717
package org.springframework.batch.sample;
1818

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.assertTrue;
22-
2319
import org.apache.commons.logging.Log;
2420
import org.apache.commons.logging.LogFactory;
2521
import org.junit.jupiter.api.Test;
26-
import org.springframework.batch.core.BatchStatus;
27-
import org.springframework.batch.core.Job;
28-
import org.springframework.batch.core.JobExecution;
29-
import org.springframework.batch.core.JobParameters;
30-
import org.springframework.batch.core.JobParametersBuilder;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
import org.springframework.batch.core.*;
3124
import org.springframework.batch.core.launch.JobOperator;
3225
import org.springframework.batch.test.JobLauncherTestUtils;
3326
import org.springframework.beans.factory.annotation.Autowired;
34-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
27+
import org.springframework.test.context.ContextConfiguration;
28+
import org.springframework.test.context.junit.jupiter.SpringExtension;
29+
30+
import static org.junit.jupiter.api.Assertions.*;
3531

3632
/**
3733
* Functional test for graceful shutdown. A batch container is started in a new thread,
3834
* then it's stopped using {@link JobOperator#stop(long)}.
3935
*
4036
* @author Lucas Ward
4137
* @author Parikshit Dutta
38+
* @author Glenn Renfro
4239
*
4340
*/
44-
@SpringJUnitConfig(
41+
@ExtendWith(SpringExtension.class)
42+
@ContextConfiguration(
4543
locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml", "/job-runner-context.xml" })
4644
class GracefulShutdownFunctionalTests {
4745

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@
1616

1717
package org.springframework.batch.sample;
1818

19-
import static org.junit.jupiter.api.Assertions.assertFalse;
20-
import static org.junit.jupiter.api.Assertions.assertTrue;
21-
22-
import java.io.File;
23-
import java.io.IOException;
24-
2519
import org.apache.commons.io.FileUtils;
2620
import org.junit.jupiter.api.BeforeEach;
2721
import org.junit.jupiter.api.Test;
28-
22+
import org.junit.jupiter.api.extension.ExtendWith;
2923
import org.springframework.batch.core.Job;
3024
import org.springframework.batch.test.JobLauncherTestUtils;
3125
import org.springframework.beans.factory.annotation.Autowired;
32-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
26+
import org.springframework.test.context.ContextConfiguration;
27+
import org.springframework.test.context.junit.jupiter.SpringExtension;
28+
29+
import java.io.File;
30+
import java.io.IOException;
31+
32+
import static org.junit.jupiter.api.Assertions.assertFalse;
33+
import static org.junit.jupiter.api.Assertions.assertTrue;
3334

34-
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/groovyJob.xml", "/job-runner-context.xml" })
35-
class GroovyJobFunctionalTests {
35+
@ExtendWith(SpringExtension.class)
36+
@ContextConfiguration(
37+
locations = { "/simple-job-launcher-context.xml", "/jobs/groovyJob.xml", "/job-runner-context.xml" })
38+
public class GroovyJobFunctionalTests {
3639

3740
@Autowired
3841
private JobLauncherTestUtils jobLauncherTestUtils;

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@
1515
*/
1616
package org.springframework.batch.sample;
1717

18-
import static org.junit.jupiter.api.Assertions.assertTrue;
19-
2018
import java.io.BufferedReader;
2119
import java.io.FileReader;
2220

2321
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.ExtendWith;
2423

2524
import org.springframework.batch.core.Job;
2625
import org.springframework.batch.test.JobLauncherTestUtils;
2726
import org.springframework.beans.factory.annotation.Autowired;
2827
import org.springframework.beans.factory.annotation.Qualifier;
2928
import org.springframework.core.io.Resource;
30-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
29+
import org.springframework.test.context.ContextConfiguration;
30+
import org.springframework.test.context.junit.jupiter.SpringExtension;
31+
32+
import static org.springframework.test.util.AssertionErrors.assertTrue;
3133

32-
@SpringJUnitConfig(
34+
@ExtendWith(SpringExtension.class)
35+
@ContextConfiguration(
3336
locations = { "/simple-job-launcher-context.xml", "/jobs/headerFooterSample.xml", "/job-runner-context.xml" })
3437
class HeaderFooterSampleFunctionalTests {
3538

@@ -60,12 +63,13 @@ void testJob(@Autowired Job job) throws Exception {
6063
int lineCount = 0;
6164
while ((line = inputReader.readLine()) != null) {
6265
lineCount++;
63-
assertTrue(outputReader.readLine().contains(line), "input line should correspond to output line");
66+
assertTrue("input line should correspond to output line", outputReader.readLine().contains(line));
6467
}
6568

6669
// footer contains the item count
6770
int itemCount = lineCount - 1; // minus 1 due to header line
68-
assertTrue(outputReader.readLine().contains(String.valueOf(itemCount)));
71+
assertTrue("OutputReader did not contain the values specified",
72+
outputReader.readLine().contains(String.valueOf(itemCount)));
6973

7074
inputReader.close();
7175
outputReader.close();

0 commit comments

Comments
 (0)