diff --git a/spring-batch-core/pom.xml b/spring-batch-core/pom.xml
index 0507ec7409..84d52400be 100644
--- a/spring-batch-core/pom.xml
+++ b/spring-batch-core/pom.xml
@@ -87,6 +87,12 @@
+
+ org.testcontainers
+ junit-jupiter
+ ${testcontainers.version}
+ test
+
org.hsqldb
hsqldb
@@ -196,21 +202,9 @@
test
- junit
- junit
- ${junit.version}
- test
-
-
- org.hamcrest
- hamcrest-core
-
-
-
-
- org.junit.vintage
- junit-vintage-engine
- ${junit-vintage-engine.version}
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit-jupiter.version}
test
@@ -233,7 +227,7 @@
org.mockito
- mockito-core
+ mockito-junit-jupiter
${mockito.version}
test
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionTests.java
index 945bf3cac4..dd4a738acc 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionTests.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,14 +16,14 @@
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public abstract class AbstractExceptionTests extends AbstractExceptionWithCauseTests {
@Test
- public void testExceptionString() throws Exception {
+ void testExceptionString() throws Exception {
Exception exception = getException("foo");
assertEquals("foo", exception.getMessage());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionWithCauseTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionWithCauseTests.java
index 8b8e50cea7..def90d30b8 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionWithCauseTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/AbstractExceptionWithCauseTests.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,14 +16,14 @@
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public abstract class AbstractExceptionWithCauseTests {
@Test
- public void testExceptionStringThrowable() throws Exception {
+ void testExceptionStringThrowable() throws Exception {
Exception exception = getException("foo", new IllegalStateException());
assertEquals("foo", exception.getMessage().substring(0, 3));
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java
index bbcfa9da0d..2d37584395 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.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,36 +15,35 @@
*/
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
-public class BatchStatusTests {
+class BatchStatusTests {
/**
* Test method for {@link org.springframework.batch.core.BatchStatus#toString()}.
*/
@Test
- public void testToString() {
+ void testToString() {
assertEquals("ABANDONED", BatchStatus.ABANDONED.toString());
}
@Test
- public void testMaxStatus() {
+ void testMaxStatus() {
assertEquals(BatchStatus.FAILED, BatchStatus.max(BatchStatus.FAILED, BatchStatus.COMPLETED));
assertEquals(BatchStatus.FAILED, BatchStatus.max(BatchStatus.COMPLETED, BatchStatus.FAILED));
assertEquals(BatchStatus.FAILED, BatchStatus.max(BatchStatus.FAILED, BatchStatus.FAILED));
@@ -53,13 +52,13 @@ public void testMaxStatus() {
}
@Test
- public void testUpgradeStatusFinished() {
+ void testUpgradeStatusFinished() {
assertEquals(BatchStatus.FAILED, BatchStatus.FAILED.upgradeTo(BatchStatus.COMPLETED));
assertEquals(BatchStatus.FAILED, BatchStatus.COMPLETED.upgradeTo(BatchStatus.FAILED));
}
@Test
- public void testUpgradeStatusUnfinished() {
+ void testUpgradeStatusUnfinished() {
assertEquals(BatchStatus.COMPLETED, BatchStatus.STARTING.upgradeTo(BatchStatus.COMPLETED));
assertEquals(BatchStatus.COMPLETED, BatchStatus.COMPLETED.upgradeTo(BatchStatus.STARTING));
assertEquals(BatchStatus.STARTED, BatchStatus.STARTING.upgradeTo(BatchStatus.STARTED));
@@ -67,7 +66,7 @@ public void testUpgradeStatusUnfinished() {
}
@Test
- public void testIsRunning() {
+ void testIsRunning() {
assertFalse(BatchStatus.FAILED.isRunning());
assertFalse(BatchStatus.COMPLETED.isRunning());
assertTrue(BatchStatus.STARTED.isRunning());
@@ -75,7 +74,7 @@ public void testIsRunning() {
}
@Test
- public void testIsUnsuccessful() {
+ void testIsUnsuccessful() {
assertTrue(BatchStatus.FAILED.isUnsuccessful());
assertFalse(BatchStatus.COMPLETED.isUnsuccessful());
assertFalse(BatchStatus.STARTED.isUnsuccessful());
@@ -83,28 +82,22 @@ public void testIsUnsuccessful() {
}
@Test
- public void testGetStatus() {
+ void testGetStatus() {
assertEquals(BatchStatus.FAILED, BatchStatus.valueOf(BatchStatus.FAILED.toString()));
}
@Test
- public void testGetStatusWrongCode() {
- try {
- BatchStatus.valueOf("foo");
- fail();
- }
- catch (IllegalArgumentException ex) {
- // expected
- }
+ void testGetStatusWrongCode() {
+ assertThrows(IllegalArgumentException.class, () -> BatchStatus.valueOf("foo"));
}
- @Test(expected = NullPointerException.class)
- public void testGetStatusNullCode() {
- assertNull(BatchStatus.valueOf(null));
+ @Test
+ void testGetStatusNullCode() {
+ assertThrows(NullPointerException.class, () -> BatchStatus.valueOf(null));
}
@Test
- public void testSerialization() throws Exception {
+ void testSerialization() throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java
index 18958d7be8..53ee6cbde5 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2021 the original author or authors.
+ * Copyright 2013-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,27 +15,22 @@
*/
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class DefaultJobKeyGeneratorTests {
+class DefaultJobKeyGeneratorTests {
- private JobKeyGenerator jobKeyGenerator;
+ private final JobKeyGenerator jobKeyGenerator = new DefaultJobKeyGenerator();
- @Before
- public void setUp() throws Exception {
- jobKeyGenerator = new DefaultJobKeyGenerator();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNullParameters() {
- jobKeyGenerator.generateKey(null);
+ @Test
+ void testNullParameters() {
+ assertThrows(IllegalArgumentException.class, () -> jobKeyGenerator.generateKey(null));
}
@Test
- public void testMixedParameters() {
+ void testMixedParameters() {
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
JobParameters jobParameters2 = new JobParametersBuilder().addString("foo", "bar", true)
@@ -46,7 +41,7 @@ public void testMixedParameters() {
}
@Test
- public void testCreateJobKey() {
+ void testCreateJobKey() {
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
String key = jobKeyGenerator.generateKey(jobParameters);
@@ -54,7 +49,7 @@ public void testCreateJobKey() {
}
@Test
- public void testCreateJobKeyOrdering() {
+ void testCreateJobKeyOrdering() {
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
String key1 = jobKeyGenerator.generateKey(jobParameters1);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/EntityTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/EntityTests.java
index 9b80fa1c1f..a8ad2e47ff 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/EntityTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/EntityTests.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,121 +15,94 @@
*/
package org.springframework.batch.core;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Dave Syer
*
*/
-public class EntityTests extends TestCase {
+class EntityTests {
- Entity entity = new Entity(11L);
+ private Entity entity = new Entity(11L);
- /**
- * Test method for {@link org.springframework.batch.core.Entity#hashCode()}.
- */
- public void testHashCode() {
+ @Test
+ void testHashCode() {
assertEquals(entity.hashCode(), new Entity(entity.getId()).hashCode());
}
- /**
- * Test method for {@link org.springframework.batch.core.Entity#hashCode()}.
- */
- public void testHashCodeNullId() {
+ @Test
+ void testHashCodeNullId() {
int withoutNull = entity.hashCode();
entity.setId(null);
int withNull = entity.hashCode();
assertTrue(withoutNull != withNull);
}
- /**
- * Test method for {@link org.springframework.batch.core.Entity#getVersion()}.
- */
- public void testGetVersion() {
- assertEquals(null, entity.getVersion());
+ @Test
+ void testGetVersion() {
+ assertNull(entity.getVersion());
}
- /**
- * Test method for {@link org.springframework.batch.core.Entity#getVersion()}.
- */
- public void testIncrementVersion() {
+ @Test
+ void testIncrementVersion() {
entity.incrementVersion();
assertEquals(Integer.valueOf(0), entity.getVersion());
}
- /**
- * Test method for {@link org.springframework.batch.core.Entity#getVersion()}.
- */
- public void testIncrementVersionTwice() {
+ @Test
+ void testIncrementVersionTwice() {
entity.incrementVersion();
entity.incrementVersion();
assertEquals(Integer.valueOf(1), entity.getVersion());
}
- /**
- * @throws Exception
- */
- public void testToString() throws Exception {
+ @Test
+ void testToString() {
Entity job = new Entity();
- assertTrue(job.toString().indexOf("id=null") >= 0);
+ assertTrue(job.toString().contains("id=null"));
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.Entity#equals(java.lang.Object)}.
- */
- public void testEqualsSelf() {
+ @Test
+ void testEqualsSelf() {
assertEquals(entity, entity);
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.Entity#equals(java.lang.Object)}.
- */
- public void testEqualsSelfWithNullId() {
+ @Test
+ void testEqualsSelfWithNullId() {
entity = new Entity(null);
assertEquals(entity, entity);
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.Entity#equals(java.lang.Object)}.
- */
- public void testEqualsEntityWithNullId() {
+ @Test
+ void testEqualsEntityWithNullId() {
entity = new Entity(null);
assertNotSame(entity, new Entity(null));
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.Entity#equals(java.lang.Object)}.
- */
- public void testEqualsEntity() {
+ @Test
+ void testEqualsEntity() {
assertEquals(entity, new Entity(entity.getId()));
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.Entity#equals(java.lang.Object)}.
- */
- public void testEqualsEntityWrongId() {
- assertFalse(entity.equals(new Entity()));
+ @Test
+ void testEqualsEntityWrongId() {
+ assertNotEquals(entity, new Entity());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.Entity#equals(java.lang.Object)}.
- */
- public void testEqualsObject() {
- assertFalse(entity.equals(new Object()));
+ @Test
+ void testEqualsObject() {
+ assertNotEquals(entity, new Object());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.Entity#equals(java.lang.Object)}.
- */
- public void testEqualsNull() {
- assertFalse(entity.equals(null));
+ @Test
+ void testEqualsNull() {
+ assertNotEquals(null, entity);
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java
index 43e73e6f17..ce32d79e05 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java
@@ -15,11 +15,11 @@
*/
package org.springframework.batch.core;
-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.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils;
/**
@@ -27,206 +27,159 @@
* @author Mahmoud Ben Hassine
*
*/
-public class ExitStatusTests {
+class ExitStatusTests {
@Test
- public void testExitStatusNullDescription() {
+ void testExitStatusNullDescription() {
ExitStatus status = new ExitStatus("10", null);
assertEquals("", status.getExitDescription());
}
@Test
- public void testExitStatusBooleanInt() {
+ void testExitStatusBooleanInt() {
ExitStatus status = new ExitStatus("10");
assertEquals("10", status.getExitCode());
}
@Test
- public void testExitStatusConstantsContinuable() {
+ void testExitStatusConstantsContinuable() {
ExitStatus status = ExitStatus.EXECUTING;
assertEquals("EXECUTING", status.getExitCode());
}
@Test
- public void testExitStatusConstantsFinished() {
+ void testExitStatusConstantsFinished() {
ExitStatus status = ExitStatus.COMPLETED;
assertEquals("COMPLETED", status.getExitCode());
}
- /**
- * Test equality of exit statuses.
- * @throws Exception
- */
@Test
- public void testEqualsWithSameProperties() throws Exception {
+ void testEqualsWithSameProperties() {
assertEquals(ExitStatus.EXECUTING, new ExitStatus("EXECUTING"));
}
@Test
- public void testEqualsSelf() {
+ void testEqualsSelf() {
ExitStatus status = new ExitStatus("test");
assertEquals(status, status);
}
@Test
- public void testEquals() {
+ void testEquals() {
assertEquals(new ExitStatus("test"), new ExitStatus("test"));
}
- /**
- * Test equality of exit statuses.
- * @throws Exception
- */
@Test
- public void testEqualsWithNull() throws Exception {
+ void testEqualsWithNull() {
assertFalse(ExitStatus.EXECUTING.equals(null));
}
- /**
- * Test equality of exit statuses.
- * @throws Exception
- */
@Test
- public void testHashcode() throws Exception {
+ void testHashcode() {
assertEquals(ExitStatus.EXECUTING.toString().hashCode(), ExitStatus.EXECUTING.hashCode());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
- * .
- */
@Test
- public void testAndExitStatusStillExecutable() {
+ void testAndExitStatusStillExecutable() {
assertEquals(ExitStatus.EXECUTING.getExitCode(), ExitStatus.EXECUTING.and(ExitStatus.EXECUTING).getExitCode());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
- * .
- */
@Test
- public void testAndExitStatusWhenFinishedAddedToContinuable() {
+ void testAndExitStatusWhenFinishedAddedToContinuable() {
assertEquals(ExitStatus.COMPLETED.getExitCode(), ExitStatus.EXECUTING.and(ExitStatus.COMPLETED).getExitCode());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
- * .
- */
@Test
- public void testAndExitStatusWhenContinuableAddedToFinished() {
+ void testAndExitStatusWhenContinuableAddedToFinished() {
assertEquals(ExitStatus.COMPLETED.getExitCode(), ExitStatus.COMPLETED.and(ExitStatus.EXECUTING).getExitCode());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
- * .
- */
@Test
- public void testAndExitStatusWhenCustomContinuableAddedToContinuable() {
+ void testAndExitStatusWhenCustomContinuableAddedToContinuable() {
assertEquals("CUSTOM", ExitStatus.EXECUTING.and(ExitStatus.EXECUTING.replaceExitCode("CUSTOM")).getExitCode());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
- * .
- */
@Test
- public void testAndExitStatusWhenCustomCompletedAddedToCompleted() {
+ void testAndExitStatusWhenCustomCompletedAddedToCompleted() {
assertEquals("COMPLETED_CUSTOM",
ExitStatus.COMPLETED.and(ExitStatus.EXECUTING.replaceExitCode("COMPLETED_CUSTOM")).getExitCode());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
- * .
- */
@Test
- public void testAndExitStatusFailedPlusFinished() {
+ void testAndExitStatusFailedPlusFinished() {
assertEquals("FAILED", ExitStatus.COMPLETED.and(ExitStatus.FAILED).getExitCode());
assertEquals("FAILED", ExitStatus.FAILED.and(ExitStatus.COMPLETED).getExitCode());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
- * .
- */
@Test
- public void testAndExitStatusWhenCustomContinuableAddedToFinished() {
+ void testAndExitStatusWhenCustomContinuableAddedToFinished() {
assertEquals("CUSTOM", ExitStatus.COMPLETED.and(ExitStatus.EXECUTING.replaceExitCode("CUSTOM")).getExitCode());
}
@Test
- public void testAddExitCode() throws Exception {
+ void testAddExitCode() {
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO");
assertTrue(ExitStatus.EXECUTING != status);
assertEquals("FOO", status.getExitCode());
}
@Test
- public void testAddExitCodeToExistingStatus() throws Exception {
+ void testAddExitCodeToExistingStatus() {
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO").replaceExitCode("BAR");
assertTrue(ExitStatus.EXECUTING != status);
assertEquals("BAR", status.getExitCode());
}
@Test
- public void testAddExitCodeToSameStatus() throws Exception {
+ void testAddExitCodeToSameStatus() {
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode(ExitStatus.EXECUTING.getExitCode());
assertTrue(ExitStatus.EXECUTING != status);
assertEquals(ExitStatus.EXECUTING.getExitCode(), status.getExitCode());
}
@Test
- public void testAddExitDescription() throws Exception {
+ void testAddExitDescription() {
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo");
assertTrue(ExitStatus.EXECUTING != status);
assertEquals("Foo", status.getExitDescription());
}
@Test
- public void testAddExitDescriptionWIthStacktrace() throws Exception {
+ void testAddExitDescriptionWIthStacktrace() {
ExitStatus status = ExitStatus.EXECUTING.addExitDescription(new RuntimeException("Foo"));
assertTrue(ExitStatus.EXECUTING != status);
String description = status.getExitDescription();
- assertTrue("Wrong description: " + description, description.contains("Foo"));
- assertTrue("Wrong description: " + description, description.contains("RuntimeException"));
+ assertTrue(description.contains("Foo"), "Wrong description: " + description);
+ assertTrue(description.contains("RuntimeException"), "Wrong description: " + description);
}
@Test
- public void testAddExitDescriptionToSameStatus() throws Exception {
+ void testAddExitDescriptionToSameStatus() {
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo").addExitDescription("Foo");
assertTrue(ExitStatus.EXECUTING != status);
assertEquals("Foo", status.getExitDescription());
}
@Test
- public void testAddEmptyExitDescription() throws Exception {
+ void testAddEmptyExitDescription() {
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo").addExitDescription((String) null);
assertEquals("Foo", status.getExitDescription());
}
@Test
- public void testAddExitCodeWithDescription() throws Exception {
+ void testAddExitCodeWithDescription() {
ExitStatus status = new ExitStatus("BAR", "Bar").replaceExitCode("FOO");
assertEquals("FOO", status.getExitCode());
assertEquals("Bar", status.getExitDescription());
}
@Test
- public void testUnknownIsRunning() throws Exception {
+ void testUnknownIsRunning() {
assertTrue(ExitStatus.UNKNOWN.isRunning());
}
@Test
- public void testSerializable() {
+ void testSerializable() {
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO");
ExitStatus clone = SerializationUtils.clone(status);
assertEquals(status.getExitCode(), clone.getExitCode());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java
index 3a1694d9b0..084f97e507 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java
@@ -15,17 +15,17 @@
*/
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils;
/**
@@ -34,12 +34,12 @@
* @author Mahmoud Ben Hassine
*
*/
-public class JobExecutionTests {
+class JobExecutionTests {
private JobExecution execution = new JobExecution(new JobInstance(11L, "foo"), 12L, new JobParameters());
@Test
- public void testJobExecution() {
+ void testJobExecution() {
assertNull(new JobExecution(new JobInstance(null, "foo"), null).getId());
}
@@ -47,7 +47,7 @@ public void testJobExecution() {
* Test method for {@link org.springframework.batch.core.JobExecution#getEndTime()}.
*/
@Test
- public void testGetEndTime() {
+ void testGetEndTime() {
assertNull(execution.getEndTime());
execution.setEndTime(new Date(100L));
assertEquals(100L, execution.getEndTime().getTime());
@@ -57,7 +57,7 @@ public void testGetEndTime() {
* Test method for {@link org.springframework.batch.core.JobExecution#getEndTime()}.
*/
@Test
- public void testIsRunning() {
+ void testIsRunning() {
execution.setStartTime(new Date());
assertTrue(execution.isRunning());
execution.setEndTime(new Date(100L));
@@ -68,7 +68,7 @@ public void testIsRunning() {
* Test method for {@link org.springframework.batch.core.JobExecution#getStartTime()}.
*/
@Test
- public void testGetStartTime() {
+ void testGetStartTime() {
execution.setStartTime(new Date(0L));
assertEquals(0L, execution.getStartTime().getTime());
}
@@ -77,7 +77,7 @@ public void testGetStartTime() {
* Test method for {@link org.springframework.batch.core.JobExecution#getStatus()}.
*/
@Test
- public void testGetStatus() {
+ void testGetStatus() {
assertEquals(BatchStatus.STARTING, execution.getStatus());
execution.setStatus(BatchStatus.COMPLETED);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
@@ -87,7 +87,7 @@ public void testGetStatus() {
* Test method for {@link org.springframework.batch.core.JobExecution#getStatus()}.
*/
@Test
- public void testUpgradeStatus() {
+ void testUpgradeStatus() {
assertEquals(BatchStatus.STARTING, execution.getStatus());
execution.upgradeStatus(BatchStatus.COMPLETED);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
@@ -97,7 +97,7 @@ public void testUpgradeStatus() {
* Test method for {@link org.springframework.batch.core.JobExecution#getStatus()}.
*/
@Test
- public void testDowngradeStatus() {
+ void testDowngradeStatus() {
execution.setStatus(BatchStatus.FAILED);
execution.upgradeStatus(BatchStatus.COMPLETED);
assertEquals(BatchStatus.FAILED, execution.getStatus());
@@ -107,7 +107,7 @@ public void testDowngradeStatus() {
* Test method for {@link org.springframework.batch.core.JobExecution#getJobId()}.
*/
@Test
- public void testGetJobId() {
+ void testGetJobId() {
assertEquals(11, execution.getJobId().longValue());
execution = new JobExecution(new JobInstance(23L, "testJob"), null, new JobParameters());
assertEquals(23, execution.getJobId().longValue());
@@ -117,7 +117,7 @@ public void testGetJobId() {
* Test method for {@link org.springframework.batch.core.JobExecution#getJobId()}.
*/
@Test
- public void testGetJobIdForNullJob() {
+ void testGetJobIdForNullJob() {
execution = new JobExecution((JobInstance) null, (JobParameters) null);
assertEquals(null, execution.getJobId());
}
@@ -126,7 +126,7 @@ public void testGetJobIdForNullJob() {
* Test method for {@link org.springframework.batch.core.JobExecution#getJobId()}.
*/
@Test
- public void testGetJob() {
+ void testGetJob() {
assertNotNull(execution.getJobInstance());
}
@@ -135,26 +135,26 @@ public void testGetJob() {
* {@link org.springframework.batch.core.JobExecution#getExitStatus()}.
*/
@Test
- public void testGetExitCode() {
+ void testGetExitCode() {
assertEquals(ExitStatus.UNKNOWN, execution.getExitStatus());
execution.setExitStatus(new ExitStatus("23"));
assertEquals("23", execution.getExitStatus().getExitCode());
}
@Test
- public void testContextContainsInfo() throws Exception {
+ void testContextContainsInfo() throws Exception {
assertEquals("foo", execution.getJobInstance().getJobName());
}
@Test
- public void testAddAndRemoveStepExecution() throws Exception {
+ void testAddAndRemoveStepExecution() throws Exception {
assertEquals(0, execution.getStepExecutions().size());
execution.createStepExecution("step");
assertEquals(1, execution.getStepExecutions().size());
}
@Test
- public void testStepExecutionsWithSameName() throws Exception {
+ void testStepExecutionsWithSameName() throws Exception {
assertEquals(0, execution.getStepExecutions().size());
execution.createStepExecution("step");
assertEquals(1, execution.getStepExecutions().size());
@@ -163,14 +163,14 @@ public void testStepExecutionsWithSameName() throws Exception {
}
@Test
- public void testSetStepExecutions() throws Exception {
+ void testSetStepExecutions() throws Exception {
assertEquals(0, execution.getStepExecutions().size());
execution.addStepExecutions(Arrays.asList(new StepExecution("step", execution)));
assertEquals(1, execution.getStepExecutions().size());
}
@Test
- public void testSetStepExecutionsWithIds() throws Exception {
+ void testSetStepExecutionsWithIds() throws Exception {
assertEquals(0, execution.getStepExecutions().size());
new StepExecution("step", execution, 1L);
assertEquals(1, execution.getStepExecutions().size());
@@ -179,20 +179,20 @@ public void testSetStepExecutionsWithIds() throws Exception {
}
@Test
- public void testToString() throws Exception {
- assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
- assertTrue("JobExecution string does not contain name: " + execution, execution.toString().indexOf("foo") >= 0);
+ void testToString() throws Exception {
+ assertTrue(execution.toString().contains("id="), "JobExecution string does not contain id");
+ assertTrue(execution.toString().contains("foo"), "JobExecution string does not contain name: " + execution);
}
@Test
- public void testToStringWithNullJob() throws Exception {
+ void testToStringWithNullJob() {
execution = new JobExecution(new JobInstance(null, "foo"), null);
- assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
- assertTrue("JobExecution string does not contain job: " + execution, execution.toString().indexOf("job=") >= 0);
+ assertTrue(execution.toString().contains("id="), "JobExecution string does not contain id");
+ assertTrue(execution.toString().contains("job="), "JobExecution string does not contain job: " + execution);
}
@Test
- public void testSerialization() {
+ void testSerialization() {
JobExecution clone = SerializationUtils.clone(execution);
assertEquals(execution, clone);
assertNotNull(clone.createStepExecution("foo"));
@@ -200,7 +200,7 @@ public void testSerialization() {
}
@Test
- public void testFailureExceptions() {
+ void testFailureExceptions() {
RuntimeException exception = new RuntimeException();
assertEquals(0, execution.getFailureExceptions().size());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java
index 4cd433243c..a53f4dfcc5 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java
@@ -15,55 +15,46 @@
*/
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils;
/**
* @author dsyer
*
- */
-public class JobInstanceTests {
+ **/
+class JobInstanceTests {
private JobInstance instance = new JobInstance(11L, "job");
- /**
- * Test method for {@link org.springframework.batch.core.JobInstance#getJobName()}.
- */
@Test
- public void testGetName() {
+ void testGetName() {
instance = new JobInstance(1L, "foo");
assertEquals("foo", instance.getJobName());
}
@Test
- public void testGetJob() {
+ void testGetJob() {
assertEquals("job", instance.getJobName());
}
@Test
- public void testCreateWithNulls() {
- try {
- new JobInstance(null, null);
- fail("job instance can't exist without job specified");
- }
- catch (IllegalArgumentException e) {
- // expected
- }
+ void testCreateWithNulls() {
+ assertThrows(IllegalArgumentException.class, () -> new JobInstance(null, null));
instance = new JobInstance(null, "testJob");
assertEquals("testJob", instance.getJobName());
}
@Test
- public void testSerialization() {
+ void testSerialization() {
instance = new JobInstance(1L, "jobName");
assertEquals(instance, SerializationUtils.clone(instance));
}
@Test
- public void testGetInstanceId() {
+ void testGetInstanceId() {
assertEquals(11, instance.getInstanceId());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.java
index c9433f1919..06fe4335a6 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.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,72 +15,72 @@
*/
package org.springframework.batch.core;
-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.assertThrows;
import java.util.Date;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Lucas Ward
*
*/
-public class JobParameterTests {
+class JobParameterTests {
JobParameter jobParameter;
@Test
- public void testStringParameter() {
+ void testStringParameter() {
jobParameter = new JobParameter("test", true);
assertEquals("test", jobParameter.getValue());
}
- @Test(expected = IllegalArgumentException.class)
- public void testNullStringParameter() {
- jobParameter = new JobParameter((String) null, true);
+ @Test
+ void testNullStringParameter() {
+ assertThrows(IllegalArgumentException.class, () -> new JobParameter((String) null, true));
}
@Test
- public void testLongParameter() {
+ void testLongParameter() {
jobParameter = new JobParameter(1L, true);
assertEquals(1L, jobParameter.getValue());
}
@Test
- public void testDoubleParameter() {
+ void testDoubleParameter() {
jobParameter = new JobParameter(1.1, true);
assertEquals(1.1, jobParameter.getValue());
}
@Test
- public void testDateParameter() {
+ void testDateParameter() {
Date epoch = new Date(0L);
jobParameter = new JobParameter(epoch, true);
assertEquals(new Date(0L), jobParameter.getValue());
}
- @Test(expected = IllegalArgumentException.class)
- public void testNullDateParameter() {
- jobParameter = new JobParameter((Date) null, true);
+ @Test
+ void testNullDateParameter() {
+ assertThrows(IllegalArgumentException.class, () -> new JobParameter((Date) null, true));
}
@Test
- public void testDateParameterToString() {
+ void testDateParameterToString() {
Date epoch = new Date(0L);
jobParameter = new JobParameter(epoch, true);
assertEquals("0", jobParameter.toString());
}
@Test
- public void testEquals() {
+ void testEquals() {
jobParameter = new JobParameter("test", true);
JobParameter testParameter = new JobParameter("test", true);
- assertTrue(jobParameter.equals(testParameter));
+ assertEquals(jobParameter, testParameter);
}
@Test
- public void testHashcode() {
+ void testHashcode() {
jobParameter = new JobParameter("test", true);
JobParameter testParameter = new JobParameter("test", true);
assertEquals(testParameter.hashCode(), jobParameter.hashCode());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersBuilderTests.java
index 6ab52e257d..95934142fd 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersBuilderTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersBuilderTests.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.
@@ -22,16 +22,16 @@
import java.util.Map;
import java.util.Properties;
-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.explore.JobExplorer;
import org.springframework.batch.core.job.SimpleJob;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -43,7 +43,7 @@
* @author Mahmoud Ben Hassine
*
*/
-public class JobParametersBuilderTests {
+class JobParametersBuilderTests {
private JobParametersBuilder parametersBuilder;
@@ -55,10 +55,10 @@ public class JobParametersBuilderTests {
private List jobExecutionList;
- private Date date = new Date(System.currentTimeMillis());
+ private final Date date = new Date(System.currentTimeMillis());
- @Before
- public void initialize() {
+ @BeforeEach
+ void initialize() {
this.job = new SimpleJob("simpleJob");
this.jobExplorer = mock(JobExplorer.class);
this.jobInstanceList = new ArrayList<>(1);
@@ -67,7 +67,7 @@ public void initialize() {
}
@Test
- public void testAddingExistingJobParameters() {
+ void testAddingExistingJobParameters() {
JobParameters params1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "baz")
.toJobParameters();
@@ -82,7 +82,7 @@ public void testAddingExistingJobParameters() {
}
@Test
- public void testNonIdentifyingParameters() {
+ void testNonIdentifyingParameters() {
this.parametersBuilder.addDate("SCHEDULE_DATE", date, false);
this.parametersBuilder.addLong("LONG", 1L, false);
this.parametersBuilder.addString("STRING", "string value", false);
@@ -100,7 +100,7 @@ public void testNonIdentifyingParameters() {
}
@Test
- public void testToJobRuntimeParameters() {
+ void testToJobRuntimeParameters() {
this.parametersBuilder.addDate("SCHEDULE_DATE", date);
this.parametersBuilder.addLong("LONG", 1L);
this.parametersBuilder.addString("STRING", "string value");
@@ -113,7 +113,7 @@ public void testToJobRuntimeParameters() {
}
@Test
- public void testCopy() {
+ void testCopy() {
this.parametersBuilder.addString("STRING", "string value");
this.parametersBuilder = new JobParametersBuilder(this.parametersBuilder.toJobParameters());
Iterator parameters = this.parametersBuilder.toJobParameters().getParameters().keySet().iterator();
@@ -121,7 +121,7 @@ public void testCopy() {
}
@Test
- public void testOrderedTypes() {
+ void testOrderedTypes() {
this.parametersBuilder.addDate("SCHEDULE_DATE", date);
this.parametersBuilder.addLong("LONG", 1L);
this.parametersBuilder.addString("STRING", "string value");
@@ -132,7 +132,7 @@ public void testOrderedTypes() {
}
@Test
- public void testOrderedStrings() {
+ void testOrderedStrings() {
this.parametersBuilder.addString("foo", "value foo");
this.parametersBuilder.addString("bar", "value bar");
this.parametersBuilder.addString("spam", "value spam");
@@ -143,7 +143,7 @@ public void testOrderedStrings() {
}
@Test
- public void testAddJobParameter() {
+ void testAddJobParameter() {
JobParameter jobParameter = new JobParameter("bar");
this.parametersBuilder.addParameter("foo", jobParameter);
Map parameters = this.parametersBuilder.toJobParameters().getParameters();
@@ -152,7 +152,7 @@ public void testAddJobParameter() {
}
@Test
- public void testProperties() {
+ void testProperties() {
Properties props = new Properties();
props.setProperty("SCHEDULE_DATE", "A DATE");
props.setProperty("LONG", "1");
@@ -168,7 +168,7 @@ public void testProperties() {
}
@Test
- public void testGetNextJobParametersFirstRun() {
+ void testGetNextJobParametersFirstRun() {
job.setJobParametersIncrementer(new RunIdIncrementer());
initializeForNextJobParameters();
this.parametersBuilder.getNextJobParameters(this.job);
@@ -176,7 +176,7 @@ public void testGetNextJobParametersFirstRun() {
}
@Test
- public void testGetNextJobParametersNoIncrementer() {
+ void testGetNextJobParametersNoIncrementer() {
initializeForNextJobParameters();
final Exception expectedException = assertThrows(IllegalArgumentException.class,
() -> this.parametersBuilder.getNextJobParameters(this.job));
@@ -184,7 +184,7 @@ public void testGetNextJobParametersNoIncrementer() {
}
@Test
- public void testGetNextJobParameters() {
+ void testGetNextJobParameters() {
this.job.setJobParametersIncrementer(new RunIdIncrementer());
this.jobInstanceList.add(new JobInstance(1L, "simpleJobInstance"));
this.jobExecutionList.add(getJobExecution(this.jobInstanceList.get(0), null));
@@ -196,7 +196,7 @@ public void testGetNextJobParameters() {
}
@Test
- public void testGetNextJobParametersRestartable() {
+ void testGetNextJobParametersRestartable() {
this.job.setRestartable(true);
this.job.setJobParametersIncrementer(new RunIdIncrementer());
this.jobInstanceList.add(new JobInstance(1L, "simpleJobInstance"));
@@ -210,7 +210,7 @@ public void testGetNextJobParametersRestartable() {
}
@Test
- public void testGetNextJobParametersNoPreviousExecution() {
+ void testGetNextJobParametersNoPreviousExecution() {
this.job.setJobParametersIncrementer(new RunIdIncrementer());
this.jobInstanceList.add(new JobInstance(1L, "simpleJobInstance"));
when(this.jobExplorer.getJobInstances("simpleJob", 0, 1)).thenReturn(this.jobInstanceList);
@@ -220,10 +220,10 @@ public void testGetNextJobParametersNoPreviousExecution() {
baseJobParametersVerify(this.parametersBuilder.toJobParameters(), 4);
}
- @Test(expected = IllegalStateException.class)
- public void testMissingJobExplorer() {
+ @Test
+ void testMissingJobExplorer() {
this.parametersBuilder = new JobParametersBuilder();
- this.parametersBuilder.getNextJobParameters(this.job);
+ assertThrows(IllegalStateException.class, () -> this.parametersBuilder.getNextJobParameters(this.job));
}
private void initializeForNextJobParameters() {
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java
index bfb61d8b5c..2203754c70 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java
@@ -15,18 +15,18 @@
*/
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils;
/**
@@ -37,7 +37,7 @@
* @author Taeik Lim
*
*/
-public class JobParametersTests {
+class JobParametersTests {
JobParameters parameters;
@@ -45,8 +45,8 @@ public class JobParametersTests {
Date date2 = new Date(7809089900L);
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
parameters = getNewParameters();
}
@@ -66,77 +66,77 @@ private JobParameters getNewParameters() {
}
@Test
- public void testGetString() {
+ void testGetString() {
assertEquals("value1", parameters.getString("string.key1"));
assertEquals("value2", parameters.getString("string.key2"));
}
@Test
- public void testGetLong() {
+ void testGetLong() {
assertEquals(1L, parameters.getLong("long.key1").longValue());
assertEquals(2L, parameters.getLong("long.key2").longValue());
}
@Test
- public void testGetDouble() {
+ void testGetDouble() {
assertEquals(Double.valueOf(1.1d), parameters.getDouble("double.key1"));
assertEquals(Double.valueOf(2.2d), parameters.getDouble("double.key2"));
}
@Test
- public void testGetDate() {
+ void testGetDate() {
assertEquals(date1, parameters.getDate("date.key1"));
assertEquals(date2, parameters.getDate("date.key2"));
}
@Test
- public void testGetMissingLong() {
+ void testGetMissingLong() {
assertNull(parameters.getLong("missing.long1"));
}
@Test
- public void testGetMissingDouble() {
+ void testGetMissingDouble() {
assertNull(parameters.getDouble("missing.double1"));
}
@Test
- public void testIsEmptyWhenEmpty() throws Exception {
+ void testIsEmptyWhenEmpty() throws Exception {
assertTrue(new JobParameters().isEmpty());
}
@Test
- public void testIsEmptyWhenNotEmpty() throws Exception {
+ void testIsEmptyWhenNotEmpty() throws Exception {
assertFalse(parameters.isEmpty());
}
@Test
- public void testEquals() {
+ void testEquals() {
JobParameters testParameters = getNewParameters();
assertTrue(testParameters.equals(parameters));
}
@Test
- public void testEqualsSelf() {
+ void testEqualsSelf() {
assertTrue(parameters.equals(parameters));
}
@Test
- public void testEqualsDifferent() {
+ void testEqualsDifferent() {
assertFalse(parameters.equals(new JobParameters()));
}
@Test
- public void testEqualsWrongType() {
+ void testEqualsWrongType() {
assertFalse(parameters.equals("foo"));
}
@Test
- public void testEqualsNull() {
+ void testEqualsNull() {
assertFalse(parameters.equals(null));
}
@Test
- public void testToStringOrder() {
+ void testToStringOrder() {
Map props = parameters.getParameters();
StringBuilder stringBuilder = new StringBuilder();
@@ -169,40 +169,40 @@ public void testToStringOrder() {
}
@Test
- public void testHashCodeEqualWhenEmpty() throws Exception {
+ void testHashCodeEqualWhenEmpty() throws Exception {
int code = new JobParameters().hashCode();
assertEquals(code, new JobParameters().hashCode());
}
@Test
- public void testHashCodeEqualWhenNotEmpty() throws Exception {
+ void testHashCodeEqualWhenNotEmpty() throws Exception {
int code = getNewParameters().hashCode();
assertEquals(code, parameters.hashCode());
}
@Test
- public void testSerialization() {
+ void testSerialization() {
JobParameters params = getNewParameters();
assertEquals(params, SerializationUtils.clone(params));
}
@Test
- public void testLongReturnsNullWhenKeyDoesntExit() {
+ void testLongReturnsNullWhenKeyDoesntExit() {
assertNull(new JobParameters().getLong("keythatdoesntexist"));
}
@Test
- public void testStringReturnsNullWhenKeyDoesntExit() {
+ void testStringReturnsNullWhenKeyDoesntExit() {
assertNull(new JobParameters().getString("keythatdoesntexist"));
}
@Test
- public void testDoubleReturnsNullWhenKeyDoesntExit() {
+ void testDoubleReturnsNullWhenKeyDoesntExit() {
assertNull(new JobParameters().getDouble("keythatdoesntexist"));
}
@Test
- public void testDateReturnsNullWhenKeyDoesntExit() {
+ void testDateReturnsNullWhenKeyDoesntExit() {
assertNull(new JobParameters().getDate("keythatdoesntexist"));
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/SpringBeanJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/SpringBeanJobTests.java
index 1df1f85ffa..c47fd72c0c 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/SpringBeanJobTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/SpringBeanJobTests.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,10 +16,10 @@
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.ChildBeanDefinition;
@@ -27,10 +27,10 @@
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.StaticApplicationContext;
-public class SpringBeanJobTests {
+class SpringBeanJobTests {
@Test
- public void testBeanName() throws Exception {
+ void testBeanName() {
StaticApplicationContext context = new StaticApplicationContext();
JobSupport configuration = new JobSupport();
context.getAutowireCapableBeanFactory().initializeBean(configuration, "bean");
@@ -43,7 +43,7 @@ public void testBeanName() throws Exception {
}
@Test
- public void testBeanNameWithBeanDefinition() throws Exception {
+ void testBeanNameWithBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues args = new ConstructorArgumentValues();
args.addGenericArgumentValue("foo");
@@ -59,7 +59,7 @@ public void testBeanNameWithBeanDefinition() throws Exception {
}
@Test
- public void testBeanNameWithParentBeanDefinition() throws Exception {
+ void testBeanNameWithParentBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues args = new ConstructorArgumentValues();
args.addGenericArgumentValue("bar");
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/StepContributionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/StepContributionTests.java
index d5deab2a3b..cc39b005da 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/StepContributionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/StepContributionTests.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,37 +15,35 @@
*/
package org.springframework.batch.core;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
* @author Dave Syer
*
*/
-public class StepContributionTests extends TestCase {
+class StepContributionTests {
- private StepExecution execution = new StepExecution("step", null);
+ private final StepExecution execution = new StepExecution("step", null);
- private StepContribution contribution = new StepContribution(execution);
+ private final StepContribution contribution = new StepContribution(execution);
- /**
- * Test method for
- * {@link org.springframework.batch.core.StepContribution#incrementFilterCount(int)} .
- */
- public void testIncrementFilterCount() {
+ @Test
+ void testIncrementFilterCount() {
assertEquals(0, contribution.getFilterCount());
contribution.incrementFilterCount(1);
assertEquals(1, contribution.getFilterCount());
}
@Test
- public void testEqualsNull() throws Exception {
- assertFalse(contribution.equals(null));
+ void testEqualsNull() {
+ assertNotEquals(null, contribution);
}
@Test
- public void testEqualsAnother() throws Exception {
+ void testEqualsAnother() {
assertEquals(new StepExecution("foo", null).createStepContribution(), contribution);
assertEquals(new StepExecution("foo", null).createStepContribution().hashCode(), contribution.hashCode());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java
index e01d539fa6..69360ddabf 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java
@@ -15,19 +15,20 @@
*/
package org.springframework.batch.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
-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.step.StepSupport;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.util.SerializationUtils;
@@ -37,26 +38,26 @@
* @author Mahmoud Ben Hassine
*
*/
-public class StepExecutionTests {
+class StepExecutionTests {
private StepExecution execution = newStepExecution(new StepSupport("stepName"), 23L);
- private StepExecution blankExecution = newStepExecution(new StepSupport("blank"), null);
+ private final StepExecution blankExecution = newStepExecution(new StepSupport("blank"), null);
- private ExecutionContext foobarEc = new ExecutionContext();
+ private final ExecutionContext foobarEc = new ExecutionContext();
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
foobarEc.put("foo", "bar");
}
@Test
- public void testStepExecution() {
+ void testStepExecution() {
assertNull(new StepExecution("step", null).getId());
}
@Test
- public void testStepExecutionWithNullId() {
+ void testStepExecutionWithNullId() {
assertNull(new StepExecution("stepName", new JobExecution(new JobInstance(null, "foo"), null)).getId());
}
@@ -64,7 +65,7 @@ public void testStepExecutionWithNullId() {
* Test method for {@link org.springframework.batch.core.JobExecution#getEndTime()}.
*/
@Test
- public void testGetEndTime() {
+ void testGetEndTime() {
assertNull(execution.getEndTime());
execution.setEndTime(new Date(0L));
assertEquals(0L, execution.getEndTime().getTime());
@@ -74,7 +75,7 @@ public void testGetEndTime() {
* Test method for {@link StepExecution#getCreateTime()}.
*/
@Test
- public void testGetCreateTime() {
+ void testGetCreateTime() {
assertNotNull(execution.getCreateTime());
execution.setCreateTime(new Date(10L));
assertEquals(10L, execution.getCreateTime().getTime());
@@ -84,7 +85,7 @@ public void testGetCreateTime() {
* Test method for {@link org.springframework.batch.core.JobExecution#getStatus()}.
*/
@Test
- public void testGetStatus() {
+ void testGetStatus() {
assertEquals(BatchStatus.STARTING, execution.getStatus());
execution.setStatus(BatchStatus.COMPLETED);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
@@ -94,7 +95,7 @@ public void testGetStatus() {
* Test method for {@link org.springframework.batch.core.JobExecution#getJobId()}.
*/
@Test
- public void testGetJobId() {
+ void testGetJobId() {
assertEquals(23, execution.getJobExecutionId().longValue());
}
@@ -103,7 +104,7 @@ public void testGetJobId() {
* {@link org.springframework.batch.core.JobExecution#getExitStatus()}.
*/
@Test
- public void testGetExitCode() {
+ void testGetExitCode() {
assertEquals(ExitStatus.EXECUTING, execution.getExitStatus());
execution.setExitStatus(ExitStatus.COMPLETED);
assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
@@ -114,24 +115,24 @@ public void testGetExitCode() {
* {@link org.springframework.batch.core.StepExecution#getCommitCount()}.
*/
@Test
- public void testGetCommitCount() {
+ void testGetCommitCount() {
execution.setCommitCount(123);
assertEquals(123, execution.getCommitCount());
}
@Test
- public void testGetFilterCount() {
+ void testGetFilterCount() {
execution.setFilterCount(123);
assertEquals(123, execution.getFilterCount());
}
@Test
- public void testGetJobExecution() throws Exception {
+ void testGetJobExecution() {
assertNotNull(execution.getJobExecution());
}
@Test
- public void testApplyContribution() throws Exception {
+ void testApplyContribution() {
StepContribution contribution = execution.createStepContribution();
contribution.incrementReadSkipCount();
contribution.incrementWriteSkipCount();
@@ -147,35 +148,29 @@ public void testApplyContribution() throws Exception {
}
@Test
- public void testTerminateOnly() throws Exception {
+ void testTerminateOnly() {
assertFalse(execution.isTerminateOnly());
execution.setTerminateOnly();
assertTrue(execution.isTerminateOnly());
}
@Test
- public void testNullNameIsIllegal() throws Exception {
- try {
- new StepExecution(null, new JobExecution(new JobInstance(null, "job"), null));
- fail();
- }
- catch (IllegalArgumentException e) {
- // expected
- }
+ void testNullNameIsIllegal() {
+ assertThrows(IllegalArgumentException.class,
+ () -> new StepExecution(null, new JobExecution(new JobInstance(null, "job"), null)));
}
@Test
- public void testToString() throws Exception {
- assertTrue("Should contain read count: " + execution.toString(), execution.toString().indexOf("read") >= 0);
- assertTrue("Should contain write count: " + execution.toString(), execution.toString().indexOf("write") >= 0);
- assertTrue("Should contain filter count: " + execution.toString(), execution.toString().indexOf("filter") >= 0);
- assertTrue("Should contain commit count: " + execution.toString(), execution.toString().indexOf("commit") >= 0);
- assertTrue("Should contain rollback count: " + execution.toString(),
- execution.toString().indexOf("rollback") >= 0);
+ void testToString() throws Exception {
+ assertTrue(execution.toString().contains("read"), "Should contain read count: " + execution.toString());
+ assertTrue(execution.toString().contains("write"), "Should contain write count: " + execution.toString());
+ assertTrue(execution.toString().contains("filter"), "Should contain filter count: " + execution.toString());
+ assertTrue(execution.toString().contains("commit"), "Should contain commit count: " + execution.toString());
+ assertTrue(execution.toString().contains("rollback"), "Should contain rollback count: " + execution.toString());
}
@Test
- public void testExecutionContext() throws Exception {
+ void testExecutionContext() {
assertNotNull(execution.getExecutionContext());
ExecutionContext context = new ExecutionContext();
context.putString("foo", "bar");
@@ -184,15 +179,15 @@ public void testExecutionContext() throws Exception {
}
@Test
- public void testEqualsWithSameName() throws Exception {
+ void testEqualsWithSameName() {
Step step = new StepSupport("stepName");
Entity stepExecution1 = newStepExecution(step, 11L, 4L);
Entity stepExecution2 = newStepExecution(step, 11L, 5L);
- assertFalse(stepExecution1.equals(stepExecution2));
+ assertNotEquals(stepExecution1, stepExecution2);
}
@Test
- public void testEqualsWithSameIdentifier() throws Exception {
+ void testEqualsWithSameIdentifier() {
Step step = new StepSupport("stepName");
Entity stepExecution1 = newStepExecution(step, 11L);
Entity stepExecution2 = newStepExecution(step, 11L);
@@ -200,57 +195,57 @@ public void testEqualsWithSameIdentifier() throws Exception {
}
@Test
- public void testEqualsWithNull() throws Exception {
+ void testEqualsWithNull() {
Entity stepExecution = newStepExecution(new StepSupport("stepName"), 11L);
- assertFalse(stepExecution.equals(null));
+ assertNotEquals(null, stepExecution);
}
@Test
- public void testEqualsWithNullIdentifiers() throws Exception {
+ void testEqualsWithNullIdentifiers() {
Entity stepExecution = newStepExecution(new StepSupport("stepName"), 11L);
- assertFalse(stepExecution.equals(blankExecution));
+ assertNotEquals(stepExecution, blankExecution);
}
@Test
- public void testEqualsWithNullJob() throws Exception {
+ void testEqualsWithNullJob() {
Entity stepExecution = newStepExecution(new StepSupport("stepName"), 11L);
- assertFalse(stepExecution.equals(blankExecution));
+ assertNotEquals(stepExecution, blankExecution);
}
@Test
- public void testEqualsWithSelf() throws Exception {
- assertTrue(execution.equals(execution));
+ void testEqualsWithSelf() {
+ assertEquals(execution, execution);
}
@Test
- public void testEqualsWithDifferent() throws Exception {
+ void testEqualsWithDifferent() {
Entity stepExecution = newStepExecution(new StepSupport("foo"), 13L);
- assertFalse(execution.equals(stepExecution));
+ assertNotEquals(execution, stepExecution);
}
@Test
- public void testEqualsWithNullStepId() throws Exception {
+ void testEqualsWithNullStepId() {
Step step = new StepSupport("name");
execution = newStepExecution(step, 31L);
assertEquals("name", execution.getStepName());
StepExecution stepExecution = newStepExecution(step, 31L);
assertEquals(stepExecution.getJobExecutionId(), execution.getJobExecutionId());
- assertTrue(execution.equals(stepExecution));
+ assertEquals(execution, stepExecution);
}
@Test
- public void testHashCode() throws Exception {
- assertTrue("Hash code same as parent", new Entity(execution.getId()).hashCode() != execution.hashCode());
+ void testHashCode() {
+ assertTrue(new Entity(execution.getId()).hashCode() != execution.hashCode(), "Hash code same as parent");
}
@Test
- public void testHashCodeWithNullIds() throws Exception {
- assertTrue("Hash code not same as parent",
- new Entity(execution.getId()).hashCode() != blankExecution.hashCode());
+ void testHashCodeWithNullIds() {
+ assertTrue(new Entity(execution.getId()).hashCode() != blankExecution.hashCode(),
+ "Hash code not same as parent");
}
@Test
- public void testHashCodeViaHashSet() throws Exception {
+ void testHashCodeViaHashSet() {
Set set = new HashSet<>();
set.add(execution);
assertTrue(set.contains(execution));
@@ -259,7 +254,7 @@ public void testHashCodeViaHashSet() throws Exception {
}
@Test
- public void testSerialization() {
+ void testSerialization() {
ExitStatus status = ExitStatus.NOOP;
execution.setExitStatus(status);
@@ -273,7 +268,7 @@ public void testSerialization() {
}
@Test
- public void testAddException() throws Exception {
+ void testAddException() {
RuntimeException exception = new RuntimeException();
assertEquals(0, execution.getFailureExceptions().size());
@@ -286,7 +281,7 @@ public void testAddException() throws Exception {
* Test method for {@link org.springframework.batch.core.JobExecution#getStatus()}.
*/
@Test
- public void testDowngradeStatus() {
+ void testDowngradeStatus() {
execution.setStatus(BatchStatus.FAILED);
execution.upgradeStatus(BatchStatus.COMPLETED);
assertEquals(BatchStatus.FAILED, execution.getStatus());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java
index aa2c47433d..20d526216e 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java
@@ -17,43 +17,36 @@
import javax.sql.DataSource;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
-import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobLauncher;
-import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
-import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
-import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.repeat.RepeatStatus;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
-@RunWith(SpringRunner.class)
-@ContextConfiguration
-@Ignore // FIXME review this as part of issue 3942
-public class InlineDataSourceDefinitionTests {
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@SpringJUnitConfig
+@Disabled // FIXME review this as part of issue 3942
+class InlineDataSourceDefinitionTests {
@Test
- public void testInlineDataSourceDefinition() throws Exception {
+ void testInlineDataSourceDefinition() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MyJobConfiguration.class);
Job job = applicationContext.getBean(Job.class);
JobLauncher jobLauncher = applicationContext.getBean(JobLauncher.class);
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
- Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
+ assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
@Configuration
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java
index 29085b42c1..b10ef54d6c 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.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,11 +16,11 @@
package org.springframework.batch.core.configuration.annotation;
-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.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
@@ -52,35 +52,33 @@ public class JobBuilderConfigurationTests {
public static boolean fail = false;
- private JobExecution execution;
-
@Test
- public void testVanillaBatchConfiguration() throws Exception {
+ void testVanillaBatchConfiguration() throws Exception {
testJob(BatchStatus.COMPLETED, 2, TestConfiguration.class);
}
@Test
- public void testConfigurerAsConfiguration() throws Exception {
+ void testConfigurerAsConfiguration() throws Exception {
testJob(BatchStatus.COMPLETED, 1, TestConfigurer.class);
}
@Test
- public void testConfigurerAsBean() throws Exception {
+ void testConfigurerAsBean() throws Exception {
testJob(BatchStatus.COMPLETED, 1, BeansConfigurer.class);
}
@Test
- public void testTwoConfigurations() throws Exception {
+ void testTwoConfigurations() throws Exception {
testJob("testJob", BatchStatus.COMPLETED, 2, TestConfiguration.class, AnotherConfiguration.class);
}
@Test
- public void testTwoConfigurationsAndConfigurer() throws Exception {
+ void testTwoConfigurationsAndConfigurer() throws Exception {
testJob("testJob", BatchStatus.COMPLETED, 2, TestConfiguration.class, TestConfigurer.class);
}
@Test
- public void testTwoConfigurationsAndBeansConfigurer() throws Exception {
+ void testTwoConfigurationsAndBeansConfigurer() throws Exception {
testJob("testJob", BatchStatus.COMPLETED, 2, TestConfiguration.class, BeansConfigurer.class);
}
@@ -97,7 +95,7 @@ private void testJob(String jobName, BatchStatus status, int stepExecutionCount,
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
Job job = jobName == null ? context.getBean(Job.class) : context.getBean(jobName, Job.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
- execution = jobLauncher.run(job, new JobParametersBuilder()
+ JobExecution execution = jobLauncher.run(job, new JobParametersBuilder()
.addLong("run.id", (long) (Math.random() * Long.MAX_VALUE)).toJobParameters());
assertEquals(status, execution.getStatus());
assertEquals(stepExecutionCount, execution.getStepExecutions().size());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java
index 6d961b71c8..e98f46492f 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2021 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,11 +15,11 @@
*/
package org.springframework.batch.core.configuration.annotation;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.annotation.PostConstruct;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
@@ -49,17 +49,15 @@
* @author Mahmoud Ben Hassine
*
*/
-public class JobLoaderConfigurationTests {
-
- private JobExecution execution;
+class JobLoaderConfigurationTests {
@Test
- public void testJobLoader() throws Exception {
+ void testJobLoader() throws Exception {
testJob("test", BatchStatus.COMPLETED, 2, LoaderFactoryConfiguration.class);
}
@Test
- public void testJobLoaderWithArray() throws Exception {
+ void testJobLoaderWithArray() throws Exception {
testJob("test", BatchStatus.COMPLETED, 2, LoaderRegistrarConfiguration.class);
}
@@ -72,7 +70,7 @@ private void testJob(String jobName, BatchStatus status, int stepExecutionCount,
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
Job job = jobName == null ? context.getBean(Job.class) : context.getBean(JobLocator.class).getJob(jobName);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
- execution = jobLauncher.run(job, new JobParametersBuilder()
+ JobExecution execution = jobLauncher.run(job, new JobParametersBuilder()
.addLong("run.id", (long) (Math.random() * Long.MAX_VALUE)).toJobParameters());
assertEquals(status, execution.getStatus());
assertEquals(stepExecutionCount, execution.getStepExecutions().size());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java
index 8f635ed76b..bbd043477a 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java
@@ -16,15 +16,15 @@
package org.springframework.batch.core.configuration.annotation;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.Callable;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+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.core.JobInstance;
@@ -59,7 +59,7 @@ public class JobScopeConfigurationTests {
private JobExecution jobExecution;
@Test
- public void testXmlJobScopeWithProxyTargetClass() throws Exception {
+ void testXmlJobScopeWithProxyTargetClass() throws Exception {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsProxyTargetClass-context.xml");
JobSynchronizationManager.register(jobExecution);
@@ -68,7 +68,7 @@ public void testXmlJobScopeWithProxyTargetClass() throws Exception {
}
@Test
- public void testXmlJobScopeWithInterface() throws Exception {
+ void testXmlJobScopeWithInterface() throws Exception {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsInterface-context.xml");
JobSynchronizationManager.register(jobExecution);
@@ -78,7 +78,7 @@ public void testXmlJobScopeWithInterface() throws Exception {
}
@Test
- public void testXmlJobScopeWithInheritance() throws Exception {
+ void testXmlJobScopeWithInheritance() throws Exception {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsInheritance-context.xml");
JobSynchronizationManager.register(jobExecution);
@@ -87,14 +87,14 @@ public void testXmlJobScopeWithInheritance() throws Exception {
}
@Test
- public void testJobScopeWithProxyTargetClass() throws Exception {
+ void testJobScopeWithProxyTargetClass() throws Exception {
init(JobScopeConfigurationRequiringProxyTargetClass.class);
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
}
@Test
- public void testStepScopeXmlImportUsingNamespace() throws Exception {
+ void testStepScopeXmlImportUsingNamespace() throws Exception {
init(JobScopeConfigurationXmlImportUsingNamespace.class);
SimpleHolder value = (SimpleHolder) context.getBean("xmlValue");
@@ -104,17 +104,17 @@ public void testStepScopeXmlImportUsingNamespace() throws Exception {
}
@Test
- public void testJobScopeWithProxyTargetClassInjected() throws Exception {
+ void testJobScopeWithProxyTargetClassInjected() throws Exception {
init(JobScopeConfigurationInjectingProxy.class);
SimpleHolder value = context.getBean(Wrapper.class).getValue();
assertEquals("JOB", value.call());
}
@Test
- public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
+ void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
init(JobScopeConfigurationRequiringProxyTargetClass.class);
JobSynchronizationManager.release();
- final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
+ final Exception expectedException = assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
});
@@ -124,10 +124,10 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
}
@Test
- public void testIntentionallyBlowupWithForcedInterface() throws Exception {
+ void testIntentionallyBlowupWithForcedInterface() throws Exception {
init(JobScopeConfigurationForcingInterfaceProxy.class);
JobSynchronizationManager.release();
- final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
+ final Exception expectedException = assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
});
@@ -137,7 +137,7 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
}
@Test
- public void testJobScopeWithDefaults() throws Exception {
+ void testJobScopeWithDefaults() throws Exception {
init(JobScopeConfigurationWithDefaults.class);
@SuppressWarnings("unchecked")
Callable value = context.getBean(Callable.class);
@@ -145,10 +145,10 @@ public void testJobScopeWithDefaults() throws Exception {
}
@Test
- public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
+ void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
init(JobScopeConfigurationWithDefaults.class);
JobSynchronizationManager.release();
- final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
+ final Exception expectedException = assertThrows(BeanCreationException.class, () -> {
@SuppressWarnings("unchecked")
Callable value = context.getBean(Callable.class);
assertEquals("JOB", value.call());
@@ -169,14 +169,14 @@ public void init(Class>... config) throws Exception {
JobSynchronizationManager.register(jobExecution);
}
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
JobSynchronizationManager.release();
jobExecution = new JobExecution(new JobInstance(5l, "JOB"), null, null);
}
- @After
- public void close() {
+ @AfterEach
+ void close() {
JobSynchronizationManager.release();
if (context != null) {
context.close();
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java
index 4eb5cfd2fe..ecce86bede 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTests.java
@@ -16,10 +16,9 @@
package org.springframework.batch.core.configuration.annotation;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.scope.context.ChunkContext;
@@ -41,8 +40,9 @@
import java.util.concurrent.Callable;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Dave Syer
@@ -57,7 +57,7 @@ public class StepScopeConfigurationTests {
private StepExecution stepExecution;
@Test
- public void testXmlStepScopeWithProxyTargetClass() throws Exception {
+ void testXmlStepScopeWithProxyTargetClass() throws Exception {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsProxyTargetClass-context.xml");
StepSynchronizationManager.register(stepExecution);
@@ -66,7 +66,7 @@ public void testXmlStepScopeWithProxyTargetClass() throws Exception {
}
@Test
- public void testXmlStepScopeWithInterface() throws Exception {
+ void testXmlStepScopeWithInterface() throws Exception {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsInterface-context.xml");
StepSynchronizationManager.register(stepExecution);
@@ -76,7 +76,7 @@ public void testXmlStepScopeWithInterface() throws Exception {
}
@Test
- public void testXmlStepScopeWithInheritance() throws Exception {
+ void testXmlStepScopeWithInheritance() throws Exception {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsInheritance-context.xml");
StepSynchronizationManager.register(stepExecution);
@@ -85,14 +85,14 @@ public void testXmlStepScopeWithInheritance() throws Exception {
}
@Test
- public void testStepScopeWithProxyTargetClass() throws Exception {
+ void testStepScopeWithProxyTargetClass() throws Exception {
init(StepScopeConfigurationRequiringProxyTargetClass.class);
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
}
@Test
- public void testStepScopeXmlImportUsingNamespace() throws Exception {
+ void testStepScopeXmlImportUsingNamespace() throws Exception {
init(StepScopeConfigurationXmlImportUsingNamespace.class);
SimpleHolder value = (SimpleHolder) context.getBean("xmlValue");
@@ -102,18 +102,18 @@ public void testStepScopeXmlImportUsingNamespace() throws Exception {
}
@Test
- public void testStepScopeWithProxyTargetClassInjected() throws Exception {
+ void testStepScopeWithProxyTargetClassInjected() throws Exception {
init(StepScopeConfigurationInjectingProxy.class);
SimpleHolder value = context.getBean(Wrapper.class).getValue();
assertEquals("STEP", value.call());
}
@Test
- public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
+ void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
init(StepScopeConfigurationRequiringProxyTargetClass.class);
StepSynchronizationManager.release();
- final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
+ final Exception expectedException = assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
});
@@ -123,10 +123,10 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
}
@Test
- public void testIntentionallyBlowupWithForcedInterface() throws Exception {
+ void testIntentionallyBlowupWithForcedInterface() throws Exception {
init(StepScopeConfigurationForcingInterfaceProxy.class);
StepSynchronizationManager.release();
- final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
+ final Exception expectedException = assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
});
@@ -136,7 +136,7 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
}
@Test
- public void testStepScopeWithDefaults() throws Exception {
+ void testStepScopeWithDefaults() throws Exception {
init(StepScopeConfigurationWithDefaults.class);
@SuppressWarnings("unchecked")
Callable value = context.getBean(Callable.class);
@@ -144,11 +144,11 @@ public void testStepScopeWithDefaults() throws Exception {
}
@Test
- public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
+ void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
init(StepScopeConfigurationWithDefaults.class);
StepSynchronizationManager.release();
- final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
+ final Exception expectedException = assertThrows(BeanCreationException.class, () -> {
@SuppressWarnings("unchecked")
Callable value = context.getBean(Callable.class);
assertEquals("STEP", value.call());
@@ -169,14 +169,14 @@ public void init(Class>... config) throws Exception {
StepSynchronizationManager.register(stepExecution);
}
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
StepSynchronizationManager.release();
stepExecution = new StepExecution("STEP", null);
}
- @After
- public void close() {
+ @AfterEach
+ void close() {
StepSynchronizationManager.release();
if (context != null) {
context.close();
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationTests.java
index 03a8bc1693..9e45dcac00 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationTests.java
@@ -18,12 +18,11 @@
import javax.sql.DataSource;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.aop.Advisor;
-import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
@@ -33,8 +32,8 @@
/**
* @author Mahmoud Ben Hassine
*/
-@RunWith(MockitoJUnitRunner.class)
-public abstract class TransactionManagerConfigurationTests {
+@ExtendWith(MockitoExtension.class)
+abstract class TransactionManagerConfigurationTests {
@Mock
protected static PlatformTransactionManager transactionManager;
@@ -53,8 +52,7 @@ PlatformTransactionManager getTransactionManagerSetOnJobRepository(JobRepository
// AbstractJobRepositoryFactoryBean.initializeProxy
Advisor[] advisors = target.getAdvisors();
for (Advisor advisor : advisors) {
- if (advisor.getAdvice() instanceof TransactionInterceptor) {
- TransactionInterceptor transactionInterceptor = (TransactionInterceptor) advisor.getAdvice();
+ if (advisor.getAdvice() instanceof TransactionInterceptor transactionInterceptor) {
return (PlatformTransactionManager) transactionInterceptor.getTransactionManager();
}
}
@@ -62,10 +60,9 @@ PlatformTransactionManager getTransactionManagerSetOnJobRepository(JobRepository
}
static DataSource createDataSource() {
- return new EmbeddedDatabaseBuilder()
+ return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
- .addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true)
- .build();
+ .addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql").build();
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java
index 90a667807b..97b459b0b4 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java
@@ -18,13 +18,9 @@
import javax.sql.DataSource;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import org.springframework.batch.core.Job;
import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.repeat.RepeatStatus;
-import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -33,34 +29,38 @@
import org.springframework.test.util.AopTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
/**
* @author Mahmoud Ben Hassine
*/
-public class TransactionManagerConfigurationWithBatchConfigurerTests extends TransactionManagerConfigurationTests {
+class TransactionManagerConfigurationWithBatchConfigurerTests extends TransactionManagerConfigurationTests {
@Test
- public void testConfigurationWithDataSourceAndNoTransactionManager() throws Exception {
+ void testConfigurationWithDataSourceAndNoTransactionManager() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
BatchConfigurationWithDataSourceAndNoTransactionManager.class);
BatchConfigurer batchConfigurer = applicationContext.getBean(BatchConfigurer.class);
PlatformTransactionManager platformTransactionManager = batchConfigurer.getTransactionManager();
- Assert.assertTrue(platformTransactionManager instanceof JdbcTransactionManager);
+ assertTrue(platformTransactionManager instanceof JdbcTransactionManager);
JdbcTransactionManager JdbcTransactionManager = AopTestUtils.getTargetObject(platformTransactionManager);
- Assert.assertEquals(applicationContext.getBean(DataSource.class), JdbcTransactionManager.getDataSource());
- Assert.assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)),
+ assertEquals(applicationContext.getBean(DataSource.class), JdbcTransactionManager.getDataSource());
+ assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)),
platformTransactionManager);
}
@Test
- public void testConfigurationWithDataSourceAndTransactionManager() throws Exception {
+ void testConfigurationWithDataSourceAndTransactionManager() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
BatchConfigurationWithDataSourceAndTransactionManager.class);
BatchConfigurer batchConfigurer = applicationContext.getBean(BatchConfigurer.class);
PlatformTransactionManager platformTransactionManager = batchConfigurer.getTransactionManager();
- Assert.assertSame(transactionManager, platformTransactionManager);
- Assert.assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)),
+ assertSame(transactionManager, platformTransactionManager);
+ assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)),
transactionManager);
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java
index f1013f0306..59c99cc56e 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java
@@ -18,86 +18,76 @@
import javax.sql.DataSource;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import org.springframework.batch.core.JobParameters;
-import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.support.JdbcTransactionManager;
-import org.springframework.test.util.AopTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
/**
* @author Mahmoud Ben Hassine
*/
-public class TransactionManagerConfigurationWithoutBatchConfigurerTests extends TransactionManagerConfigurationTests {
-
- @Test(expected = BeanCreationException.class)
- public void testConfigurationWithNoDataSourceAndNoTransactionManager() {
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
- BatchConfigurationWithNoDataSourceAndNoTransactionManager.class);
- // beans created by `@EnableBatchProcessing` are lazy proxies,
- // SimpleBatchConfiguration.initialize is only triggered
- // when a method is called on one of these proxies
- JobRepository jobRepository = context.getBean(JobRepository.class);
- Assert.assertFalse(jobRepository.isJobInstanceExists("myJob", new JobParameters()));
+class TransactionManagerConfigurationWithoutBatchConfigurerTests extends TransactionManagerConfigurationTests {
+
+ @Test
+ void testConfigurationWithNoDataSourceAndNoTransactionManager() {
+ assertThrows(BeanCreationException.class, () -> new AnnotationConfigApplicationContext(
+ BatchConfigurationWithNoDataSourceAndNoTransactionManager.class));
}
- @Test(expected = BeanCreationException.class)
- public void testConfigurationWithNoDataSourceAndTransactionManager() {
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
- BatchConfigurationWithNoDataSourceAndTransactionManager.class);
- // beans created by `@EnableBatchProcessing` are lazy proxies,
- // SimpleBatchConfiguration.initialize is only triggered
- // when a method is called on one of these proxies
- JobRepository jobRepository = context.getBean(JobRepository.class);
- Assert.assertFalse(jobRepository.isJobInstanceExists("myJob", new JobParameters()));
+ @Test
+ void testConfigurationWithNoDataSourceAndTransactionManager() {
+ assertThrows(BeanCreationException.class, () -> new AnnotationConfigApplicationContext(
+ BatchConfigurationWithNoDataSourceAndTransactionManager.class));
}
@Test
- public void testConfigurationWithDataSourceAndNoTransactionManager() throws Exception {
+ void testConfigurationWithDataSourceAndNoTransactionManager() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
BatchConfigurationWithDataSourceAndNoTransactionManager.class);
PlatformTransactionManager platformTransactionManager = getTransactionManagerSetOnJobRepository(
applicationContext.getBean(JobRepository.class));
- Assert.assertTrue(platformTransactionManager instanceof JdbcTransactionManager);
+ assertTrue(platformTransactionManager instanceof JdbcTransactionManager);
JdbcTransactionManager JdbcTransactionManager = (JdbcTransactionManager) platformTransactionManager;
- Assert.assertEquals(applicationContext.getBean(DataSource.class), JdbcTransactionManager.getDataSource());
+ assertEquals(applicationContext.getBean(DataSource.class), JdbcTransactionManager.getDataSource());
}
@Test
- public void testConfigurationWithDataSourceAndOneTransactionManager() throws Exception {
+ void testConfigurationWithDataSourceAndOneTransactionManager() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
BatchConfigurationWithDataSourceAndOneTransactionManager.class);
PlatformTransactionManager platformTransactionManager = applicationContext
.getBean(PlatformTransactionManager.class);
- Assert.assertSame(transactionManager, platformTransactionManager);
+ assertSame(transactionManager, platformTransactionManager);
// In this case, the supplied transaction manager won't be used by batch and a
// JdbcTransactionManager will be used instead.
// The user has to provide a custom BatchConfigurer.
- Assert.assertTrue(getTransactionManagerSetOnJobRepository(
+ assertTrue(getTransactionManagerSetOnJobRepository(
applicationContext.getBean(JobRepository.class)) instanceof JdbcTransactionManager);
}
@Test
- public void testConfigurationWithDataSourceAndMultipleTransactionManagers() throws Exception {
+ void testConfigurationWithDataSourceAndMultipleTransactionManagers() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
BatchConfigurationWithDataSourceAndMultipleTransactionManagers.class);
PlatformTransactionManager platformTransactionManager = applicationContext
.getBean(PlatformTransactionManager.class);
- Assert.assertSame(transactionManager2, platformTransactionManager);
+ assertSame(transactionManager2, platformTransactionManager);
// In this case, the supplied primary transaction manager won't be used by batch
// and a JdbcTransactionManager will be used instead.
// The user has to provide a custom BatchConfigurer.
- Assert.assertTrue(getTransactionManagerSetOnJobRepository(
+ assertTrue(getTransactionManagerSetOnJobRepository(
applicationContext.getBean(JobRepository.class)) instanceof JdbcTransactionManager);
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java
index 794dd39142..e12b9e8ffd 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2012 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,27 +15,27 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.StaticApplicationContext;
-public class ApplicationContextJobFactoryTests {
+class ApplicationContextJobFactoryTests {
@Test
- public void testFactoryContext() throws Exception {
+ void testFactoryContext() {
ApplicationContextJobFactory factory = new ApplicationContextJobFactory("job",
new StubApplicationContextFactory());
assertNotNull(factory.createJob());
}
@Test
- public void testPostProcessing() throws Exception {
+ void testPostProcessing() {
ApplicationContextJobFactory factory = new ApplicationContextJobFactory("job",
new PostProcessingApplicationContextFactory());
assertEquals("bar", factory.getJobName());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarContextTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarContextTests.java
index eae166649d..5af7467e00 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarContextTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarContextTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 the original author or authors.
+ * Copyright 2010-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,32 +15,29 @@
*/
package org.springframework.batch.core.configuration.support;
-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.Collection;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.JobRegistry;
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;
/**
* @author Dave Syer
*
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration
-public class AutomaticJobRegistrarContextTests {
+@SpringJUnitConfig
+class AutomaticJobRegistrarContextTests {
@Autowired
private JobRegistry registry;
@Test
- public void testLocateJob() throws Exception {
+ void testLocateJob() throws Exception {
Collection names = registry.getJobNames();
assertEquals(2, names.size());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java
index 7224355195..c58894659f 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 the original author or authors.
+ * Copyright 2010-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,16 +15,16 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.batch.core.Job;
import org.springframework.beans.factory.BeanCreationException;
@@ -41,14 +41,14 @@
* @author Mahmoud Ben Hassine
*
*/
-public class AutomaticJobRegistrarTests {
+class AutomaticJobRegistrarTests {
- private AutomaticJobRegistrar registrar = new AutomaticJobRegistrar();
+ private final AutomaticJobRegistrar registrar = new AutomaticJobRegistrar();
- private MapJobRegistry registry = new MapJobRegistry();
+ private final MapJobRegistry registry = new MapJobRegistry();
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
DefaultJobLoader jobLoader = new DefaultJobLoader();
jobLoader.setJobRegistry(registry);
registrar.setJobLoader(jobLoader);
@@ -56,7 +56,7 @@ public void setUp() {
@SuppressWarnings("cast")
@Test
- public void testOrderedImplemented() throws Exception {
+ void testOrderedImplemented() {
assertTrue(registrar instanceof Ordered);
assertEquals(Ordered.LOWEST_PRECEDENCE, registrar.getOrder());
@@ -66,27 +66,26 @@ public void testOrderedImplemented() throws Exception {
}
@Test
- public void testDefaultAutoStartup() throws Exception {
+ void testDefaultAutoStartup() {
assertTrue(registrar.isAutoStartup());
}
@Test
- public void testDefaultPhase() throws Exception {
+ void testDefaultPhase() {
assertEquals(Integer.MIN_VALUE + 1000, registrar.getPhase());
}
@Test
- public void testLocateJob() throws Exception {
+ void testLocateJob() throws Exception {
Resource[] jobPaths = new Resource[] {
new ClassPathResource("org/springframework/batch/core/launch/support/job.xml"),
new ClassPathResource("org/springframework/batch/core/launch/support/job2.xml") };
- @SuppressWarnings("resource")
GenericApplicationContext applicationContext = new GenericApplicationContext();
applicationContext.refresh();
setUpApplicationContextFactories(jobPaths, applicationContext);
@@ -105,11 +104,10 @@ public void testLocateJob() throws Exception {
}
@Test
- public void testNoJobFound() throws Exception {
+ void testNoJobFound() {
Resource[] jobPaths = new Resource[] {
new ClassPathResource("org/springframework/batch/core/launch/support/test-environment.xml") };
- @SuppressWarnings("resource")
GenericApplicationContext applicationContext = new GenericApplicationContext();
applicationContext.refresh();
setUpApplicationContextFactories(jobPaths, applicationContext);
@@ -118,11 +116,10 @@ public void testNoJobFound() throws Exception {
}
@Test
- public void testDuplicateJobsInFile() throws Exception {
+ void testDuplicateJobsInFile() {
Resource[] jobPaths = new Resource[] {
new ClassPathResource("org/springframework/batch/core/launch/support/2jobs.xml") };
- @SuppressWarnings("resource")
GenericApplicationContext applicationContext = new GenericApplicationContext();
applicationContext.refresh();
setUpApplicationContextFactories(jobPaths, applicationContext);
@@ -132,11 +129,10 @@ public void testDuplicateJobsInFile() throws Exception {
}
@Test
- public void testChildContextOverridesBeanPostProcessor() throws Exception {
+ void testChildContextOverridesBeanPostProcessor() {
Resource[] jobPaths = new Resource[] {
new ClassPathResource("org/springframework/batch/core/launch/support/2jobs.xml") };
- @SuppressWarnings("resource")
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"/org/springframework/batch/core/launch/support/test-environment-with-registry-and-auto-register.xml");
registrar.setApplicationContext(applicationContext);
@@ -146,23 +142,18 @@ public void testChildContextOverridesBeanPostProcessor() throws Exception {
}
@Test
- public void testErrorInContext() throws Exception {
+ void testErrorInContext() {
Resource[] jobPaths = new Resource[] {
new ClassPathResource("org/springframework/batch/core/launch/support/2jobs.xml"),
new ClassPathResource("org/springframework/batch/core/launch/support/error.xml") };
setUpApplicationContextFactories(jobPaths, null);
- try {
- registrar.start();
- fail("Expected BeanCreationException");
- }
- catch (BeanCreationException e) {
- }
+ assertThrows(BeanCreationException.class, registrar::start);
}
@Test
- public void testClear() throws Exception {
+ void testClear() {
Resource[] jobPaths = new Resource[] {
new ClassPathResource("org/springframework/batch/core/launch/support/2jobs.xml") };
@@ -175,7 +166,7 @@ public void testClear() throws Exception {
}
@Test
- public void testStartStopRunning() throws Exception {
+ void testStartStopRunning() {
Resource[] jobPaths = new Resource[] {
new ClassPathResource("org/springframework/batch/core/launch/support/2jobs.xml") };
@@ -190,7 +181,7 @@ public void testStartStopRunning() throws Exception {
}
@Test
- public void testStartStopRunningWithCallback() throws Exception {
+ void testStartStopRunningWithCallback() {
Runnable callback = Mockito.mock(Runnable.class);
Resource[] jobPaths = new Resource[] {
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/DefaultJobLoaderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/DefaultJobLoaderTests.java
index c7316a73ff..e0c3802992 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/DefaultJobLoaderTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/DefaultJobLoaderTests.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,14 +15,15 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersIncrementer;
@@ -31,7 +32,6 @@
import org.springframework.batch.core.configuration.DuplicateJobException;
import org.springframework.batch.core.configuration.JobRegistry;
import org.springframework.batch.core.configuration.StepRegistry;
-import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.batch.core.step.NoSuchStepException;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.core.io.ByteArrayResource;
@@ -44,7 +44,7 @@
* @author Stephane Nicoll
* @author Mahmoud Ben Hassine
*/
-public class DefaultJobLoaderTests {
+class DefaultJobLoaderTests {
/**
* The name of the job as defined in the test context used in this test.
@@ -56,14 +56,14 @@ public class DefaultJobLoaderTests {
*/
private static final String TEST_STEP_NAME = "test-step";
- private JobRegistry jobRegistry = new MapJobRegistry();
+ private final JobRegistry jobRegistry = new MapJobRegistry();
- private StepRegistry stepRegistry = new MapStepRegistry();
+ private final StepRegistry stepRegistry = new MapStepRegistry();
- private DefaultJobLoader jobLoader = new DefaultJobLoader(jobRegistry, stepRegistry);
+ private final DefaultJobLoader jobLoader = new DefaultJobLoader(jobRegistry, stepRegistry);
@Test
- public void testClear() throws Exception {
+ void testClear() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ByteArrayResource(JOB_XML.getBytes()));
jobLoader.load(factory);
@@ -75,7 +75,7 @@ public void testClear() throws Exception {
}
@Test
- public void testLoadWithExplicitName() throws Exception {
+ void testLoadWithExplicitName() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ByteArrayResource(JOB_XML.getBytes()));
jobLoader.load(factory);
@@ -85,7 +85,7 @@ public void testLoadWithExplicitName() throws Exception {
}
@Test
- public void createWithBothRegistries() {
+ void createWithBothRegistries() {
final DefaultJobLoader loader = new DefaultJobLoader();
loader.setJobRegistry(jobRegistry);
loader.setStepRegistry(stepRegistry);
@@ -94,7 +94,7 @@ public void createWithBothRegistries() {
}
@Test
- public void createWithOnlyJobRegistry() {
+ void createWithOnlyJobRegistry() {
final DefaultJobLoader loader = new DefaultJobLoader();
loader.setJobRegistry(jobRegistry);
@@ -102,7 +102,7 @@ public void createWithOnlyJobRegistry() {
}
@Test
- public void testRegistryUpdated() throws DuplicateJobException {
+ void testRegistryUpdated() throws DuplicateJobException {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource("trivial-context.xml", getClass()));
jobLoader.load(factory);
@@ -111,7 +111,7 @@ public void testRegistryUpdated() throws DuplicateJobException {
}
@Test
- public void testMultipleJobsInTheSameContext() throws DuplicateJobException {
+ void testMultipleJobsInTheSameContext() throws DuplicateJobException {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource("job-context-with-steps.xml", getClass()));
jobLoader.load(factory);
@@ -123,7 +123,7 @@ public void testMultipleJobsInTheSameContext() throws DuplicateJobException {
}
@Test
- public void testMultipleJobsInTheSameContextWithSeparateSteps() throws DuplicateJobException {
+ void testMultipleJobsInTheSameContextWithSeparateSteps() throws DuplicateJobException {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource("job-context-with-separate-steps.xml", getClass()));
jobLoader.load(factory);
@@ -135,7 +135,7 @@ public void testMultipleJobsInTheSameContextWithSeparateSteps() throws Duplicate
}
@Test
- public void testNoStepRegistryAvailable() throws DuplicateJobException {
+ void testNoStepRegistryAvailable() throws DuplicateJobException {
final JobLoader loader = new DefaultJobLoader(jobRegistry);
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource("job-context-with-steps.xml", getClass()));
@@ -145,36 +145,22 @@ public void testNoStepRegistryAvailable() throws DuplicateJobException {
}
@Test
- public void testLoadWithJobThatIsNotAStepLocator() throws DuplicateJobException {
+ void testLoadWithJobThatIsNotAStepLocator() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ByteArrayResource(BASIC_JOB_XML.getBytes()));
- try {
- jobLoader.load(factory);
- fail("Should have failed with a [" + UnsupportedOperationException.class.getName() + "] as job does not"
- + "implement StepLocator.");
- }
- catch (UnsupportedOperationException e) {
- // Job is not a step locator, can't register steps
- }
-
+ assertThrows(UnsupportedOperationException.class, () -> jobLoader.load(factory));
}
@Test
- public void testLoadWithJobThatIsNotAStepLocatorNoStepRegistry() throws DuplicateJobException {
+ void testLoadWithJobThatIsNotAStepLocatorNoStepRegistry() {
final JobLoader loader = new DefaultJobLoader(jobRegistry);
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ByteArrayResource(BASIC_JOB_XML.getBytes()));
- try {
- loader.load(factory);
- }
- catch (UnsupportedOperationException e) {
- fail("Should not have failed with a [" + UnsupportedOperationException.class.getName() + "] as "
- + "stepRegistry is not available for this JobLoader instance.");
- }
+ assertDoesNotThrow(() -> loader.load(factory));
}
@Test
- public void testReload() throws Exception {
+ void testReload() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource("trivial-context.xml", getClass()));
jobLoader.load(factory);
@@ -186,7 +172,7 @@ public void testReload() throws Exception {
}
@Test
- public void testReloadWithAutoRegister() throws Exception {
+ void testReloadWithAutoRegister() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource("trivial-context-autoregister.xml", getClass()));
jobLoader.load(factory);
@@ -199,31 +185,13 @@ public void testReloadWithAutoRegister() throws Exception {
protected void assertStepExist(String jobName, String... stepNames) {
for (String stepName : stepNames) {
- try {
- stepRegistry.getStep(jobName, stepName);
- }
- catch (NoSuchJobException e) {
- fail("Job with name [" + jobName + "] should have been found.");
- }
- catch (NoSuchStepException e) {
- fail("Step with name [" + stepName + "] for job [" + jobName + "] should have been found.");
- }
+ assertDoesNotThrow(() -> stepRegistry.getStep(jobName, stepName));
}
}
protected void assertStepDoNotExist(String jobName, String... stepNames) {
for (String stepName : stepNames) {
- try {
- final Step step = stepRegistry.getStep(jobName, stepName);
- fail("Step with name [" + stepName + "] for job [" + jobName + "] should "
- + "not have been found but got [" + step + "]");
- }
- catch (NoSuchJobException e) {
- fail("Job with name [" + jobName + "] should have been found.");
- }
- catch (NoSuchStepException e) {
- // OK
- }
+ assertThrows(NoSuchStepException.class, () -> stepRegistry.getStep(jobName, stepName));
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactoryTests.java
index d9da01b88c..69f5fc20d8 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactoryTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactoryTests.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,12 +15,13 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.job.JobSupport;
@@ -47,28 +48,26 @@
* @author Mahmoud Ben Hassine
*
*/
-public class GenericApplicationContextFactoryTests {
+class GenericApplicationContextFactoryTests {
@Test
- public void testCreateJob() {
+ void testCreateJob() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml")));
- @SuppressWarnings("resource")
ConfigurableApplicationContext context = factory.createApplicationContext();
assertNotNull(context);
- assertTrue("Wrong id: " + context, context.getId().contains("trivial-context.xml"));
+ assertTrue(context.getId().contains("trivial-context.xml"), "Wrong id: " + context);
}
@Test
- public void testGetJobName() {
+ void testGetJobName() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml")));
assertEquals("test-job", factory.createApplicationContext().getBeanNamesForType(Job.class)[0]);
}
- @SuppressWarnings("resource")
@Test
- public void testParentConfigurationInherited() {
+ void testParentConfigurationInherited() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "child-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(
@@ -79,9 +78,8 @@ public void testParentConfigurationInherited() {
assertEquals(4, context.getBean("foo", Foo.class).values[1], 0.01);
}
- @SuppressWarnings("resource")
@Test
- public void testBeanFactoryPostProcessorOrderRespected() {
+ void testBeanFactoryPostProcessorOrderRespected() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "placeholder-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(
@@ -91,26 +89,24 @@ public void testBeanFactoryPostProcessorOrderRespected() {
assertEquals("spam", context.getBean("test-job", Job.class).getName());
}
+ // FIXME replacing PropertyPlaceholderConfigurer with
+ // PropertySourcesPlaceholderConfigurer does not seem to inherit profiles
@Test
- @Ignore // FIXME replacing PropertyPlaceholderConfigurer with
- // PropertySourcesPlaceholderConfigurer does not seem to inherit profiles
- public void testBeanFactoryProfileRespected() {
+ @Disabled
+ void testBeanFactoryProfileRespected() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "profiles.xml")));
- @SuppressWarnings("resource")
ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext(
ClassUtils.addResourcePathToPackagePath(getClass(), "parent-context.xml"));
parentContext.getEnvironment().setActiveProfiles("preferred");
factory.setApplicationContext(parentContext);
- @SuppressWarnings("resource")
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("test-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("spam", context.getBean("test-job", Job.class).getName());
}
- @SuppressWarnings("resource")
@Test
- public void testBeanFactoryPostProcessorsNotCopied() {
+ void testBeanFactoryPostProcessorsNotCopied() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "child-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(
@@ -124,9 +120,8 @@ public void testBeanFactoryPostProcessorsNotCopied() {
assertEquals(4, context.getBean("foo", Foo.class).values[1], 0.01);
}
- @SuppressWarnings("resource")
@Test
- public void testBeanFactoryConfigurationNotCopied() {
+ void testBeanFactoryConfigurationNotCopied() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "child-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(
@@ -141,7 +136,7 @@ public void testBeanFactoryConfigurationNotCopied() {
}
@Test
- public void testEquals() throws Exception {
+ void testEquals() {
Resource resource = new ClassPathResource(
ClassUtils.addResourcePathToPackagePath(getClass(), "child-context.xml"));
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource);
@@ -151,7 +146,7 @@ public void testEquals() throws Exception {
}
@Test
- public void testEqualsMultipleConfigs() throws Exception {
+ void testEqualsMultipleConfigs() {
Resource resource1 = new ClassPathResource(
ClassUtils.addResourcePathToPackagePath(getClass(), "abstract-context.xml"));
Resource resource2 = new ClassPathResource(
@@ -163,7 +158,7 @@ public void testEqualsMultipleConfigs() throws Exception {
}
@Test
- public void testParentConfigurationInheritedMultipleConfigs() {
+ void testParentConfigurationInheritedMultipleConfigs() {
Resource resource1 = new ClassPathResource(
ClassUtils.addResourcePathToPackagePath(getClass(), "abstract-context.xml"));
Resource resource2 = new ClassPathResource(
@@ -185,17 +180,17 @@ public void testParentConfigurationInheritedMultipleConfigs() {
assertTrue(autowiredFound);
}
- @Test(expected = IllegalArgumentException.class)
- public void testDifferentResourceTypes() throws Exception {
+ @Test
+ void testDifferentResourceTypes() {
Resource resource1 = new ClassPathResource(
ClassUtils.addResourcePathToPackagePath(getClass(), "abstract-context.xml"));
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource1,
Configuration1.class);
- factory.createApplicationContext();
+ assertThrows(IllegalArgumentException.class, factory::createApplicationContext);
}
@Test
- public void testPackageScanning() throws Exception {
+ void testPackageScanning() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
"org.springframework.batch.core.configuration.support");
ConfigurableApplicationContext context = factory.createApplicationContext();
@@ -207,7 +202,7 @@ public void testPackageScanning() throws Exception {
}
@Test
- public void testMultipleConfigurationClasses() throws Exception {
+ void testMultipleConfigurationClasses() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(Configuration1.class,
Configuration2.class);
ConfigurableApplicationContext context = factory.createApplicationContext();
@@ -219,7 +214,7 @@ public void testMultipleConfigurationClasses() throws Exception {
}
@Test
- public void testParentChildLifecycleEvents() throws InterruptedException {
+ void testParentChildLifecycleEvents() {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(ParentContext.class);
GenericApplicationContextFactory child = new GenericApplicationContextFactory(ChildContextConfiguration.class);
child.setApplicationContext(parent);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobTests.java
index 113489511f..ad1af070fe 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobTests.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,9 +15,9 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.job.JobSupport;
@@ -25,24 +25,24 @@
* @author Dave Syer
*
*/
-public class GroupAwareJobTests {
+class GroupAwareJobTests {
- private Job job = new JobSupport("foo");
+ private final Job job = new JobSupport("foo");
@Test
- public void testCreateJob() {
+ void testCreateJob() {
GroupAwareJob result = new GroupAwareJob(job);
assertEquals("foo", result.getName());
}
@Test
- public void testGetJobName() {
+ void testGetJobName() {
GroupAwareJob result = new GroupAwareJob("jobs", job);
assertEquals("jobs.foo", result.getName());
}
@Test
- public void testToString() {
+ void testToString() {
GroupAwareJob result = new GroupAwareJob("jobs", job);
assertEquals("JobSupport: [name=jobs.foo]", result.toString());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListenerTests.java
index 55cbabf293..d834a3e981 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListenerTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListenerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2013 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,9 +15,9 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.JobFactory;
@@ -25,19 +25,14 @@
* @author Dave Syer
*
*/
-public class JobFactoryRegistrationListenerTests {
+class JobFactoryRegistrationListenerTests {
- private JobFactoryRegistrationListener listener = new JobFactoryRegistrationListener();
+ private final JobFactoryRegistrationListener listener = new JobFactoryRegistrationListener();
- private MapJobRegistry registry = new MapJobRegistry();
+ private final MapJobRegistry registry = new MapJobRegistry();
- /**
- * Test method for
- * {@link org.springframework.batch.core.configuration.support.JobFactoryRegistrationListener#bind(org.springframework.batch.core.configuration.JobFactory, java.util.Map)}.
- * @throws Exception
- */
@Test
- public void testBind() throws Exception {
+ void testBind() throws Exception {
listener.setJobRegistry(registry);
listener.bind(new JobFactory() {
@Override
@@ -53,13 +48,8 @@ public String getJobName() {
assertEquals(1, registry.getJobNames().size());
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.configuration.support.JobFactoryRegistrationListener#unbind(org.springframework.batch.core.configuration.JobFactory, java.util.Map)}.
- * @throws Exception
- */
@Test
- public void testUnbind() throws Exception {
+ void testUnbind() throws Exception {
testBind();
listener.unbind(new JobFactory() {
@Override
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java
index 4af662ea94..923ac92bbe 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.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,14 +15,14 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.configuration.DuplicateJobException;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.beans.FatalBeanException;
@@ -30,38 +30,32 @@
/**
* @author Dave Syer
- *
+ *
*/
-public class JobRegistryBeanPostProcessorTests {
+class JobRegistryBeanPostProcessorTests {
- private JobRegistryBeanPostProcessor processor = new JobRegistryBeanPostProcessor();
+ private final JobRegistryBeanPostProcessor processor = new JobRegistryBeanPostProcessor();
@Test
- public void testInitializationFails() throws Exception {
- try {
- processor.afterPropertiesSet();
- fail("Expected IllegalArgumentException");
- }
- catch (IllegalArgumentException e) {
- // expected
- assertTrue(e.getMessage().contains("JobRegistry"));
- }
+ void testInitializationFails() {
+ Exception exception = assertThrows(IllegalArgumentException.class, processor::afterPropertiesSet);
+ assertTrue(exception.getMessage().contains("JobRegistry"));
}
@Test
- public void testBeforeInitialization() throws Exception {
+ void testBeforeInitialization() {
// should be a no-op
assertEquals("foo", processor.postProcessBeforeInitialization("foo", "bar"));
}
@Test
- public void testAfterInitializationWithWrongType() throws Exception {
+ void testAfterInitializationWithWrongType() {
// should be a no-op
assertEquals("foo", processor.postProcessAfterInitialization("foo", "bar"));
}
@Test
- public void testAfterInitializationWithCorrectType() throws Exception {
+ void testAfterInitializationWithCorrectType() {
MapJobRegistry registry = new MapJobRegistry();
processor.setJobRegistry(registry);
JobSupport job = new JobSupport();
@@ -71,7 +65,7 @@ public void testAfterInitializationWithCorrectType() throws Exception {
}
@Test
- public void testAfterInitializationWithGroupName() throws Exception {
+ void testAfterInitializationWithGroupName() {
MapJobRegistry registry = new MapJobRegistry();
processor.setJobRegistry(registry);
processor.setGroupName("jobs");
@@ -82,24 +76,19 @@ public void testAfterInitializationWithGroupName() throws Exception {
}
@Test
- public void testAfterInitializationWithDuplicate() throws Exception {
+ void testAfterInitializationWithDuplicate() {
MapJobRegistry registry = new MapJobRegistry();
processor.setJobRegistry(registry);
JobSupport job = new JobSupport();
job.setBeanName("foo");
processor.postProcessAfterInitialization(job, "bar");
- try {
- processor.postProcessAfterInitialization(job, "spam");
- fail("Expected FatalBeanException");
- }
- catch (FatalBeanException e) {
- // Expected
- assertTrue(e.getCause() instanceof DuplicateJobException);
- }
+ Exception exception = assertThrows(FatalBeanException.class,
+ () -> processor.postProcessAfterInitialization(job, "spam"));
+ assertTrue(exception.getCause() instanceof DuplicateJobException);
}
@Test
- public void testUnregisterOnDestroy() throws Exception {
+ void testUnregisterOnDestroy() throws Exception {
MapJobRegistry registry = new MapJobRegistry();
processor.setJobRegistry(registry);
JobSupport job = new JobSupport();
@@ -110,8 +99,7 @@ public void testUnregisterOnDestroy() throws Exception {
}
@Test
- @SuppressWarnings("resource")
- public void testExecutionWithApplicationContext() throws Exception {
+ void testExecutionWithApplicationContext() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test-context.xml", getClass());
MapJobRegistry registry = (MapJobRegistry) context.getBean("registry");
Collection configurations = registry.getJobNames();
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests.java
index 05368b8fc2..7586b62ebe 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests.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,23 +15,20 @@
*/
package org.springframework.batch.core.configuration.support;
-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.Job;
import org.springframework.batch.core.configuration.JobRegistry;
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;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class JobRegistryIntegrationTests {
+@SpringJUnitConfig
+class JobRegistryIntegrationTests {
@Autowired
private JobRegistry jobRegistry;
@@ -40,7 +37,7 @@ public class JobRegistryIntegrationTests {
private Job job;
@Test
- public void testRegistry() throws Exception {
+ void testRegistry() {
assertEquals(1, jobRegistry.getJobNames().size());
assertEquals(job.getName(), jobRegistry.getJobNames().iterator().next());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapJobRegistryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapJobRegistryTests.java
index 2fc3affa09..d35c5ff7d9 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapJobRegistryTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapJobRegistryTests.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,79 +17,52 @@
import java.util.Collection;
-import junit.framework.TestCase;
-
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.configuration.DuplicateJobException;
import org.springframework.batch.core.configuration.JobFactory;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.batch.core.launch.NoSuchJobException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
/**
* @author Dave Syer
*
*/
-public class MapJobRegistryTests extends TestCase {
+class MapJobRegistryTests {
- private MapJobRegistry registry = new MapJobRegistry();
+ private final MapJobRegistry registry = new MapJobRegistry();
- /**
- * Test method for
- * {@link org.springframework.batch.core.configuration.support.MapJobRegistry#unregister(String)}.
- * @throws Exception
- */
- public void testUnregister() throws Exception {
+ @Test
+ void testUnregister() throws Exception {
registry.register(new ReferenceJobFactory(new JobSupport("foo")));
assertNotNull(registry.getJob("foo"));
registry.unregister("foo");
- try {
- assertNull(registry.getJob("foo"));
- fail("Expected NoSuchJobConfigurationException");
- }
- catch (NoSuchJobException e) {
- // expected
- assertTrue(e.getMessage().indexOf("foo") >= 0);
- }
+ Exception exception = assertThrows(NoSuchJobException.class, () -> registry.getJob("foo"));
+ assertTrue(exception.getMessage().contains("foo"));
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJob(java.lang.String)}.
- */
- public void testReplaceDuplicateConfiguration() throws Exception {
+ @Test
+ void testReplaceDuplicateConfiguration() throws Exception {
registry.register(new ReferenceJobFactory(new JobSupport("foo")));
- try {
- registry.register(new ReferenceJobFactory(new JobSupport("foo")));
- fail("Expected DuplicateJobConfigurationException");
- }
- catch (DuplicateJobException e) {
- // unexpected: even if the job is different we want a DuplicateJobException
- assertTrue(e.getMessage().indexOf("foo") >= 0);
- }
+ JobFactory jobFactory = new ReferenceJobFactory(new JobSupport("foo"));
+ Exception exception = assertThrows(DuplicateJobException.class, () -> registry.register(jobFactory));
+ assertTrue(exception.getMessage().contains("foo"));
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJob(java.lang.String)}.
- */
- public void testRealDuplicateConfiguration() throws Exception {
+ @Test
+ void testRealDuplicateConfiguration() throws Exception {
JobFactory jobFactory = new ReferenceJobFactory(new JobSupport("foo"));
registry.register(jobFactory);
- try {
- registry.register(jobFactory);
- fail("Unexpected DuplicateJobConfigurationException");
- }
- catch (DuplicateJobException e) {
- // expected
- assertTrue(e.getMessage().indexOf("foo") >= 0);
- }
+ Exception exception = assertThrows(DuplicateJobException.class, () -> registry.register(jobFactory));
+ assertTrue(exception.getMessage().contains("foo"));
}
- /**
- * Test method for
- * {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJobNames()}.
- * @throws Exception
- */
- public void testGetJobConfigurations() throws Exception {
+ @Test
+ void testGetJobConfigurations() throws Exception {
JobFactory jobFactory = new ReferenceJobFactory(new JobSupport("foo"));
registry.register(jobFactory);
registry.register(new ReferenceJobFactory(new JobSupport("bar")));
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapStepRegistryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapStepRegistryTests.java
index f812945ff6..394132cb31 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapStepRegistryTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/MapStepRegistryTests.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,14 +15,14 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.DuplicateJobException;
import org.springframework.batch.core.configuration.StepRegistry;
@@ -33,43 +33,29 @@
/**
* @author Sebastien Gerard
*/
-public class MapStepRegistryTests {
-
- private static final String EXCEPTION_NOT_THROWN_MSG = "An exception should have been thrown";
+class MapStepRegistryTests {
@Test
- public void registerStepEmptyCollection() throws DuplicateJobException {
+ void registerStepEmptyCollection() throws DuplicateJobException {
final StepRegistry stepRegistry = createRegistry();
launchRegisterGetRegistered(stepRegistry, "myJob", getStepCollection());
}
@Test
- public void registerStepNullJobName() throws DuplicateJobException {
- final StepRegistry stepRegistry = createRegistry();
-
- try {
- stepRegistry.register(null, new HashSet<>());
- Assert.fail(EXCEPTION_NOT_THROWN_MSG);
- }
- catch (IllegalArgumentException e) {
- }
+ void registerStepNullJobName() {
+ StepRegistry stepRegistry = createRegistry();
+ assertThrows(IllegalArgumentException.class, () -> stepRegistry.register(null, new HashSet<>()));
}
@Test
- public void registerStepNullSteps() throws DuplicateJobException {
- final StepRegistry stepRegistry = createRegistry();
-
- try {
- stepRegistry.register("fdsfsd", null);
- Assert.fail(EXCEPTION_NOT_THROWN_MSG);
- }
- catch (IllegalArgumentException e) {
- }
+ void registerStepNullSteps() {
+ StepRegistry stepRegistry = createRegistry();
+ assertThrows(IllegalArgumentException.class, () -> stepRegistry.register("fdsfsd", null));
}
@Test
- public void registerStepGetStep() throws DuplicateJobException {
+ void registerStepGetStep() throws DuplicateJobException {
final StepRegistry stepRegistry = createRegistry();
launchRegisterGetRegistered(stepRegistry, "myJob",
@@ -77,7 +63,7 @@ public void registerStepGetStep() throws DuplicateJobException {
}
@Test
- public void getJobNotRegistered() throws DuplicateJobException {
+ void getJobNotRegistered() throws DuplicateJobException {
final StepRegistry stepRegistry = createRegistry();
final String aStepName = "myStep";
@@ -88,14 +74,14 @@ public void getJobNotRegistered() throws DuplicateJobException {
}
@Test
- public void getJobNotRegisteredNoRegistration() {
+ void getJobNotRegisteredNoRegistration() {
final StepRegistry stepRegistry = createRegistry();
assertJobNotRegistered(stepRegistry, "a ghost");
}
@Test
- public void getStepNotRegistered() throws DuplicateJobException {
+ void getStepNotRegistered() throws DuplicateJobException {
final StepRegistry stepRegistry = createRegistry();
final String jobName = "myJob";
@@ -106,7 +92,7 @@ public void getStepNotRegistered() throws DuplicateJobException {
}
@Test
- public void registerTwice() throws DuplicateJobException {
+ void registerTwice() throws DuplicateJobException {
final StepRegistry stepRegistry = createRegistry();
final String jobName = "myJob";
@@ -117,44 +103,27 @@ public void registerTwice() throws DuplicateJobException {
launchRegisterGetRegistered(stepRegistry, jobName, stepsFirstRegistration);
// Second registration with same name should fail
- try {
- stepRegistry.register(jobName, getStepCollection(createStep("myFourthStep"), createStep("lastOne")));
- fail("Should have failed with a " + DuplicateJobException.class.getSimpleName());
- }
- catch (DuplicateJobException e) {
- // OK
- }
+ assertThrows(DuplicateJobException.class, () -> stepRegistry.register(jobName,
+ getStepCollection(createStep("myFourthStep"), createStep("lastOne"))));
}
@Test
- public void getStepNullJobName() throws NoSuchJobException {
- final StepRegistry stepRegistry = createRegistry();
-
- try {
- stepRegistry.getStep(null, "a step");
- Assert.fail(EXCEPTION_NOT_THROWN_MSG);
- }
- catch (IllegalArgumentException e) {
- }
+ void getStepNullJobName() {
+ StepRegistry stepRegistry = createRegistry();
+ assertThrows(IllegalArgumentException.class, () -> stepRegistry.getStep(null, "a step"));
}
@Test
- public void getStepNullStepName() throws NoSuchJobException, DuplicateJobException {
+ void getStepNullStepName() throws DuplicateJobException {
final StepRegistry stepRegistry = createRegistry();
final String stepName = "myStep";
launchRegisterGetRegistered(stepRegistry, "myJob", getStepCollection(createStep(stepName)));
-
- try {
- stepRegistry.getStep(null, stepName);
- Assert.fail(EXCEPTION_NOT_THROWN_MSG);
- }
- catch (IllegalArgumentException e) {
- }
+ assertThrows(IllegalArgumentException.class, () -> stepRegistry.getStep(null, stepName));
}
@Test
- public void registerStepUnregisterJob() throws DuplicateJobException {
+ void registerStepUnregisterJob() throws DuplicateJobException {
final StepRegistry stepRegistry = createRegistry();
final Collection steps = getStepCollection(createStep("myStep"), createStep("myOtherStep"),
@@ -168,19 +137,13 @@ public void registerStepUnregisterJob() throws DuplicateJobException {
}
@Test
- public void unregisterJobNameNull() {
- final StepRegistry stepRegistry = createRegistry();
-
- try {
- stepRegistry.unregisterStepsFromJob(null);
- Assert.fail(EXCEPTION_NOT_THROWN_MSG);
- }
- catch (IllegalArgumentException e) {
- }
+ void unregisterJobNameNull() {
+ StepRegistry stepRegistry = createRegistry();
+ assertThrows(IllegalArgumentException.class, () -> stepRegistry.unregisterStepsFromJob(null));
}
@Test
- public void unregisterNoRegistration() {
+ void unregisterNoRegistration() {
final StepRegistry stepRegistry = createRegistry();
assertJobNotRegistered(stepRegistry, "a job");
@@ -205,22 +168,12 @@ protected void launchRegisterGetRegistered(StepRegistry stepRegistry, String job
}
protected void assertJobNotRegistered(StepRegistry stepRegistry, String jobName) {
- try {
- stepRegistry.getStep(jobName, "a step");
- Assert.fail(EXCEPTION_NOT_THROWN_MSG);
- }
- catch (NoSuchJobException e) {
- }
+ assertThrows(NoSuchJobException.class, () -> stepRegistry.getStep(jobName, "a step"));
}
protected void assertStepsRegistered(StepRegistry stepRegistry, String jobName, Collection steps) {
for (Step step : steps) {
- try {
- stepRegistry.getStep(jobName, step.getName());
- }
- catch (NoSuchJobException e) {
- Assert.fail("Unexpected exception " + e);
- }
+ assertDoesNotThrow(() -> stepRegistry.getStep(jobName, step.getName()));
}
}
@@ -231,15 +184,7 @@ protected void assertStepsNotRegistered(StepRegistry stepRegistry, String jobNam
}
protected void assertStepNameNotRegistered(StepRegistry stepRegistry, String jobName, String stepName) {
- try {
- stepRegistry.getStep(jobName, stepName);
- Assert.fail(EXCEPTION_NOT_THROWN_MSG);
- }
- catch (NoSuchJobException e) {
- Assert.fail("Unexpected exception");
- }
- catch (NoSuchStepException e) {
- }
+ assertThrows(NoSuchStepException.class, () -> stepRegistry.getStep(jobName, stepName));
}
}
\ No newline at end of file
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.java
index bee25289e0..122bf05556 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.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,19 +15,19 @@
*/
package org.springframework.batch.core.configuration.support;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.job.JobSupport;
/**
* @author Dave Syer
*
*/
-public class ReferenceJobFactoryTests {
+class ReferenceJobFactoryTests {
@Test
- public void testGroupName() throws Exception {
+ void testGroupName() {
ReferenceJobFactory factory = new ReferenceJobFactory(new JobSupport("foo"));
assertEquals("foo", factory.getJobName());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java
index bd9510f5df..d22a663a74 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.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.
@@ -17,7 +17,7 @@
import java.util.ArrayList;
-import org.junit.Before;
+import org.junit.jupiter.api.BeforeEach;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
@@ -29,8 +29,6 @@
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.beans.factory.annotation.Autowired;
-import static org.junit.Assert.fail;
-
/**
* @author Dan Garrette
* @author Mahmoud Ben Hassine
@@ -47,8 +45,8 @@ public abstract class AbstractJobParserTests {
@Autowired
protected ArrayList stepNamesList = new ArrayList<>();
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
stepNamesList.clear();
}
@@ -67,8 +65,7 @@ protected StepExecution getStepExecution(JobExecution jobExecution, String stepN
return stepExecution;
}
}
- fail("No stepExecution found with name: [" + stepName + "]");
- return null;
+ throw new AssertionError("No stepExecution found with name: [" + stepName + "]");
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeTests.java
index ffd360cf55..4db299aff6 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 the original author or authors.
+ * Copyright 2013-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,11 +15,11 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.scope.JobScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -28,24 +28,22 @@
* @author Thomas Risberg
* @author Jimmy Praet
*/
-public class AutoRegisteringJobScopeTests {
+class AutoRegisteringJobScopeTests {
@Test
- @SuppressWarnings("resource")
- public void testJobElement() throws Exception {
+ void testJobElement() {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeForJobElementTests-context.xml");
Map beans = ctx.getBeansOfType(JobScope.class);
- assertTrue("JobScope not defined properly", beans.size() == 1);
+ assertEquals(1, beans.size(), "JobScope not defined properly");
}
@Test
- @SuppressWarnings("resource")
- public void testStepElement() throws Exception {
+ void testStepElement() {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeForStepElementTests-context.xml");
Map beans = ctx.getBeansOfType(JobScope.class);
- assertTrue("JobScope not defined properly", beans.size() == 1);
+ assertEquals(1, beans.size(), "JobScope not defined properly");
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeTests.java
index 015a9ee2d1..9fb40b888b 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2009 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,36 +15,34 @@
*/
package org.springframework.batch.core.configuration.xml;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.scope.StepScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.Map;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Thomas Risberg
*/
-public class AutoRegisteringStepScopeTests {
+class AutoRegisteringStepScopeTests {
@Test
- @SuppressWarnings("resource")
- public void testJobElement() throws Exception {
+ void testJobElement() {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeForJobElementTests-context.xml");
Map beans = ctx.getBeansOfType(StepScope.class);
- assertTrue("StepScope not defined properly", beans.size() == 1);
+ assertEquals(1, beans.size(), "StepScope not defined properly");
}
@Test
- @SuppressWarnings("resource")
- public void testStepElement() throws Exception {
+ void testStepElement() {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeForStepElementTests-context.xml");
Map beans = ctx.getBeansOfType(StepScope.class);
- assertTrue("StepScope not defined properly", beans.size() == 1);
+ assertEquals(1, beans.size(), "StepScope not defined properly");
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests.java
index 93e724de3c..9a91891aed 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 the original author or authors.
+ * Copyright 2014-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,7 +15,7 @@
*/
package org.springframework.batch.core.configuration.xml;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
@@ -23,10 +23,10 @@
* Test cases for BATCH-1863.
*
*/
-public class BeanDefinitionOverrideTests {
+class BeanDefinitionOverrideTests {
@Test
- public void testAllowBeanOverride() {
+ void testAllowBeanOverride() {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setConfigLocation(
"org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml");
@@ -34,7 +34,7 @@ public void testAllowBeanOverride() {
}
@Test
- public void testAllowBeanOverrideFalse() {
+ void testAllowBeanOverrideFalse() {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setAllowBeanDefinitionOverriding(false);
applicationContext.setConfigLocation(
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BranchStepJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BranchStepJobParserTests.java
index 0cc093956b..dfbc44e4aa 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BranchStepJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/BranchStepJobParserTests.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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
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.Job;
import org.springframework.batch.core.JobExecution;
@@ -30,16 +29,14 @@
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
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;
/**
* @author Dave Syer
- *
+ *
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class BranchStepJobParserTests {
+@SpringJUnitConfig
+class BranchStepJobParserTests {
@Autowired
private Job job;
@@ -48,7 +45,7 @@ public class BranchStepJobParserTests {
private JobRepository jobRepository;
@Test
- public void testBranchStep() throws Exception {
+ void testBranchStep() throws Exception {
assertNotNull(job);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java
index 0314a95043..feecf382bd 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java
@@ -20,7 +20,7 @@
import java.util.Collection;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.step.item.SimpleChunkProcessor;
@@ -34,6 +34,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.NestedRuntimeException;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.ConcurrencyFailureException;
@@ -45,11 +46,11 @@
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.StringUtils;
-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.Assert.fail;
+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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Dan Garrette
@@ -57,56 +58,43 @@
* @author Mahmoud Ben Hassine
* @since 2.0
*/
-public class ChunkElementParserTests {
+class ChunkElementParserTests {
@Test
- @SuppressWarnings("resource")
- public void testSimpleAttributes() throws Exception {
+ void testSimpleAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementSimpleAttributeParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
- assertTrue("Wrong processor type", chunkProcessor instanceof SimpleChunkProcessor);
+ assertTrue(chunkProcessor instanceof SimpleChunkProcessor, "Wrong processor type");
}
@Test
- @SuppressWarnings("resource")
- public void testCommitIntervalLateBinding() throws Exception {
+ void testCommitIntervalLateBinding() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementLateBindingParserTests-context.xml");
Step step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
}
@Test
- @SuppressWarnings("resource")
- public void testSkipAndRetryAttributes() throws Exception {
+ void testSkipAndRetryAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementSkipAndRetryAttributeParserTests-context.xml");
Step step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
}
@Test
- @SuppressWarnings("resource")
- public void testIllegalSkipAndRetryAttributes() throws Exception {
- try {
- ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
- "org/springframework/batch/core/configuration/xml/ChunkElementIllegalSkipAndRetryAttributeParserTests-context.xml");
- Step step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
- fail("Expected BeanCreationException");
- }
- catch (BeanCreationException e) {
- // expected
- }
+ void testIllegalSkipAndRetryAttributes() {
+ assertThrows(BeanCreationException.class, () -> new ClassPathXmlApplicationContext(
+ "org/springframework/batch/core/configuration/xml/ChunkElementIllegalSkipAndRetryAttributeParserTests-context.xml"));
}
@Test
- public void testRetryPolicyAttribute() throws Exception {
- @SuppressWarnings("resource")
+ void testRetryPolicyAttribute() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml");
Map, Boolean> retryable = getNestedExceptionMap("s1", context,
@@ -118,8 +106,7 @@ public void testRetryPolicyAttribute() throws Exception {
}
@Test
- public void testRetryPolicyElement() throws Exception {
- @SuppressWarnings("resource")
+ void testRetryPolicyElement() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml");
SimpleRetryPolicy policy = (SimpleRetryPolicy) getPolicy("s2", context,
@@ -128,8 +115,7 @@ public void testRetryPolicyElement() throws Exception {
}
@Test
- public void testSkipPolicyAttribute() throws Exception {
- @SuppressWarnings("resource")
+ void testSkipPolicyAttribute() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementSkipPolicyParserTests-context.xml");
SkipPolicy policy = getSkipPolicy("s1", context);
@@ -138,8 +124,7 @@ public void testSkipPolicyAttribute() throws Exception {
}
@Test
- public void testSkipPolicyElement() throws Exception {
- @SuppressWarnings("resource")
+ void testSkipPolicyElement() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementSkipPolicyParserTests-context.xml");
SkipPolicy policy = getSkipPolicy("s2", context);
@@ -148,48 +133,41 @@ public void testSkipPolicyElement() throws Exception {
}
@Test
- @SuppressWarnings("resource")
- public void testProcessorTransactionalAttributes() throws Exception {
+ void testProcessorTransactionalAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementTransactionalAttributeParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
Boolean processorTransactional = (Boolean) ReflectionTestUtils.getField(chunkProcessor,
"processorTransactional");
- assertFalse("Flag not set", processorTransactional);
+ assertFalse(processorTransactional, "Flag not set");
}
@Test
- @SuppressWarnings("resource")
- public void testProcessorTransactionalNotAllowedOnSimpleProcessor() throws Exception {
+ void testProcessorTransactionalNotAllowedOnSimpleProcessor() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementIllegalAttributeParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
assertTrue(chunkProcessor instanceof SimpleChunkProcessor, ?>);
}
@Test
- public void testProcessorNonTransactionalNotAllowedWithTransactionalReader() throws Exception {
- try {
- new ClassPathXmlApplicationContext(
- "org/springframework/batch/core/configuration/xml/ChunkElementIllegalTransactionalAttributeParserTests-context.xml");
- fail("Expected BeanCreationException");
- }
- catch (BeanCreationException e) {
- String msg = e.getRootCause().getMessage();
- assertTrue("Wrong message: " + msg,
- msg.contains("The field 'processor-transactional' cannot be false if 'reader-transactional"));
- }
-
+ void testProcessorNonTransactionalNotAllowedWithTransactionalReader() {
+ NestedRuntimeException exception = assertThrows(BeanCreationException.class,
+ () -> new ClassPathXmlApplicationContext(
+ "org/springframework/batch/core/configuration/xml/ChunkElementIllegalTransactionalAttributeParserTests-context.xml"));
+ String msg = exception.getRootCause().getMessage();
+ assertTrue(msg.contains("The field 'processor-transactional' cannot be false if 'reader-transactional"),
+ "Wrong message: " + msg);
}
@Test
- public void testRetryable() throws Exception {
+ void testRetryable() throws Exception {
Map, Boolean> retryable = getRetryableExceptionClasses("s1", getContext());
System.err.println(retryable);
assertEquals(3, retryable.size());
@@ -198,7 +176,7 @@ public void testRetryable() throws Exception {
}
@Test
- public void testRetryableInherited() throws Exception {
+ void testRetryableInherited() throws Exception {
Map, Boolean> retryable = getRetryableExceptionClasses("s3", getContext());
System.err.println(retryable);
assertEquals(2, retryable.size());
@@ -206,7 +184,7 @@ public void testRetryableInherited() throws Exception {
}
@Test
- public void testRetryableInheritedMerge() throws Exception {
+ void testRetryableInheritedMerge() throws Exception {
Map, Boolean> retryable = getRetryableExceptionClasses("s4", getContext());
System.err.println(retryable);
assertEquals(3, retryable.size());
@@ -214,7 +192,7 @@ public void testRetryableInheritedMerge() throws Exception {
}
@Test
- public void testInheritSkippable() throws Exception {
+ void testInheritSkippable() throws Exception {
Map, Boolean> skippable = getSkippableExceptionClasses("s1", getContext());
System.err.println(skippable);
assertEquals(5, skippable.size());
@@ -225,7 +203,7 @@ public void testInheritSkippable() throws Exception {
}
@Test
- public void testInheritSkippableWithNoMerge() throws Exception {
+ void testInheritSkippableWithNoMerge() throws Exception {
Map, Boolean> skippable = getSkippableExceptionClasses("s2", getContext());
assertEquals(3, skippable.size());
containsClassified(skippable, IllegalArgumentException.class, true);
@@ -235,7 +213,7 @@ public void testInheritSkippableWithNoMerge() throws Exception {
}
@Test
- public void testInheritStreams() throws Exception {
+ void testInheritStreams() throws Exception {
Collection streams = getStreams("s1", getContext());
assertEquals(2, streams.size());
boolean c = false;
@@ -248,7 +226,7 @@ public void testInheritStreams() throws Exception {
}
@Test
- public void testInheritRetryListeners() throws Exception {
+ void testInheritRetryListeners() throws Exception {
Collection retryListeners = getRetryListeners("s1", getContext());
assertEquals(2, retryListeners.size());
boolean g = false;
@@ -266,7 +244,7 @@ else if (o instanceof DummyRetryListener) {
}
@Test
- public void testInheritStreamsWithNoMerge() throws Exception {
+ void testInheritStreamsWithNoMerge() throws Exception {
Collection streams = getStreams("s2", getContext());
assertEquals(1, streams.size());
boolean c = false;
@@ -279,7 +257,7 @@ public void testInheritStreamsWithNoMerge() throws Exception {
}
@Test
- public void testInheritRetryListenersWithNoMerge() throws Exception {
+ void testInheritRetryListenersWithNoMerge() throws Exception {
Collection retryListeners = getRetryListeners("s2", getContext());
assertEquals(1, retryListeners.size());
boolean h = false;
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DecisionJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DecisionJobParserTests.java
index bdb2cba7e0..f8b89f76b0 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DecisionJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DecisionJobParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2019 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,11 +15,10 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-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.Job;
import org.springframework.batch.core.JobExecution;
@@ -31,16 +30,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.Nullable;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class DecisionJobParserTests {
+@SpringJUnitConfig
+class DecisionJobParserTests {
@Autowired
@Qualifier("job")
@@ -50,7 +47,7 @@ public class DecisionJobParserTests {
private JobRepository jobRepository;
@Test
- public void testDecisionState() throws Exception {
+ void testDecisionState() throws Exception {
assertNotNull(job);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultFailureJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultFailureJobParserTests.java
index 42477f6dbb..b50661c214 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultFailureJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultFailureJobParserTests.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,28 +15,25 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class DefaultFailureJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class DefaultFailureJobParserTests extends AbstractJobParserTests {
@Test
- public void testDefaultFailure() throws Exception {
+ void testDefaultFailure() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultSuccessJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultSuccessJobParserTests.java
index 07f955f91a..3859bf4968 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultSuccessJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultSuccessJobParserTests.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,27 +15,24 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class DefaultSuccessJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class DefaultSuccessJobParserTests extends AbstractJobParserTests {
@Test
- public void testDefaultSuccess() throws Exception {
+ void testDefaultSuccess() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.java
index 18c0992296..8a6ee6d6cd 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.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,30 +15,27 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.lang.Nullable;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dan Garrette
* @author Mahmoud Ben Hassine
* @since 2.0
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class DefaultUnknownJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class DefaultUnknownJobParserTests extends AbstractJobParserTests {
@Test
- public void testDefaultUnknown() throws Exception {
+ void testDefaultUnknown() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DuplicateTransitionJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DuplicateTransitionJobParserTests.java
index 064aa3b4ac..710666cebd 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DuplicateTransitionJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DuplicateTransitionJobParserTests.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,30 +15,30 @@
*/
package org.springframework.batch.core.configuration.xml;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.ClassUtils;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* @author Dan Garrette
* @author Dave Syer
* @since 2.0
*/
-public class DuplicateTransitionJobParserTests {
+class DuplicateTransitionJobParserTests {
- @Test(expected = BeanDefinitionStoreException.class)
- @SuppressWarnings("resource")
- public void testNextAttributeWithNestedElement() throws Exception {
- new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(getClass(),
- "NextAttributeMultipleFinalJobParserTests-context.xml"));
+ @Test
+ void testNextAttributeWithNestedElement() {
+ assertThrows(BeanDefinitionStoreException.class, () -> new ClassPathXmlApplicationContext(ClassUtils
+ .addResourcePathToPackagePath(getClass(), "NextAttributeMultipleFinalJobParserTests-context.xml")));
}
- @Test(expected = BeanDefinitionStoreException.class)
- @SuppressWarnings("resource")
- public void testDuplicateTransition() throws Exception {
- new ClassPathXmlApplicationContext(
- ClassUtils.addResourcePathToPackagePath(getClass(), "DuplicateTransitionJobParserTests-context.xml"));
+ @Test
+ void testDuplicateTransition() {
+ assertThrows(BeanDefinitionStoreException.class, () -> new ClassPathXmlApplicationContext(
+ ClassUtils.addResourcePathToPackagePath(getClass(), "DuplicateTransitionJobParserTests-context.xml")));
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionDefaultStatusJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionDefaultStatusJobParserTests.java
index 0e8f678470..5a1ee0ca6d 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionDefaultStatusJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionDefaultStatusJobParserTests.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,28 +15,25 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class EndTransitionDefaultStatusJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class EndTransitionDefaultStatusJobParserTests extends AbstractJobParserTests {
@Test
- public void testEndTransitionDefaultStatus() throws Exception {
+ void testEndTransitionDefaultStatus() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionJobParserTests.java
index d4d9190861..5cf04b2469 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/EndTransitionJobParserTests.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,30 +15,27 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+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.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class EndTransitionJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class EndTransitionJobParserTests extends AbstractJobParserTests {
@Test
- public void testEndTransition() throws Exception {
+ void testEndTransition() throws Exception {
//
// First Launch
@@ -64,16 +61,7 @@ public void testEndTransition() throws Exception {
// Second Launch
//
stepNamesList.clear();
- try {
- jobExecution = createJobExecution();
- fail("JobInstanceAlreadyCompleteException expected");
- }
- catch (JobInstanceAlreadyCompleteException e) {
- //
- // Expected
- //
- }
-
+ assertThrows(JobInstanceAlreadyCompleteException.class, this::createJobExecution);
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionDefaultStatusJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionDefaultStatusJobParserTests.java
index 3214388d10..17fabe7979 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionDefaultStatusJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionDefaultStatusJobParserTests.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,28 +15,25 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class FailTransitionDefaultStatusJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class FailTransitionDefaultStatusJobParserTests extends AbstractJobParserTests {
@Test
- public void testFailTransitionDefaultStatus() throws Exception {
+ void testFailTransitionDefaultStatus() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionJobParserTests.java
index f6de0552f1..aae2910a6b 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FailTransitionJobParserTests.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,28 +15,25 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class FailTransitionJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class FailTransitionJobParserTests extends AbstractJobParserTests {
@Test
- public void testFailTransition() throws Exception {
+ void testFailTransition() throws Exception {
//
// First Launch
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.java
index 01e16fbb8e..f204a28825 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
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.Job;
import org.springframework.batch.core.JobExecution;
@@ -31,17 +30,15 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class FlowJobParserTests {
+@SpringJUnitConfig
+class FlowJobParserTests {
@Autowired
@Qualifier("job1")
@@ -63,7 +60,7 @@ public class FlowJobParserTests {
private JobRepository jobRepository;
@Test
- public void testFlowJob() throws Exception {
+ void testFlowJob() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParameters());
job1.execute(jobExecution);
@@ -74,7 +71,7 @@ public void testFlowJob() throws Exception {
}
@Test
- public void testFlowJobWithNestedTransitions() throws Exception {
+ void testFlowJobWithNestedTransitions() throws Exception {
assertNotNull(job2);
JobExecution jobExecution = jobRepository.createJobExecution(job2.getName(), new JobParameters());
job2.execute(jobExecution);
@@ -86,7 +83,7 @@ public void testFlowJobWithNestedTransitions() throws Exception {
}
@Test
- public void testFlowJobWithNoSteps() throws Exception {
+ void testFlowJobWithNoSteps() throws Exception {
assertNotNull(job3);
JobExecution jobExecution = jobRepository.createJobExecution(job3.getName(), new JobParameters());
job3.execute(jobExecution);
@@ -97,7 +94,7 @@ public void testFlowJobWithNoSteps() throws Exception {
}
@Test
- public void testFlowInSplit() throws Exception {
+ void testFlowInSplit() throws Exception {
assertNotNull(job4);
JobExecution jobExecution = jobRepository.createJobExecution(job4.getName(), new JobParameters());
job4.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.java
index c86fb2c5d8..2ee4e500a0 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
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.Job;
import org.springframework.batch.core.JobExecution;
@@ -34,17 +33,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.Nullable;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class FlowStepParserTests {
+@SpringJUnitConfig
+class FlowStepParserTests {
@Autowired
@Qualifier("job1")
@@ -66,7 +63,7 @@ public class FlowStepParserTests {
private JobRepository jobRepository;
@Test
- public void testFlowStep() throws Exception {
+ void testFlowStep() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParameters());
job1.execute(jobExecution);
@@ -77,7 +74,7 @@ public void testFlowStep() throws Exception {
}
@Test
- public void testFlowExternalStep() throws Exception {
+ void testFlowExternalStep() throws Exception {
assertNotNull(job2);
JobExecution jobExecution = jobRepository.createJobExecution(job2.getName(), new JobParameters());
job2.execute(jobExecution);
@@ -88,7 +85,7 @@ public void testFlowExternalStep() throws Exception {
}
@Test
- public void testRepeatedFlow() throws Exception {
+ void testRepeatedFlow() throws Exception {
assertNotNull(job3);
JobExecution jobExecution = jobRepository.createJobExecution(job3.getName(), new JobParameters());
job3.execute(jobExecution);
@@ -100,7 +97,7 @@ public void testRepeatedFlow() throws Exception {
@Test
// TODO: BATCH-1745
- public void testRestartedFlow() throws Exception {
+ void testRestartedFlow() throws Exception {
assertNotNull(job4);
JobExecution jobExecution = jobRepository.createJobExecution(job4.getName(), new JobParameters());
job4.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests.java
index 858d06fa61..5acc06b074 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009-2014 the original author or authors.
+ * Copyright 2009-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,13 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.Map;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.scope.context.StepSynchronizationManager;
@@ -37,12 +37,12 @@
* @author Dan Garrette
* @since 2.1
*/
-public class InlineItemHandlerParserTests {
+class InlineItemHandlerParserTests {
private ConfigurableApplicationContext context;
- @After
- public void close() {
+ @AfterEach
+ void close() {
if (context != null) {
context.close();
}
@@ -50,7 +50,7 @@ public void close() {
}
@Test
- public void testInlineHandlers() throws Exception {
+ void testInlineHandlers() {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests-context.xml");
Object step = context.getBean("inlineHandlers");
@@ -67,7 +67,7 @@ public void testInlineHandlers() throws Exception {
}
@Test
- public void testInlineAdapters() throws Exception {
+ void testInlineAdapters() {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests-context.xml");
Object step = context.getBean("inlineAdapters");
@@ -98,7 +98,7 @@ public void testInlineAdapters() throws Exception {
}
@Test
- public void testInlineHandlersWithStepScope() throws Exception {
+ void testInlineHandlersWithStepScope() {
context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml");
StepSynchronizationManager.register(new StepExecution("step", new JobExecution(123L)));
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerMethodAttributeParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerMethodAttributeParserTests.java
index 06814e530b..2814f7bcb1 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerMethodAttributeParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerMethodAttributeParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-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.core.configuration.xml;
-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.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.repository.JobRepository;
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;
/**
* @author Lucas Ward
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitConfig
public class JobExecutionListenerMethodAttributeParserTests {
public static boolean beforeCalled = false;
@@ -46,7 +43,7 @@ public class JobExecutionListenerMethodAttributeParserTests {
JobRepository jobRepository;
@Test
- public void testListeners() throws Exception {
+ void testListeners() throws Exception {
JobExecution jobExecution = jobRepository.createJobExecution("testJob",
new JobParametersBuilder().addLong("now", System.currentTimeMillis()).toJobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerParserTests.java
index f8ee428e2f..8f9d3a195d 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobExecutionListenerParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-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.core.configuration.xml;
-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.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
@@ -26,15 +25,13 @@
import org.springframework.batch.core.annotation.BeforeJob;
import org.springframework.batch.core.repository.JobRepository;
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;
/**
* @author Lucas Ward
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitConfig
public class JobExecutionListenerParserTests {
public static boolean beforeCalled = false;
@@ -48,7 +45,7 @@ public class JobExecutionListenerParserTests {
JobRepository jobRepository;
@Test
- public void testListeners() throws Exception {
+ void testListeners() throws Exception {
JobExecution jobExecution = jobRepository.createJobExecution("testJob",
new JobParametersBuilder().addLong("now", System.currentTimeMillis()).toJobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java
index 14b0cde801..49b5bec12d 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java
@@ -15,71 +15,52 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.NestedRuntimeException;
-public class JobParserExceptionTests {
+class JobParserExceptionTests {
@Test
- public void testUnreachableStep() {
- try {
- new ClassPathXmlApplicationContext(
- "org/springframework/batch/core/configuration/xml/JobParserUnreachableStepTests-context.xml");
- fail("Error expected");
- }
- catch (BeanDefinitionParsingException e) {
- assertTrue(e.getMessage().contains("The element [s2] is unreachable"));
- }
+ void testUnreachableStep() {
+ Exception exception = assertThrows(BeanDefinitionParsingException.class,
+ () -> new ClassPathXmlApplicationContext(
+ "org/springframework/batch/core/configuration/xml/JobParserUnreachableStepTests-context.xml"));
+ assertTrue(exception.getMessage().contains("The element [s2] is unreachable"));
}
@Test
- public void testUnreachableStepInFlow() {
- try {
- new ClassPathXmlApplicationContext(
- "org/springframework/batch/core/configuration/xml/JobParserUnreachableStepInFlowTests-context.xml");
- fail("Error expected");
- }
- catch (BeanDefinitionParsingException e) {
- assertTrue(e.getMessage().contains("The element [s4] is unreachable"));
- }
+ void testUnreachableStepInFlow() {
+ Exception exception = assertThrows(BeanDefinitionParsingException.class,
+ () -> new ClassPathXmlApplicationContext(
+ "org/springframework/batch/core/configuration/xml/JobParserUnreachableStepInFlowTests-context.xml"));
+ assertTrue(exception.getMessage().contains("The element [s4] is unreachable"));
}
@Test
- public void testNextOutOfScope() {
- try {
- new ClassPathXmlApplicationContext(
- "org/springframework/batch/core/configuration/xml/JobParserNextOutOfScopeTests-context.xml");
- fail("Error expected");
- }
- catch (BeanCreationException e) {
- String message = e.getRootCause().getMessage();
- assertTrue("Wrong message: " + message, message
- .matches(".*Missing state for \\[StateTransition: \\[state=.*s2, pattern=\\*, next=.*s3\\]\\]"));
- }
+ void testNextOutOfScope() {
+ NestedRuntimeException exception = assertThrows(BeanCreationException.class,
+ () -> new ClassPathXmlApplicationContext(
+ "org/springframework/batch/core/configuration/xml/JobParserNextOutOfScopeTests-context.xml"));
+ String message = exception.getRootCause().getMessage();
+ assertTrue(
+ message.matches(".*Missing state for \\[StateTransition: \\[state=.*s2, pattern=\\*, next=.*s3\\]\\]"),
+ "Wrong message: " + message);
}
@Test
- public void testWrongSchemaInRoot() {
- try {
- new ClassPathXmlApplicationContext(
- "org/springframework/batch/core/configuration/xml/JobParserWrongSchemaInRootTests-context.xml");
- fail("Error expected");
- }
- catch (BeanDefinitionParsingException e) {
- String message = e.getMessage();
- assertTrue("Wrong message: " + message,
- message.startsWith("Configuration problem: You are using a version of the spring-batch XSD"));
- }
- catch (BeanDefinitionStoreException e) {
- // Probably the internet is not available and the schema validation failed.
- fail("Wrong exception when schema didn't match: " + e.getMessage());
- }
+ void testWrongSchemaInRoot() {
+ Exception exception = assertThrows(BeanDefinitionParsingException.class,
+ () -> new ClassPathXmlApplicationContext(
+ "org/springframework/batch/core/configuration/xml/JobParserWrongSchemaInRootTests-context.xml"));
+ String message = exception.getMessage();
+ assertTrue(message.startsWith("Configuration problem: You are using a version of the spring-batch XSD"),
+ "Wrong message: " + message);
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBeanTests.java
index ae91f2e9c7..f3cb9eb1d7 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBeanTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBeanTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 the original author or authors.
+ * Copyright 2009-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,17 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class JobParserJobFactoryBeanTests {
+class JobParserJobFactoryBeanTests {
- private JobParserJobFactoryBean factory = new JobParserJobFactoryBean("jobFactory");
+ private final JobParserJobFactoryBean factory = new JobParserJobFactoryBean("jobFactory");
@Test
- public void testSingleton() throws Exception {
- assertTrue("Expected singleton", factory.isSingleton());
+ void testSingleton() {
+ assertTrue(factory.isSingleton(), "Expected singleton");
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.java
index 93304d4311..d04c078171 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecutionListener;
@@ -31,8 +30,7 @@
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-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.util.ReflectionTestUtils;
/**
@@ -41,9 +39,8 @@
* @author Mahmoud Ben Hassine
* @since 2.0
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class JobParserParentAttributeTests {
+@SpringJUnitConfig
+class JobParserParentAttributeTests {
@Autowired
@Qualifier("listenerClearingJob")
@@ -78,7 +75,7 @@ public class JobParserParentAttributeTests {
private Job job1;
@Test
- public void testInheritListeners() throws Exception {
+ void testInheritListeners() throws Exception {
List> job1Listeners = getListeners(job1);
assertEquals(2, job1Listeners.size());
boolean a = false;
@@ -96,7 +93,7 @@ else if (l instanceof DummyJobExecutionListener) {
}
@Test
- public void testInheritListeners_NoMerge() throws Exception {
+ void testInheritListeners_NoMerge() throws Exception {
List> job2Listeners = getListeners(job2);
assertEquals(1, job2Listeners.size());
boolean c = false;
@@ -109,7 +106,7 @@ public void testInheritListeners_NoMerge() throws Exception {
}
@Test
- public void testStandaloneListener() throws Exception {
+ void testStandaloneListener() throws Exception {
List> jobListeners = getListeners(job3);
assertEquals(2, jobListeners.size());
boolean a = false;
@@ -127,7 +124,7 @@ else if (l instanceof DummyJobExecutionListener) {
}
@Test
- public void testJobRepositoryDefaults() throws Exception {
+ void testJobRepositoryDefaults() throws Exception {
assertTrue(getJobRepository(defaultRepoJob) instanceof SimpleJobRepository);
assertTrue(getJobRepository(specifiedRepoJob) instanceof DummyJobRepository);
assertTrue(getJobRepository(inheritSpecifiedRepoJob) instanceof DummyJobRepository);
@@ -135,7 +132,7 @@ public void testJobRepositoryDefaults() throws Exception {
}
@Test
- public void testListenerClearingJob() throws Exception {
+ void testListenerClearingJob() throws Exception {
assertEquals(0, getListeners(listenerClearingJob).size());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserValidatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserValidatorTests.java
index ed1e6e37df..54e3b79887 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserValidatorTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserValidatorTests.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,14 +15,14 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersInvalidException;
@@ -31,17 +31,15 @@
import org.springframework.batch.core.job.DefaultJobParametersValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-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.util.ReflectionTestUtils;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class JobParserValidatorTests {
+@SpringJUnitConfig
+class JobParserValidatorTests {
@Autowired
@Qualifier("job1")
@@ -55,35 +53,35 @@ public class JobParserValidatorTests {
@Qualifier("job3")
private Job job3;
- @Test(expected = JobParametersInvalidException.class)
- public void testValidatorAttribute() throws Exception {
+ @Test
+ void testValidatorAttribute() {
assertNotNull(job1);
JobParametersValidator validator = (JobParametersValidator) ReflectionTestUtils.getField(job1,
"jobParametersValidator");
assertNotNull(validator);
- validator.validate(new JobParameters());
+ assertThrows(JobParametersInvalidException.class, () -> validator.validate(new JobParameters()));
}
- @Test(expected = JobParametersInvalidException.class)
- public void testValidatorRef() throws Exception {
+ @Test
+ void testValidatorRef() {
assertNotNull(job2);
JobParametersValidator validator = (JobParametersValidator) ReflectionTestUtils.getField(job2,
"jobParametersValidator");
assertNotNull(validator);
- validator.validate(new JobParameters());
+ assertThrows(JobParametersInvalidException.class, () -> validator.validate(new JobParameters()));
}
- @Test(expected = JobParametersInvalidException.class)
- public void testValidatorBean() throws Exception {
+ @Test
+ void testValidatorBean() {
assertNotNull(job3);
JobParametersValidator validator = (JobParametersValidator) ReflectionTestUtils.getField(job3,
"jobParametersValidator");
assertNotNull(validator);
- validator.validate(new JobParameters());
+ assertThrows(JobParametersInvalidException.class, () -> validator.validate(new JobParameters()));
}
@Test
- public void testParametersValidator() {
+ void testParametersValidator() {
assertTrue(job1 instanceof AbstractJob);
Object validator = ReflectionTestUtils.getField(job1, "jobParametersValidator");
assertTrue(validator instanceof DefaultJobParametersValidator);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests.java
index 1512152145..9c6f4cf623 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2013 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,25 +15,22 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.Job;
import org.springframework.batch.core.configuration.ListableJobLocator;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitConfig
public class JobRegistryJobParserTests implements ApplicationContextAware {
@Autowired
@@ -47,7 +44,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
}
@Test
- public void testOneStep() throws Exception {
+ void testOneStep() {
assertEquals(2, applicationContext.getBeanNamesForType(Job.class).length);
assertEquals(2, jobRegistry.getJobNames().size());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests.java
index 6a945b65d3..26871439af 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests.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,30 +15,27 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class JobRepositoryDefaultParserTests {
+@SpringJUnitConfig
+class JobRepositoryDefaultParserTests {
@Autowired
@Qualifier("jobRepository")
private JobRepository jobRepository;
@Test
- public void testOneStep() throws Exception {
+ void testOneStep() {
assertNotNull(jobRepository);
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserReferenceTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserReferenceTests.java
index cd95693ee8..d0a6d753b9 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserReferenceTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserReferenceTests.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,30 +15,27 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class JobRepositoryParserReferenceTests {
+@SpringJUnitConfig
+class JobRepositoryParserReferenceTests {
@Autowired
@Qualifier("jobRepo1")
private JobRepository jobRepository;
@Test
- public void testOneStep() throws Exception {
+ void testOneStep() {
assertNotNull(jobRepository);
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserTests.java
index f0b6353676..dade661504 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryParserTests.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,30 +15,27 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Thomas Risberg
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class JobRepositoryParserTests {
+@SpringJUnitConfig
+class JobRepositoryParserTests {
@Autowired
@Qualifier("jobRepo1")
private JobRepository jobRepository;
@Test
- public void testOneStep() throws Exception {
+ void testOneStep() {
assertNotNull(jobRepository);
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.java
index bdb8dcc51b..dff6c73368 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
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.Job;
import org.springframework.batch.core.JobExecution;
@@ -31,17 +30,15 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class JobStepParserTests {
+@SpringJUnitConfig
+class JobStepParserTests {
@Autowired
@Qualifier("job1")
@@ -55,7 +52,7 @@ public class JobStepParserTests {
private JobRepository jobRepository;
@Test
- public void testFlowStep() throws Exception {
+ void testFlowStep() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParameters());
job1.execute(jobExecution);
@@ -66,7 +63,7 @@ public void testFlowStep() throws Exception {
}
@Test
- public void testFlowExternalStep() throws Exception {
+ void testFlowExternalStep() throws Exception {
assertNotNull(job2);
JobExecution jobExecution = jobRepository.createJobExecution(job2.getName(), new JobParameters());
job2.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.java
index 0bfe06b9e8..f097fb88ce 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.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,11 +15,10 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-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.Job;
import org.springframework.batch.core.JobExecution;
@@ -27,17 +26,15 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class NamespacePrefixedJobParserTests {
+@SpringJUnitConfig
+class NamespacePrefixedJobParserTests {
@Autowired
@Qualifier("job1")
@@ -47,7 +44,7 @@ public class NamespacePrefixedJobParserTests {
private JobRepository jobRepository;
@Test
- public void testNoopJob() throws Exception {
+ void testNoopJob() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParameters());
job1.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeJobParserTests.java
index 2d679e8ed9..d510ca3f4c 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeJobParserTests.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,28 +15,25 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class NextAttributeJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class NextAttributeJobParserTests extends AbstractJobParserTests {
@Test
- public void testNextAttributeFailedDefault() throws Exception {
+ void testNextAttributeFailedDefault() throws Exception {
//
// Launch 1
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.java
index 2d496260e6..3720442df6 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.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,30 +15,27 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.lang.Nullable;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @since 2.1.9
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class NextAttributeUnknownJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class NextAttributeUnknownJobParserTests extends AbstractJobParserTests {
@Test
- public void testDefaultUnknown() throws Exception {
+ void testDefaultUnknown() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/OneStepJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/OneStepJobParserTests.java
index 0d38be1afd..f1a470d2fc 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/OneStepJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/OneStepJobParserTests.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,11 +15,10 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-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.Job;
import org.springframework.batch.core.JobExecution;
@@ -27,16 +26,14 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class OneStepJobParserTests {
+@SpringJUnitConfig
+class OneStepJobParserTests {
@Autowired
@Qualifier("job")
@@ -46,7 +43,7 @@ public class OneStepJobParserTests {
private JobRepository jobRepository;
@Test
- public void testOneStep() throws Exception {
+ void testOneStep() throws Exception {
assertNotNull(job);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.java
index 32ab2c9f67..9913385164 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.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,10 +15,10 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.step.item.FaultTolerantChunkProcessor;
import org.springframework.context.ConfigurableApplicationContext;
@@ -29,68 +29,63 @@
* @author Dave Syer
*
*/
-public class ParentStepFactoryBeanParserTests {
+class ParentStepFactoryBeanParserTests {
@Test
- @SuppressWarnings("resource")
- public void testSimpleAttributes() throws Exception {
+ void testSimpleAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
- assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor, ?>);
+ assertTrue(chunkProcessor instanceof FaultTolerantChunkProcessor, ?>, "Wrong processor type");
}
@Test
- @SuppressWarnings("resource")
- public void testSkippableAttributes() throws Exception {
+ void testSkippableAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentSkippableStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
- assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor, ?>);
+ assertTrue(chunkProcessor instanceof FaultTolerantChunkProcessor, ?>, "Wrong processor type");
}
@Test
- @SuppressWarnings("resource")
- public void testRetryableAttributes() throws Exception {
+ void testRetryableAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentRetryableStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
- assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor, ?>);
+ assertTrue(chunkProcessor instanceof FaultTolerantChunkProcessor, ?>, "Wrong processor type");
}
// BATCH-1396
@Test
- @SuppressWarnings("resource")
- public void testRetryableLateBindingAttributes() throws Exception {
+ void testRetryableLateBindingAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentRetryableLateBindingStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
- assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor, ?>);
+ assertTrue(chunkProcessor instanceof FaultTolerantChunkProcessor, ?>, "Wrong processor type");
}
// BATCH-1396
@Test
- @SuppressWarnings("resource")
- public void testSkippableLateBindingAttributes() throws Exception {
+ void testSkippableLateBindingAttributes() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentSkippableLateBindingStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
- assertNotNull("Step not parsed", step);
+ assertNotNull(step, "Step not parsed");
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
- assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor, ?>);
+ assertTrue(chunkProcessor instanceof FaultTolerantChunkProcessor, ?>, "Wrong processor type");
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.java
index fa0ef1318e..3790b31339 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.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,8 +15,8 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -25,9 +25,8 @@
import java.util.Collections;
import java.util.List;
-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.JobExecution;
@@ -45,8 +44,7 @@
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;
import org.springframework.util.ReflectionUtils;
/**
@@ -54,8 +52,7 @@
* @author Josh Long
* @author Mahmoud Ben Hassine
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitConfig
public class PartitionStepParserTests implements ApplicationContextAware {
@Autowired
@@ -94,8 +91,8 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
this.applicationContext = applicationContext;
}
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
nameStoringTasklet.setStepNamesList(savedStepNames);
}
@@ -110,7 +107,7 @@ private T accessPrivateField(Object o, String fieldName) {
}
@Test
- public void testDefaultHandlerStep() throws Exception {
+ void testDefaultHandlerStep() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParameters());
job1.execute(jobExecution);
@@ -124,7 +121,7 @@ public void testDefaultHandlerStep() throws Exception {
}
@Test
- public void testHandlerRefStep() throws Exception {
+ void testHandlerRefStep() throws Exception {
assertNotNull(job2);
JobExecution jobExecution = jobRepository.createJobExecution(job2.getName(), new JobParameters());
job2.execute(jobExecution);
@@ -142,8 +139,8 @@ public void testHandlerRefStep() throws Exception {
* handler has a reference to the inline step definition
*/
@Test
- public void testNestedPartitionStepStepReference() throws Throwable {
- assertNotNull("the reference to the job3 configured in the XML file must not be null", job3);
+ void testNestedPartitionStepStepReference() throws Throwable {
+ assertNotNull(job3, "the reference to the job3 configured in the XML file must not be null");
JobExecution jobExecution = jobRepository.createJobExecution(job3.getName(), new JobParameters());
job3.execute(jobExecution);
@@ -159,8 +156,8 @@ public void testNestedPartitionStepStepReference() throws Throwable {
"partitionHandler");
TaskletStep taskletStep = accessPrivateField(taskExecutorPartitionHandler, "step");
- assertNotNull("the taskletStep wasn't configured with a step. "
- + "We're trusting that the factory ensured " + "a reference was given.", taskletStep);
+ assertNotNull(taskletStep, "the taskletStep wasn't configured with a step. "
+ + "We're trusting that the factory ensured " + "a reference was given.");
}
}
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
@@ -181,8 +178,8 @@ public void testNestedPartitionStepStepReference() throws Throwable {
* handler has a reference to the inline step definition
*/
@Test
- public void testNestedPartitionStep() throws Throwable {
- assertNotNull("the reference to the job4 configured in the XML file must not be null", job4);
+ void testNestedPartitionStep() throws Throwable {
+ assertNotNull(job4, "the reference to the job4 configured in the XML file must not be null");
JobExecution jobExecution = jobRepository.createJobExecution(job4.getName(), new JobParameters());
job4.execute(jobExecution);
@@ -199,8 +196,8 @@ public void testNestedPartitionStep() throws Throwable {
"partitionHandler");
TaskletStep taskletStep = accessPrivateField(taskExecutorPartitionHandler, "step");
- assertNotNull("the taskletStep wasn't configured with a step. "
- + "We're trusting that the factory ensured " + "a reference was given.", taskletStep);
+ assertNotNull(taskletStep, "the taskletStep wasn't configured with a step. "
+ + "We're trusting that the factory ensured " + "a reference was given.");
}
}
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
@@ -214,7 +211,7 @@ public void testNestedPartitionStep() throws Throwable {
}
@Test
- public void testCustomHandlerRefStep() throws Exception {
+ void testCustomHandlerRefStep() throws Exception {
assertNotNull(job5);
JobExecution jobExecution = jobRepository.createJobExecution(job5.getName(), new JobParameters());
job5.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.java
index 88b2eaffcf..a2391387a4 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.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,16 +15,15 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-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.JobExecution;
@@ -36,17 +35,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.Nullable;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @author Josh Long
* @author Mahmoud Ben Hassine
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class PartitionStepWithFlowParserTests {
+@SpringJUnitConfig
+class PartitionStepWithFlowParserTests {
@Autowired
@Qualifier("job1")
@@ -59,15 +56,15 @@ public class PartitionStepWithFlowParserTests {
@Autowired
private JobRepository jobRepository;
- private List savedStepNames = new ArrayList<>();
+ private final List savedStepNames = new ArrayList<>();
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
nameStoringTasklet.setStepNamesList(savedStepNames);
}
@Test
- public void testRepeatedFlowStep() throws Exception {
+ void testRepeatedFlowStep() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(),
new JobParametersBuilder().addLong("gridSize", 1L).toJobParameters());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.java
index c964bae2c2..ee6c0fb2c5 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.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,16 +15,15 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-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.JobExecution;
@@ -33,17 +32,15 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @author Josh Long
* @author Mahmoud Ben Hassine
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class PartitionStepWithLateBindingParserTests {
+@SpringJUnitConfig
+class PartitionStepWithLateBindingParserTests {
@Autowired
@Qualifier("job1")
@@ -56,15 +53,15 @@ public class PartitionStepWithLateBindingParserTests {
@Autowired
private JobRepository jobRepository;
- private List savedStepNames = new ArrayList<>();
+ private final List savedStepNames = new ArrayList<>();
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
nameStoringTasklet.setStepNamesList(savedStepNames);
}
@Test
- public void testExplicitHandlerStep() throws Exception {
+ void testExplicitHandlerStep() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(),
new JobParametersBuilder().addLong("gridSize", 1L).toJobParameters());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java
index 454d256bf3..9508171ecd 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.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,28 +15,25 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-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.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.repository.JobRepository;
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;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class PartitionStepWithNonDefaultTransactionManagerParserTests {
+@SpringJUnitConfig
+class PartitionStepWithNonDefaultTransactionManagerParserTests {
@Autowired
private Job job;
@@ -45,7 +42,7 @@ public class PartitionStepWithNonDefaultTransactionManagerParserTests {
private JobRepository jobRepository;
@Test
- public void testDefaultHandlerStep() throws Exception {
+ void testDefaultHandlerStep() throws Exception {
assertNotNull(job);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests.java
index f4526f906e..0a8cad596e 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests.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,11 +15,10 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-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.Job;
import org.springframework.batch.core.JobExecution;
@@ -27,16 +26,14 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class RepositoryJobParserTests {
+@SpringJUnitConfig
+class RepositoryJobParserTests {
@Autowired
@Qualifier("job")
@@ -46,7 +43,7 @@ public class RepositoryJobParserTests {
private JobRepository jobRepository;
@Test
- public void testTaskletStepWithBadListener() throws Exception {
+ void testTaskletStepWithBadListener() throws Exception {
assertNotNull(job);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailFirstJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailFirstJobParserTests.java
index c04ebb49be..79e04e3a94 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailFirstJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailFirstJobParserTests.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,32 +15,29 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class SplitDifferentResultsFailFirstJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class SplitDifferentResultsFailFirstJobParserTests extends AbstractJobParserTests {
@Test
- public void testSplitDifferentResultsFailFirst() throws Exception {
+ void testSplitDifferentResultsFailFirst() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
assertEquals(2, stepNamesList.size());
- assertEquals("Wrong step names: " + stepNamesList, "[fail, s1]", stepNamesList.toString());
+ assertEquals("[fail, s1]", stepNamesList.toString(), "Wrong step names: " + stepNamesList);
assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailSecondJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailSecondJobParserTests.java
index c66a869495..97ece09a08 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailSecondJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitDifferentResultsFailSecondJobParserTests.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,34 +15,31 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-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
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class SplitDifferentResultsFailSecondJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class SplitDifferentResultsFailSecondJobParserTests extends AbstractJobParserTests {
@Test
- public void testSplitDifferentResultsFailSecond() throws Exception {
+ void testSplitDifferentResultsFailSecond() throws Exception {
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
- assertEquals("Wrong step names: " + stepNamesList, 3, stepNamesList.size());
- assertTrue("Wrong step names: " + stepNamesList, stepNamesList.contains("s1"));
- assertTrue("Wrong step names: " + stepNamesList, stepNamesList.contains("fail"));
+ assertEquals(3, stepNamesList.size(), "Wrong step names: " + stepNamesList);
+ assertTrue(stepNamesList.contains("s1"), "Wrong step names: " + stepNamesList);
+ assertTrue(stepNamesList.contains("fail"), "Wrong step names: " + stepNamesList);
assertTrue(stepNamesList.contains("s3"));
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitInterruptedJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitInterruptedJobParserTests.java
index 6ba4adea61..fbf838acf2 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitInterruptedJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitInterruptedJobParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2013 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,28 +15,25 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
* @since 2.0
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class SplitInterruptedJobParserTests extends AbstractJobParserTests {
+@SpringJUnitConfig
+class SplitInterruptedJobParserTests extends AbstractJobParserTests {
@Test
- public void testSplitInterrupted() throws Exception {
+ void testSplitInterrupted() throws Exception {
final JobExecution jobExecution = createJobExecution();
new Thread(new Runnable() {
@@ -53,12 +50,12 @@ public void run() {
while (jobExecution.getStatus() == BatchStatus.STOPPING && count++ < 10) {
Thread.sleep(200L);
}
- assertTrue("Timed out waiting for job to stop: " + jobExecution, count < 10);
+ assertTrue(count < 10, "Timed out waiting for job to stop: " + jobExecution);
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
assertEquals(ExitStatus.STOPPED.getExitCode(), jobExecution.getExitStatus().getExitCode());
- assertTrue("Wrong step names: " + stepNamesList, stepNamesList.contains("stop"));
+ assertTrue(stepNamesList.contains("stop"), "Wrong step names: " + stepNamesList);
StepExecution stepExecution = getStepExecution(jobExecution, "stop");
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitJobParserTests.java
index 83a0298185..85240859b7 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitJobParserTests.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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
import java.util.Collections;
-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.Job;
import org.springframework.batch.core.JobExecution;
@@ -31,16 +30,14 @@
import org.springframework.batch.core.step.StepLocator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
*
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class SplitJobParserTests {
+@SpringJUnitConfig
+class SplitJobParserTests {
@Autowired
@Qualifier("job")
@@ -50,7 +47,7 @@ public class SplitJobParserTests {
private JobRepository jobRepository;
@Test
- public void testSplitJob() throws Exception {
+ void testSplitJob() throws Exception {
assertNotNull(job);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitNestedJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitNestedJobParserTests.java
index d27603e377..ed59f4cb29 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitNestedJobParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/SplitNestedJobParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2011 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,11 +15,10 @@
*/
package org.springframework.batch.core.configuration.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-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.Job;
import org.springframework.batch.core.JobExecution;
@@ -27,16 +26,14 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Josh Long
- *
+ *
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class SplitNestedJobParserTests {
+@SpringJUnitConfig
+class SplitNestedJobParserTests {
@Autowired
@Qualifier("job")
@@ -46,7 +43,7 @@ public class SplitNestedJobParserTests {
private JobRepository jobRepository;
@Test
- public void testSplitJob() throws Exception {
+ void testSplitJob() throws Exception {
assertNotNull(job);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java
index d696532940..1505c491b1 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepListener;
@@ -30,8 +29,7 @@
import org.springframework.batch.core.step.tasklet.TaskletStep;
import org.springframework.beans.factory.BeanFactory;
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;
import org.springframework.test.util.ReflectionTestUtils;
/**
@@ -39,15 +37,14 @@
* @author Mahmoud Ben Hassine
* @since 2.0
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class StepListenerInStepParserTests {
+@SpringJUnitConfig
+class StepListenerInStepParserTests {
@Autowired
private BeanFactory beanFactory;
@Test
- public void testListenersAtStepLevel() throws Exception {
+ void testListenersAtStepLevel() throws Exception {
Step step = (Step) beanFactory.getBean("s1");
List> list = getListeners(step);
assertEquals(1, list.size());
@@ -56,7 +53,7 @@ public void testListenersAtStepLevel() throws Exception {
@Test
// TODO: BATCH-1689 (expected=BeanCreationException.class)
- public void testListenersAtStepLevelWrongType() throws Exception {
+ void testListenersAtStepLevelWrongType() throws Exception {
Step step = (Step) beanFactory.getBean("s2");
List> list = getListeners(step);
assertEquals(1, list.size());
@@ -64,7 +61,7 @@ public void testListenersAtStepLevelWrongType() throws Exception {
}
@Test
- public void testListenersAtTaskletAndStepLevels() throws Exception {
+ void testListenersAtTaskletAndStepLevels() throws Exception {
Step step = (Step) beanFactory.getBean("s3");
List> list = getListeners(step);
assertEquals(2, list.size());
@@ -73,7 +70,7 @@ public void testListenersAtTaskletAndStepLevels() throws Exception {
}
@Test
- public void testListenersAtChunkAndStepLevels() throws Exception {
+ void testListenersAtChunkAndStepLevels() throws Exception {
Step step = (Step) beanFactory.getBean("s4");
List> list = getListeners(step);
assertEquals(2, list.size());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerMethodAttributeParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerMethodAttributeParserTests.java
index d830259d88..0c82748b05 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerMethodAttributeParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerMethodAttributeParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-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,38 +15,35 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.step.tasklet.TaskletStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-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.util.ReflectionTestUtils;
/**
* @author Dan Garrette
* @since 2.0
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class StepListenerMethodAttributeParserTests {
+@SpringJUnitConfig
+class StepListenerMethodAttributeParserTests {
@Autowired
@Qualifier("s1")
private Step step1;
@Test
- public void testInheritListeners() throws Exception {
+ void testInheritListeners() throws Exception {
List> list = getListeners(step1);
assertEquals(2, list.size());
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java
index c2975350c8..fbb4cf065d 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-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,14 +15,13 @@
*/
package org.springframework.batch.core.configuration.xml;
-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.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepListener;
@@ -31,8 +30,7 @@
import org.springframework.batch.core.step.tasklet.TaskletStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-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.util.ReflectionTestUtils;
/**
@@ -40,9 +38,8 @@
* @author Mahmoud Ben Hassine
* @since 2.0
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
-public class StepListenerParserTests {
+@SpringJUnitConfig
+class StepListenerParserTests {
@Autowired
@Qualifier("s1")
@@ -57,7 +54,7 @@ public class StepListenerParserTests {
private Step step3;
@Test
- public void testInheritListeners() throws Exception {
+ void testInheritListeners() throws Exception {
List> list = getListeners(step1);
@@ -82,7 +79,7 @@ else if (listener instanceof CompositeStepExecutionListener) {
}
@Test
- public void testInheritListenersNoMerge() throws Exception {
+ void testInheritListenersNoMerge() throws Exception {
List> list = getListeners(step2);
@@ -102,7 +99,7 @@ else if (listener instanceof DummyStepExecutionListener) {
}
@Test
- public void testInheritListenersNoMergeFaultTolerant() throws Exception {
+ void testInheritListenersNoMergeFaultTolerant() throws Exception {
List> list = getListeners(step3);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepNameTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepNameTests.java
index 41d41ad28e..6932f31c12 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepNameTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepNameTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2008 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,19 +15,18 @@
*/
package org.springframework.batch.core.configuration.xml;
-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 java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.beans.factory.BeanCreationException;
@@ -36,49 +35,45 @@
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourceArrayPropertyEditor;
+import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
-@RunWith(Parameterized.class)
-public class StepNameTests {
+class StepNameTests {
- private Map stepLocators = new HashMap<>();
-
- private ApplicationContext context;
-
- public StepNameTests(Resource resource) throws Exception {
+ @Nullable
+ private ApplicationContext getContextFromResource(Resource resource) throws IOException {
try {
- context = new FileSystemXmlApplicationContext("file:///" + resource.getFile().getAbsolutePath());
+ return new FileSystemXmlApplicationContext("file:///" + resource.getFile().getAbsolutePath());
}
- catch (BeanDefinitionParsingException e) {
- return;
+ catch (BeanDefinitionParsingException | BeanCreationException e) {
+ return null;
}
- catch (BeanCreationException e) {
+ }
+
+ @MethodSource
+ @ParameterizedTest
+ void testStepNames(Resource resource) throws Exception {
+ ApplicationContext context = getContextFromResource(resource);
+ if (context == null) {
return;
}
Map stepLocators = context.getBeansOfType(StepLocator.class);
- this.stepLocators = stepLocators;
- }
-
- @Test
- public void testStepNames() throws Exception {
for (String name : stepLocators.keySet()) {
StepLocator stepLocator = stepLocators.get(name);
Collection stepNames = stepLocator.getStepNames();
Job job = (Job) context.getBean(name);
String jobName = job.getName();
- assertTrue("Job has no steps: " + jobName, !stepNames.isEmpty());
+ assertFalse(stepNames.isEmpty(), "Job has no steps: " + jobName);
for (String registeredName : stepNames) {
String stepName = stepLocator.getStep(registeredName).getName();
- assertEquals(
- "Step name not equal to registered value: " + stepName + "!=" + registeredName + ", " + jobName,
- stepName, registeredName);
+ assertEquals(stepName, registeredName, "Step name not equal to registered value: " + stepName + "!="
+ + registeredName + ", " + jobName);
}
}
}
- @Parameters
- public static List