Skip to content

Migrate Spring Batch Core to JUnit Jupiter #4172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions spring-batch-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
Expand Down Expand Up @@ -196,21 +202,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-vintage-engine.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -233,7 +227,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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));
Expand All @@ -53,58 +52,52 @@ 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));
assertEquals(BatchStatus.STARTED, BatchStatus.STARTED.upgradeTo(BatchStatus.STARTING));
}

@Test
public void testIsRunning() {
void testIsRunning() {
assertFalse(BatchStatus.FAILED.isRunning());
assertFalse(BatchStatus.COMPLETED.isRunning());
assertTrue(BatchStatus.STARTED.isRunning());
assertTrue(BatchStatus.STARTING.isRunning());
}

@Test
public void testIsUnsuccessful() {
void testIsUnsuccessful() {
assertTrue(BatchStatus.FAILED.isUnsuccessful());
assertFalse(BatchStatus.COMPLETED.isUnsuccessful());
assertFalse(BatchStatus.STARTED.isUnsuccessful());
assertFalse(BatchStatus.STARTING.isUnsuccessful());
}

@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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<JobParameters> jobKeyGenerator;
private final JobKeyGenerator<JobParameters> 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)
Expand All @@ -46,15 +41,15 @@ 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);
assertEquals(32, key.length());
}

@Test
public void testCreateJobKeyOrdering() {
void testCreateJobKeyOrdering() {
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
String key1 = jobKeyGenerator.generateKey(jobParameters1);
Expand Down
Loading