Skip to content

Commit 2fdb68d

Browse files
hpoettkerfmbenhassine
authored andcommitted
Migrate Spring Batch Core to JUnit Jupiter
1 parent feefc1c commit 2fdb68d

File tree

286 files changed

+4852
-6412
lines changed

Some content is hidden

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

286 files changed

+4852
-6412
lines changed

spring-batch-core/pom.xml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
</dependency>
8888

8989
<!-- test dependencies -->
90+
<dependency>
91+
<groupId>org.testcontainers</groupId>
92+
<artifactId>junit-jupiter</artifactId>
93+
<version>${testcontainers.version}</version>
94+
<scope>test</scope>
95+
</dependency>
9096
<dependency>
9197
<groupId>org.hsqldb</groupId>
9298
<artifactId>hsqldb</artifactId>
@@ -196,21 +202,9 @@
196202
<scope>test</scope>
197203
</dependency>
198204
<dependency>
199-
<groupId>junit</groupId>
200-
<artifactId>junit</artifactId>
201-
<version>${junit.version}</version>
202-
<scope>test</scope>
203-
<exclusions>
204-
<exclusion>
205-
<groupId>org.hamcrest</groupId>
206-
<artifactId>hamcrest-core</artifactId>
207-
</exclusion>
208-
</exclusions>
209-
</dependency>
210-
<dependency>
211-
<groupId>org.junit.vintage</groupId>
212-
<artifactId>junit-vintage-engine</artifactId>
213-
<version>${junit-vintage-engine.version}</version>
205+
<groupId>org.junit.jupiter</groupId>
206+
<artifactId>junit-jupiter-engine</artifactId>
207+
<version>${junit-jupiter.version}</version>
214208
<scope>test</scope>
215209
</dependency>
216210
<dependency>
@@ -233,7 +227,7 @@
233227
</dependency>
234228
<dependency>
235229
<groupId>org.mockito</groupId>
236-
<artifactId>mockito-core</artifactId>
230+
<artifactId>mockito-junit-jupiter</artifactId>
237231
<version>${mockito.version}</version>
238232
<scope>test</scope>
239233
</dependency>

spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,14 @@
1616

1717
package org.springframework.batch.core;
1818

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

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
public abstract class AbstractExceptionTests extends AbstractExceptionWithCauseTests {
2424

2525
@Test
26-
public void testExceptionString() throws Exception {
26+
void testExceptionString() throws Exception {
2727
Exception exception = getException("foo");
2828
assertEquals("foo", exception.getMessage());
2929
}

spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionWithCauseTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,14 @@
1616

1717
package org.springframework.batch.core;
1818

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

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
public abstract class AbstractExceptionWithCauseTests {
2424

2525
@Test
26-
public void testExceptionStringThrowable() throws Exception {
26+
void testExceptionStringThrowable() throws Exception {
2727
Exception exception = getException("foo", new IllegalStateException());
2828
assertEquals("foo", exception.getMessage().substring(0, 3));
2929
}

spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,36 +15,35 @@
1515
*/
1616
package org.springframework.batch.core;
1717

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

2423
import java.io.ByteArrayInputStream;
2524
import java.io.ByteArrayOutputStream;
2625
import java.io.ObjectInputStream;
2726
import java.io.ObjectOutputStream;
2827

29-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
3029

3130
/**
3231
* @author Dave Syer
3332
* @author Mahmoud Ben Hassine
3433
*
3534
*/
36-
public class BatchStatusTests {
35+
class BatchStatusTests {
3736

3837
/**
3938
* Test method for {@link org.springframework.batch.core.BatchStatus#toString()}.
4039
*/
4140
@Test
42-
public void testToString() {
41+
void testToString() {
4342
assertEquals("ABANDONED", BatchStatus.ABANDONED.toString());
4443
}
4544

4645
@Test
47-
public void testMaxStatus() {
46+
void testMaxStatus() {
4847
assertEquals(BatchStatus.FAILED, BatchStatus.max(BatchStatus.FAILED, BatchStatus.COMPLETED));
4948
assertEquals(BatchStatus.FAILED, BatchStatus.max(BatchStatus.COMPLETED, BatchStatus.FAILED));
5049
assertEquals(BatchStatus.FAILED, BatchStatus.max(BatchStatus.FAILED, BatchStatus.FAILED));
@@ -53,58 +52,52 @@ public void testMaxStatus() {
5352
}
5453

5554
@Test
56-
public void testUpgradeStatusFinished() {
55+
void testUpgradeStatusFinished() {
5756
assertEquals(BatchStatus.FAILED, BatchStatus.FAILED.upgradeTo(BatchStatus.COMPLETED));
5857
assertEquals(BatchStatus.FAILED, BatchStatus.COMPLETED.upgradeTo(BatchStatus.FAILED));
5958
}
6059

6160
@Test
62-
public void testUpgradeStatusUnfinished() {
61+
void testUpgradeStatusUnfinished() {
6362
assertEquals(BatchStatus.COMPLETED, BatchStatus.STARTING.upgradeTo(BatchStatus.COMPLETED));
6463
assertEquals(BatchStatus.COMPLETED, BatchStatus.COMPLETED.upgradeTo(BatchStatus.STARTING));
6564
assertEquals(BatchStatus.STARTED, BatchStatus.STARTING.upgradeTo(BatchStatus.STARTED));
6665
assertEquals(BatchStatus.STARTED, BatchStatus.STARTED.upgradeTo(BatchStatus.STARTING));
6766
}
6867

6968
@Test
70-
public void testIsRunning() {
69+
void testIsRunning() {
7170
assertFalse(BatchStatus.FAILED.isRunning());
7271
assertFalse(BatchStatus.COMPLETED.isRunning());
7372
assertTrue(BatchStatus.STARTED.isRunning());
7473
assertTrue(BatchStatus.STARTING.isRunning());
7574
}
7675

7776
@Test
78-
public void testIsUnsuccessful() {
77+
void testIsUnsuccessful() {
7978
assertTrue(BatchStatus.FAILED.isUnsuccessful());
8079
assertFalse(BatchStatus.COMPLETED.isUnsuccessful());
8180
assertFalse(BatchStatus.STARTED.isUnsuccessful());
8281
assertFalse(BatchStatus.STARTING.isUnsuccessful());
8382
}
8483

8584
@Test
86-
public void testGetStatus() {
85+
void testGetStatus() {
8786
assertEquals(BatchStatus.FAILED, BatchStatus.valueOf(BatchStatus.FAILED.toString()));
8887
}
8988

9089
@Test
91-
public void testGetStatusWrongCode() {
92-
try {
93-
BatchStatus.valueOf("foo");
94-
fail();
95-
}
96-
catch (IllegalArgumentException ex) {
97-
// expected
98-
}
90+
void testGetStatusWrongCode() {
91+
assertThrows(IllegalArgumentException.class, () -> BatchStatus.valueOf("foo"));
9992
}
10093

101-
@Test(expected = NullPointerException.class)
102-
public void testGetStatusNullCode() {
103-
assertNull(BatchStatus.valueOf(null));
94+
@Test
95+
void testGetStatusNullCode() {
96+
assertThrows(NullPointerException.class, () -> BatchStatus.valueOf(null));
10497
}
10598

10699
@Test
107-
public void testSerialization() throws Exception {
100+
void testSerialization() throws Exception {
108101

109102
ByteArrayOutputStream bout = new ByteArrayOutputStream();
110103
ObjectOutputStream out = new ObjectOutputStream(bout);

spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2013-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,27 +15,22 @@
1515
*/
1616
package org.springframework.batch.core;
1717

18-
import static org.junit.Assert.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertThrows;
1920

20-
import org.junit.Before;
21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
public class DefaultJobKeyGeneratorTests {
23+
class DefaultJobKeyGeneratorTests {
2424

25-
private JobKeyGenerator<JobParameters> jobKeyGenerator;
25+
private final JobKeyGenerator<JobParameters> jobKeyGenerator = new DefaultJobKeyGenerator();
2626

27-
@Before
28-
public void setUp() throws Exception {
29-
jobKeyGenerator = new DefaultJobKeyGenerator();
30-
}
31-
32-
@Test(expected = IllegalArgumentException.class)
33-
public void testNullParameters() {
34-
jobKeyGenerator.generateKey(null);
27+
@Test
28+
void testNullParameters() {
29+
assertThrows(IllegalArgumentException.class, () -> jobKeyGenerator.generateKey(null));
3530
}
3631

3732
@Test
38-
public void testMixedParameters() {
33+
void testMixedParameters() {
3934
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
4035
.toJobParameters();
4136
JobParameters jobParameters2 = new JobParametersBuilder().addString("foo", "bar", true)
@@ -46,15 +41,15 @@ public void testMixedParameters() {
4641
}
4742

4843
@Test
49-
public void testCreateJobKey() {
44+
void testCreateJobKey() {
5045
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
5146
.toJobParameters();
5247
String key = jobKeyGenerator.generateKey(jobParameters);
5348
assertEquals(32, key.length());
5449
}
5550

5651
@Test
57-
public void testCreateJobKeyOrdering() {
52+
void testCreateJobKeyOrdering() {
5853
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
5954
.toJobParameters();
6055
String key1 = jobKeyGenerator.generateKey(jobParameters1);

0 commit comments

Comments
 (0)