diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index 40957133e..08cf0d5fe 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -170,6 +170,11 @@ + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + org.hamcrest hamcrest-library diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java index bbbd58df1..ff17b7796 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,13 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** *

@@ -39,10 +37,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; *

*/ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/amqp-example-job.xml", "/job-runner-context.xml" }) -public class AMQPJobFunctionalTests { +class AMQPJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -51,7 +48,7 @@ public class AMQPJobFunctionalTests { private JobExplorer jobExplorer; @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { jobLauncherTestUtils.launchJob(); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java index b78110164..b5d16a584 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/BeanWrapperMapperSampleJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,23 +16,20 @@ package org.springframework.batch.sample; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml", +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/beanWrapperMapperSampleJob.xml", "/job-runner-context.xml" }) -public class BeanWrapperMapperSampleJobFunctionalTests { +class BeanWrapperMapperSampleJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testJobLaunch() throws Exception { + void testJobLaunch() throws Exception { jobLauncherTestUtils.launchJob(); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java index 05bfb1ad5..ce31eda86 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,24 +25,21 @@ import java.util.List; import javax.sql.DataSource; import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml", +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml", "/job-runner-context.xml" }) -public class CompositeItemWriterSampleFunctionalTests { +class CompositeItemWriterSampleFunctionalTests { private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM TRADE order by isin"; @@ -63,7 +60,7 @@ public class CompositeItemWriterSampleFunctionalTests { } @Test - public void testJobLaunch() throws Exception { + void testJobLaunch() throws Exception { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE"); int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"); @@ -75,7 +72,6 @@ public class CompositeItemWriterSampleFunctionalTests { } private void checkOutputTable(int before) { - @SuppressWarnings("serial") final List trades = new ArrayList() { { add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1")); @@ -107,7 +103,6 @@ public class CompositeItemWriterSampleFunctionalTests { } private void checkOutputFile(String fileName) throws IOException { - @SuppressWarnings("resource") List outputLines = IOUtils.readLines(new FileInputStream(fileName), "UTF-8"); String output = ""; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java index fd963336e..69110d385 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.ResultSet; import java.sql.SQLException; @@ -27,23 +27,20 @@ import java.util.Map; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.JobExecution; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/customerFilterJob.xml", "/job-runner-context.xml" }) -public class CustomerFilterJobFunctionalTests { +class CustomerFilterJobFunctionalTests { private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME"; @@ -53,7 +50,7 @@ public class CustomerFilterJobFunctionalTests { private JdbcTemplate jdbcTemplate; - private Map credits = new HashMap<>(); + private final Map credits = new HashMap<>(); @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -63,8 +60,8 @@ public class CustomerFilterJobFunctionalTests { this.jdbcTemplate = new JdbcTemplate(dataSource); } - @Before - public void onSetUp() throws Exception { + @BeforeEach + void onSetUp() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE"); JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4"); jdbcTemplate.update("update CUSTOMER set credit=100000"); @@ -76,14 +73,14 @@ public class CustomerFilterJobFunctionalTests { } } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE"); JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4"); } @Test - public void testFilterJob() throws Exception { + void testFilterJob() throws Exception { JobExecution jobExecution = jobLauncherTestUtils.launchJob(); customers = Arrays.asList(new Customer("customer1", (credits.get("customer1"))), diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java index 2e3d3fca4..a85443cd0 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,22 +16,20 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Functional test for graceful shutdown. A batch container is started in a new thread, @@ -41,10 +39,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Mahmoud Ben Hassine * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml", "/job-runner-context.xml" }) -public class DatabaseShutdownFunctionalTests { +class DatabaseShutdownFunctionalTests { /** Logger */ protected final Log logger = LogFactory.getLog(getClass()); @@ -56,7 +53,7 @@ public class DatabaseShutdownFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { JobExecution jobExecution = jobLauncherTestUtils.launchJob(); @@ -75,7 +72,7 @@ public class DatabaseShutdownFunctionalTests { count++; } - assertFalse("Timed out waiting for job to end.", jobExecution.isRunning()); + assertFalse(jobExecution.isRunning(), "Timed out waiting for job to end."); assertEquals(BatchStatus.STOPPED, jobExecution.getStatus()); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java index b4bea1cd4..4ca1283e4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DelegatingJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009 the original author or authors. + * Copyright 2007-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +15,18 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.person.PersonService; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/delegatingJob.xml", "/job-runner-context.xml" }) -public class DelegatingJobFunctionalTests { +class DelegatingJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -38,7 +35,7 @@ public class DelegatingJobFunctionalTests { private PersonService personService; @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { jobLauncherTestUtils.launchJob(); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java index 64619f919..283cf70db 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2021 the original author or authors. + * Copyright 2007-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,23 +15,20 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/footballJob.xml", "/job-runner-context.xml" }) -public class FootballJobFunctionalTests { +class FootballJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -44,7 +41,7 @@ public class FootballJobFunctionalTests { } @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS", "GAMES", "PLAYER_SUMMARY"); jobLauncherTestUtils.launchJob(); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java index 60bfd5494..9f0b9d269 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,13 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; @@ -31,8 +30,7 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Functional test for graceful shutdown. A batch container is started in a new thread, @@ -42,10 +40,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Parikshit Dutta * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml", "/job-runner-context.xml" }) -public class GracefulShutdownFunctionalTests { +class GracefulShutdownFunctionalTests { /** Logger */ private final Log logger = LogFactory.getLog(getClass()); @@ -57,7 +54,7 @@ public class GracefulShutdownFunctionalTests { private JobOperator jobOperator; @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { final JobParameters jobParameters = new JobParametersBuilder().addLong("timestamp", System.currentTimeMillis()) .toJobParameters(); @@ -78,7 +75,7 @@ public class GracefulShutdownFunctionalTests { count++; } - assertFalse("Timed out waiting for job to end.", jobExecution.isRunning()); + assertFalse(jobExecution.isRunning(), "Timed out waiting for job to end."); assertEquals(BatchStatus.STOPPED, jobExecution.getStatus()); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java index ddbe20d9a..09afcd451 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,36 +16,32 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( - locations = { "/simple-job-launcher-context.xml", "/jobs/groovyJob.xml", "/job-runner-context.xml" }) -public class GroovyJobFunctionalTests { +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/groovyJob.xml", "/job-runner-context.xml" }) +class GroovyJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - @Before - public void removeOldData() throws IOException { + @BeforeEach + void removeOldData() throws IOException { FileUtils.deleteDirectory(new File("target/groovyJob")); } @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { assertFalse(new File("target/groovyJob/output/files.zip").exists()); jobLauncherTestUtils.launchJob(); assertTrue(new File("target/groovyJob/output/files.zip").exists()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java index c19e80790..ec55a4510 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HeaderFooterSampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,24 +15,21 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedReader; import java.io.FileReader; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.io.Resource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/headerFooterSample.xml", "/job-runner-context.xml" }) -public class HeaderFooterSampleFunctionalTests { +class HeaderFooterSampleFunctionalTests { @Autowired @Qualifier("inputResource") @@ -46,7 +43,7 @@ public class HeaderFooterSampleFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testJob() throws Exception { + void testJob() throws Exception { jobLauncherTestUtils.launchJob(); BufferedReader inputReader = new BufferedReader(new FileReader(input.getFile())); @@ -60,7 +57,7 @@ public class HeaderFooterSampleFunctionalTests { int lineCount = 0; while ((line = inputReader.readLine()) != null) { lineCount++; - assertTrue("input line should correspond to output line", outputReader.readLine().contains(line)); + assertTrue(outputReader.readLine().contains(line), "input line should correspond to output line"); } // footer contains the item count diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java index 6215d12fb..d429200d9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2021 the original author or authors. + * Copyright 2007-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.math.BigDecimal; import java.sql.ResultSet; @@ -26,8 +26,7 @@ import java.util.List; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; @@ -40,8 +39,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.RowMapper; import org.springframework.orm.hibernate5.HibernateJdbcException; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; @@ -54,10 +52,9 @@ import org.springframework.transaction.support.TransactionTemplate; * @author Dave Syer * @author Mahmoud Ben Hassine */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/hibernate-context.xml", - "/jobs/hibernateJob.xml", "/job-runner-context.xml" }) -public class HibernateFailureJobFunctionalTests { +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/hibernate-context.xml", "/jobs/hibernateJob.xml", + "/job-runner-context.xml" }) +class HibernateFailureJobFunctionalTests { private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT; @@ -65,7 +62,7 @@ public class HibernateFailureJobFunctionalTests { private static final String CREDIT_COLUMN = "CREDIT"; - private static String[] customers = { + private static final String[] customers = { "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)", "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)", "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)", @@ -78,6 +75,7 @@ public class HibernateFailureJobFunctionalTests { private JdbcTemplate jdbcTemplate; + @Autowired private PlatformTransactionManager transactionManager; private List creditsBeforeUpdate; @@ -90,13 +88,8 @@ public class HibernateFailureJobFunctionalTests { this.jdbcTemplate = new JdbcTemplate(dataSource); } - @Autowired - public void setTransactionManager(PlatformTransactionManager transactionManager) { - this.transactionManager = transactionManager; - } - @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { validatePreConditions(); JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters(); @@ -126,7 +119,7 @@ public class HibernateFailureJobFunctionalTests { /** * All customers have the same credit */ - protected void validatePreConditions() throws Exception { + protected void validatePreConditions() { ensureState(); creditsBeforeUpdate = new TransactionTemplate(transactionManager) .execute(new TransactionCallback>() { @@ -163,7 +156,7 @@ public class HibernateFailureJobFunctionalTests { /** * Credit was increased by CREDIT_INCREASE */ - protected void validatePostConditions() throws Exception { + protected void validatePostConditions() { final List matches = new ArrayList<>(); new TransactionTemplate(transactionManager).execute(new TransactionCallback() { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java index ce0f86d5e..a411c087b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,10 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.Map; @@ -25,9 +26,8 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobParametersBuilder; @@ -35,12 +35,10 @@ import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.support.ReferenceJobFactory; import org.springframework.batch.core.launch.JobOperator; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml" }) -public class JobOperatorFunctionalTests { +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml" }) +class JobOperatorFunctionalTests { private static final Log LOG = LogFactory.getLog(JobOperatorFunctionalTests.class); @@ -53,15 +51,15 @@ public class JobOperatorFunctionalTests { @Autowired private JobRegistry jobRegistry; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { if (!jobRegistry.getJobNames().contains(job.getName())) { jobRegistry.register(new ReferenceJobFactory(job)); } } @Test - public void testStartStopResumeJob() throws Exception { + void testStartStopResumeJob() throws Exception { String params = new JobParametersBuilder().addLong("jobOperatorTestParam", 7L).toJobParameters().toString(); long executionId = operator.start(job.getName(), params); @@ -91,10 +89,10 @@ public class JobOperatorFunctionalTests { Thread.sleep(1000); Set runningExecutions = operator.getRunningExecutions(job.getName()); - assertTrue("Wrong executions: " + runningExecutions + " expected: " + executionId, - runningExecutions.contains(executionId)); - assertTrue("Wrong summary: " + operator.getSummary(executionId), - operator.getSummary(executionId).contains(BatchStatus.STARTED.toString())); + assertTrue(runningExecutions.contains(executionId), + "Wrong executions: " + runningExecutions + " expected: " + executionId); + assertTrue(operator.getSummary(executionId).contains(BatchStatus.STARTED.toString()), + "Wrong summary: " + operator.getSummary(executionId)); operator.stop(executionId); @@ -106,10 +104,10 @@ public class JobOperatorFunctionalTests { } runningExecutions = operator.getRunningExecutions(job.getName()); - assertFalse("Wrong executions: " + runningExecutions + " expected: " + executionId, - runningExecutions.contains(executionId)); - assertTrue("Wrong summary: " + operator.getSummary(executionId), - operator.getSummary(executionId).contains(BatchStatus.STOPPED.toString())); + assertFalse(runningExecutions.contains(executionId), + "Wrong executions: " + runningExecutions + " expected: " + executionId); + assertTrue(operator.getSummary(executionId).contains(BatchStatus.STOPPED.toString()), + "Wrong summary: " + operator.getSummary(executionId)); // there is just a single step in the test job Map summaries = operator.getStepExecutionSummaries(executionId); @@ -118,7 +116,7 @@ public class JobOperatorFunctionalTests { } @Test - public void testMultipleSimultaneousInstances() throws Exception { + void testMultipleSimultaneousInstances() throws Exception { String jobName = job.getName(); Set names = operator.getJobNames(); @@ -129,7 +127,7 @@ public class JobOperatorFunctionalTests { long exec2 = operator.startNextInstance(jobName); assertTrue(exec1 != exec2); - assertTrue(!operator.getParameters(exec1).equals(operator.getParameters(exec2))); + assertNotEquals(operator.getParameters(exec1), operator.getParameters(exec2)); // Give the asynchronous task executor a chance to start executions Thread.sleep(1000); @@ -147,8 +145,8 @@ public class JobOperatorFunctionalTests { running = operator.getSummary(exec1).contains("STARTED") && operator.getSummary(exec2).contains("STARTED"); } - assertTrue(String.format("Jobs not started: [%s] and [%s]", operator.getSummary(exec1), - operator.getSummary(exec1)), running); + assertTrue(running, String.format("Jobs not started: [%s] and [%s]", operator.getSummary(exec1), + operator.getSummary(exec1))); operator.stop(exec1); operator.stop(exec2); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java index 2cc6d95b5..4d6e5ce24 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,17 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.support.PropertiesConverter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; /** @@ -37,9 +35,8 @@ import org.springframework.test.jdbc.JdbcTestUtils; * @author Dave Syer * @author Mahmoud Ben Hassine */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class JobStepFunctionalTests { +@SpringJUnitConfig +class JobStepFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -52,7 +49,7 @@ public class JobStepFunctionalTests { } @Test - public void testJobLaunch() throws Exception { + void testJobLaunch() throws Exception { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE"); jobLauncherTestUtils diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java index 390cae1ef..fa66a651d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,8 @@ import java.nio.file.Paths; import javax.sql.DataSource; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; @@ -52,23 +51,25 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.util.DigestUtils; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Mahmoud Ben Hassine */ -public class JsonSupportIntegrationTests { +class JsonSupportIntegrationTests { private static final String INPUT_FILE_DIRECTORY = "src/test/resources/org/springframework/batch/item/json/"; private static final String OUTPUT_FILE_DIRECTORY = "target/"; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { Files.deleteIfExists(Paths.get("build", "trades.json")); } @Configuration @EnableBatchProcessing - public static class JobConfiguration { + static class JobConfiguration { @Autowired private JobBuilderFactory jobs; @@ -109,13 +110,13 @@ public class JsonSupportIntegrationTests { } @Test - public void testJsonReadingAndWriting() throws Exception { + void testJsonReadingAndWriting() throws Exception { ApplicationContext context = new AnnotationConfigApplicationContext(JobConfiguration.class); JobLauncher jobLauncher = context.getBean(JobLauncher.class); Job job = context.getBean(Job.class); JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); - Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); + assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); assertFileEquals(new File(INPUT_FILE_DIRECTORY + "trades.json"), new File(OUTPUT_FILE_DIRECTORY + "trades.json")); } @@ -123,7 +124,7 @@ public class JsonSupportIntegrationTests { private void assertFileEquals(File expected, File actual) throws Exception { String expectedHash = DigestUtils.md5DigestAsHex(new FileInputStream(expected)); String actualHash = DigestUtils.md5DigestAsHex(new FileInputStream(actual)); - Assert.assertEquals(expectedHash, actualHash); + assertEquals(expectedHash, actualHash); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java index 9e6c76fdb..082cc22c8 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/LoopFlowSampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,13 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Checks that expected number of items have been processed. @@ -31,10 +29,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Dan Garrette * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/loopFlowSample.xml", "/job-runner-context.xml" }) -public class LoopFlowSampleFunctionalTests { +class LoopFlowSampleFunctionalTests { @Autowired private ItemTrackingTradeItemWriter itemWriter; @@ -43,7 +40,7 @@ public class LoopFlowSampleFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testJobLaunch() throws Exception { + void testJobLaunch() throws Exception { jobLauncherTestUtils.launchJob(); // items processed = items read + 2 exceptions assertEquals(10, itemWriter.getItems().size()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java index 1ecf4d3a6..4abc32f5e 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,16 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Iterator; import java.util.List; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.sample.domain.mail.internal.TestMailErrorHandler; @@ -35,20 +34,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mail.MailMessage; import org.springframework.mail.SimpleMailMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; /** * @author Dan Garrette * @author Dave Syer * @author Mahmoud Ben Hassine - * @Since 2.1 + * @since 2.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( - locations = { "/simple-job-launcher-context.xml", "/jobs/mailJob.xml", "/job-runner-context.xml" }) -public class MailJobFunctionalTests { +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/mailJob.xml", "/job-runner-context.xml" }) +class MailJobFunctionalTests { private static final String email = "to@company.com"; @@ -84,20 +80,20 @@ public class MailJobFunctionalTests { jdbcTemplate = new JdbcTemplate(dataSource); } - @Before - public void before() { + @BeforeEach + void before() { mailSender.clear(); errorHandler.clear(); jdbcTemplate.update("create table USERS (ID INTEGER, NAME VARCHAR(40), EMAIL VARCHAR(20))"); } - @After - public void after() throws Exception { + @AfterEach + void after() { JdbcTestUtils.dropTables(jdbcTemplate, "USERS"); } @Test - public void testSkip() throws Exception { + void testSkip() throws Exception { this.createUsers(new Object[][] { USER1, USER2_SKIP, USER3, USER4_SKIP, USER5, USER6, USER7, USER8 }); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java index a84031219..c38a896f5 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,23 +17,20 @@ package org.springframework.batch.sample; import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.StringUtils; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/multilineJob.xml", "/job-runner-context.xml" }) -public class MultilineJobFunctionalTests { +class MultilineJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -43,10 +40,10 @@ public class MultilineJobFunctionalTests { private static final String EXPECTED_RESULT = "[Trade: [isin=UK21341EAH45,quantity=978,price=98.34,customer=customer1], Trade: [isin=UK21341EAH46,quantity=112,price=18.12,customer=customer2]]" + "[Trade: [isin=UK21341EAH47,quantity=245,price=12.78,customer=customer2], Trade: [isin=UK21341EAH48,quantity=108,price=9.25,customer=customer3], Trade: [isin=UK21341EAH49,quantity=854,price=23.39,customer=customer4]]"; - private Resource output = new FileSystemResource("target/test-outputs/20070122.testStream.multilineStep.txt"); + private final Resource output = new FileSystemResource("target/test-outputs/20070122.testStream.multilineStep.txt"); @Test - public void testJobLaunch() throws Exception { + void testJobLaunch() throws Exception { jobLauncherTestUtils.launchJob(); assertEquals(EXPECTED_RESULT, StringUtils.replace(IOUtils.toString(output.getInputStream(), "UTF-8"), System.getProperty("line.separator"), "")); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java index ef9458cb4..e900de909 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineOrderJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,19 +18,16 @@ package org.springframework.batch.sample; import static org.springframework.batch.test.AssertFile.assertFileEquals; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/multilineOrderJob.xml", "/job-runner-context.xml" }) -public class MultilineOrderJobFunctionalTests { +class MultilineOrderJobFunctionalTests { private static final String ACTUAL = "target/test-outputs/multilineOrderOutput.txt"; @@ -40,7 +37,7 @@ public class MultilineOrderJobFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testJobLaunch() throws Exception { + void testJobLaunch() throws Exception { jobLauncherTestUtils.launchJob(); assertFileEquals(new ClassPathResource(EXPECTED), new FileSystemResource(ACTUAL)); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java index 1ee733c2c..024af43b9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,25 +16,22 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/parallelJob.xml", "/job-runner-context.xml" }) -public class ParallelJobFunctionalTests { +class ParallelJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -47,7 +44,7 @@ public class ParallelJobFunctionalTests { } @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); JobExecution execution = jobLauncherTestUtils.launchJob(); int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java index d3ec63643..123c0557c 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionFileJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,15 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.item.ExecutionContext; @@ -39,13 +38,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/partitionFileJob.xml", "/job-runner-context.xml" }) -public class PartitionFileJobFunctionalTests implements ApplicationContextAware { +class PartitionFileJobFunctionalTests implements ApplicationContextAware { @Autowired @Qualifier("inputTestReader") @@ -65,9 +62,9 @@ public class PartitionFileJobFunctionalTests implements ApplicationContextAware * Check the resulting credits correspond to inputs increased by fixed amount. */ @Test - public void testUpdateCredit() throws Exception { - assertTrue("Define a prototype bean called 'outputTestReader' to check the output", - applicationContext.containsBeanDefinition("outputTestReader")); + void testUpdateCredit() throws Exception { + assertTrue(applicationContext.containsBeanDefinition("outputTestReader"), + "Define a prototype bean called 'outputTestReader' to check the output"); open(inputReader); List inputs = new ArrayList<>(getCredits(inputReader)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java index 33ec74b77..7adeaffae 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/PartitionJdbcJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,15 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.item.ExecutionContext; @@ -39,13 +38,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/partitionJdbcJob.xml", "/job-runner-context.xml" }) -public class PartitionJdbcJobFunctionalTests implements ApplicationContextAware { +class PartitionJdbcJobFunctionalTests implements ApplicationContextAware { @Autowired @Qualifier("inputTestReader") @@ -65,9 +62,9 @@ public class PartitionJdbcJobFunctionalTests implements ApplicationContextAware * Check the resulting credits correspond to inputs increased by fixed amount. */ @Test - public void testUpdateCredit() throws Exception { - assertTrue("Define a prototype bean called 'outputTestReader' to check the output", - applicationContext.containsBeanDefinition("outputTestReader")); + void testUpdateCredit() throws Exception { + assertTrue(applicationContext.containsBeanDefinition("outputTestReader"), + "Define a prototype bean called 'outputTestReader' to check the output"); open(inputReader); List inputs = new ArrayList<>(getCredits(inputReader)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java index 424942de0..144ded649 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,9 @@ package org.springframework.batch.sample; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; @@ -32,11 +29,11 @@ import org.springframework.batch.sample.remotechunking.ManagerConfiguration; import org.springframework.batch.sample.remotechunking.WorkerConfiguration; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * The manager step of the job under test will read data and send chunks to the worker @@ -45,22 +42,19 @@ import org.springframework.test.context.junit4.SpringRunner; * * @author Mahmoud Ben Hassine */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) +@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) @PropertySource("classpath:remote-chunking.properties") -public class RemoteChunkingJobFunctionalTests { - - private static final String BROKER_DATA_DIRECTORY = "target/activemq-data"; +class RemoteChunkingJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - private static EmbeddedActiveMQ brokerService; + private EmbeddedActiveMQ brokerService; private AnnotationConfigApplicationContext workerApplicationContext; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { Configuration configuration = new ConfigurationImpl().addAcceptorConfiguration("jms", "tcp://localhost:61616") .setPersistenceEnabled(false).setSecurityEnabled(false).setJMXManagementEnabled(false) .setJournalDatasync(false); @@ -68,21 +62,21 @@ public class RemoteChunkingJobFunctionalTests { this.workerApplicationContext = new AnnotationConfigApplicationContext(WorkerConfiguration.class); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { this.workerApplicationContext.close(); this.brokerService.stop(); } @Test - public void testRemoteChunkingJob() throws Exception { + void testRemoteChunkingJob() throws Exception { // when JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(); // then - Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); - Assert.assertEquals("Waited for 2 results.", // the manager sent 2 chunks ({1, 2, - // 3} and {4, 5, 6}) to workers + assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); + assertEquals("Waited for 2 results.", // the manager sent 2 chunks ({1, 2, + // 3} and {4, 5, 6}) to workers jobExecution.getExitStatus().getExitDescription()); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java index 163bb898c..969e6c5d4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,9 @@ import javax.sql.DataSource; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; @@ -35,14 +33,14 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.PropertySource; import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; -import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Base class for remote partitioning tests. * * @author Mahmoud Ben Hassine */ -@RunWith(SpringRunner.class) @PropertySource("classpath:remote-partitioning.properties") public abstract class RemotePartitioningJobFunctionalTests { @@ -63,8 +61,8 @@ public abstract class RemotePartitioningJobFunctionalTests { protected abstract Class getWorkerConfigurationClass(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { Configuration configuration = new ConfigurationImpl().addAcceptorConfiguration("jms", "tcp://localhost:61617") .setPersistenceEnabled(false).setSecurityEnabled(false).setJMXManagementEnabled(false) .setJournalDatasync(false); @@ -77,18 +75,18 @@ public abstract class RemotePartitioningJobFunctionalTests { } @Test - public void testRemotePartitioningJob() throws Exception { + void testRemotePartitioningJob() throws Exception { // when JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(); // then - Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); - Assert.assertEquals(4, jobExecution.getStepExecutions().size()); // manager + 3 - // workers + assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); + assertEquals(4, jobExecution.getStepExecutions().size()); // manager + 3 + // workers } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { this.workerApplicationContext.close(); this.brokerService.stop(); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java index 8fa4950a4..c6e837814 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithMessageAggregationFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,15 @@ package org.springframework.batch.sample; import org.springframework.batch.sample.config.JobRunnerConfiguration; import org.springframework.batch.sample.remotepartitioning.aggregating.ManagerConfiguration; import org.springframework.batch.sample.remotepartitioning.aggregating.WorkerConfiguration; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * The manager step of the job under test will create 3 partitions for workers to process. * * @author Mahmoud Ben Hassine */ -@ContextConfiguration(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) -public class RemotePartitioningJobWithMessageAggregationFunctionalTests extends RemotePartitioningJobFunctionalTests { +@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) +class RemotePartitioningJobWithMessageAggregationFunctionalTests extends RemotePartitioningJobFunctionalTests { @Override protected Class getWorkerConfigurationClass() { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java index 4e7e9e0de..db404d4c8 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemotePartitioningJobWithRepositoryPollingFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,15 @@ package org.springframework.batch.sample; import org.springframework.batch.sample.config.JobRunnerConfiguration; import org.springframework.batch.sample.remotepartitioning.polling.ManagerConfiguration; import org.springframework.batch.sample.remotepartitioning.polling.WorkerConfiguration; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * The manager step of the job under test will create 3 partitions for workers to process. * * @author Mahmoud Ben Hassine */ -@ContextConfiguration(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) -public class RemotePartitioningJobWithRepositoryPollingFunctionalTests extends RemotePartitioningJobFunctionalTests { +@SpringJUnitConfig(classes = { JobRunnerConfiguration.class, ManagerConfiguration.class }) +class RemotePartitioningJobWithRepositoryPollingFunctionalTests extends RemotePartitioningJobFunctionalTests { @Override protected Class getWorkerConfigurationClass() { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java index 53139af2d..494f846fd 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFileSampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; @@ -31,17 +30,15 @@ import org.springframework.batch.test.AssertFile; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dan Garrette * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/restartFileSampleJob.xml", "/job-runner-context.xml" }) -public class RestartFileSampleFunctionalTests { +class RestartFileSampleFunctionalTests { @Autowired private Resource outputResource; @@ -50,7 +47,7 @@ public class RestartFileSampleFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void runTest() throws Exception { + void runTest() throws Exception { JobParameters jobParameters = jobLauncherTestUtils.getUniqueJobParameters(); JobExecution je1 = jobLauncherTestUtils.launchJob(jobParameters); @@ -62,7 +59,7 @@ public class RestartFileSampleFunctionalTests { AssertFile.assertLineCount(20, outputResource); } - public static class CustomerCreditFlatFileItemWriter extends FlatFileItemWriter { + static class CustomerCreditFlatFileItemWriter extends FlatFileItemWriter { private boolean failed = false; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java index adea0bc07..ef826f45b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.converter.DefaultJobParametersConverter; @@ -29,8 +29,7 @@ import org.springframework.batch.support.PropertiesConverter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.jdbc.JdbcTestUtils; @@ -41,10 +40,9 @@ import org.springframework.test.jdbc.JdbcTestUtils; * @author Dave Syer * @author Mahmoud Ben Hassine */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/restartSample.xml", "/job-runner-context.xml" }) -public class RestartFunctionalTests { +class RestartFunctionalTests { private JdbcTemplate jdbcTemplate; @@ -57,7 +55,7 @@ public class RestartFunctionalTests { } @BeforeTransaction - public void onTearDown() throws Exception { + void onTearDown() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE"); } @@ -69,19 +67,14 @@ public class RestartFunctionalTests { * @throws Exception */ @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"); JobExecution jobExecution = runJobForRestartTest(); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); Throwable ex = jobExecution.getAllFailureExceptions().get(0); - if (ex.getMessage().toLowerCase().indexOf("planned") < 0) { - if (ex instanceof Exception) { - throw (Exception) ex; - } - throw new RuntimeException(ex); - } + assertTrue(ex.getMessage().toLowerCase().contains("planned")); int medium = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"); // assert based on commit interval = 2 diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java index c1b55d923..02020fee2 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,9 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.config.DataSourceConfiguration; import org.springframework.batch.sample.config.JobRunnerConfiguration; import org.springframework.batch.sample.config.RetrySampleConfiguration; @@ -26,8 +25,7 @@ import org.springframework.batch.sample.domain.trade.internal.GeneratingTradeIte import org.springframework.batch.sample.support.RetrySampleItemWriter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Checks that expected number of items have been processed. @@ -35,10 +33,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Robert Kasanicky * @author Dave Syer */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( classes = { DataSourceConfiguration.class, RetrySampleConfiguration.class, JobRunnerConfiguration.class }) -public class RetrySampleConfigurationTests { +class RetrySampleConfigurationTests { @Autowired private GeneratingTradeItemReader itemGenerator; @@ -50,7 +47,7 @@ public class RetrySampleConfigurationTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { jobLauncherTestUtils.launchJob(); // items processed = items read + 2 exceptions assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java index 3359d5907..8c5cbc07e 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RetrySampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +15,23 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.internal.GeneratingTradeItemReader; import org.springframework.batch.sample.support.RetrySampleItemWriter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Checks that expected number of items have been processed. * * @author Robert Kasanicky */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/retrySample.xml", "/job-runner-context.xml" }) -public class RetrySampleFunctionalTests { +class RetrySampleFunctionalTests { @Autowired private GeneratingTradeItemReader itemGenerator; @@ -46,7 +43,7 @@ public class RetrySampleFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { jobLauncherTestUtils.launchJob(); // items processed = items read + 2 exceptions assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java index 1a47cf9b3..89407584c 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,18 @@ */ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.util.Map; import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; @@ -54,8 +55,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Error is encountered during writing - transaction is rolled back and the error item is @@ -65,9 +65,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Dan Garrette * @author Mahmoud Ben Hassine */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/skipSample-job-launcher-context.xml" }) -public class SkipSampleFunctionalTests { +@SpringJUnitConfig(locations = { "/skipSample-job-launcher-context.xml" }) +class SkipSampleFunctionalTests { private JdbcTemplate jdbcTemplate; @@ -86,8 +85,8 @@ public class SkipSampleFunctionalTests { this.jdbcTemplate = new JdbcTemplate(dataSource); } - @Before - public void setUp() { + @BeforeEach + void setUp() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE", "CUSTOMER"); for (int i = 1; i < 10; i++) { jdbcTemplate.update("INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (" + incrementer.nextIntValue() @@ -155,7 +154,7 @@ public class SkipSampleFunctionalTests { * */ @Test - public void testJobIncrementing() { + void testJobIncrementing() { // // Launch 1 // @@ -184,7 +183,7 @@ public class SkipSampleFunctionalTests { // instances // assertTrue(id1 != id2); - assertTrue(!execution1.getJobId().equals(execution2.getJobId())); + assertNotEquals(execution1.getJobId(), execution2.getJobId()); } /* @@ -193,7 +192,7 @@ public class SkipSampleFunctionalTests { * written). */ @Test - public void testSkippableExceptionDuringRead() throws Exception { + void testSkippableExceptionDuringRead() throws Exception { // given ApplicationContext context = new AnnotationConfigApplicationContext(SkippableExceptionDuringReadSample.class); JobLauncher jobLauncher = context.getBean(JobLauncher.class); @@ -216,7 +215,7 @@ public class SkipSampleFunctionalTests { * the writer). */ @Test - public void testSkippableExceptionDuringProcess() throws Exception { + void testSkippableExceptionDuringProcess() throws Exception { // given ApplicationContext context = new AnnotationConfigApplicationContext( SkippableExceptionDuringProcessSample.class); @@ -242,7 +241,7 @@ public class SkipSampleFunctionalTests { * re-processed/re-written in its own transaction). */ @Test - public void testSkippableExceptionDuringWrite() throws Exception { + void testSkippableExceptionDuringWrite() throws Exception { // given ApplicationContext context = new AnnotationConfigApplicationContext(SkippableExceptionDuringWriteSample.class); JobLauncher jobLauncher = context.getBean(JobLauncher.class); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java index c75f29734..ac2b85e47 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,36 +16,33 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/taskletJob.xml", "/job-runner-context.xml" }) -public class TaskletJobFunctionalTests { +class TaskletJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { JobExecution jobExecution = jobLauncherTestUtils .launchJob(new JobParametersBuilder().addString("value", "foo").toJobParameters()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals("yes", jobExecution.getExecutionContext().getString("done")); } - public static class TestBean { + static class TestBean { private String value; @@ -62,7 +59,7 @@ public class TaskletJobFunctionalTests { } - public static class Task { + static class Task { public boolean doWork(ChunkContext chunkContext) { chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("done", "yes"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java index 421f314c9..64d978bf9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package org.springframework.batch.sample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.sql.ResultSet; @@ -29,23 +29,19 @@ import java.util.Map; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( - locations = { "/simple-job-launcher-context.xml", "/jobs/tradeJob.xml", "/job-runner-context.xml" }) -public class TradeJobFunctionalTests { +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/tradeJob.xml", "/job-runner-context.xml" }) +class TradeJobFunctionalTests { private static final String GET_TRADES = "select ISIN, QUANTITY, PRICE, CUSTOMER, ID, VERSION from TRADE order by ISIN"; @@ -59,7 +55,7 @@ public class TradeJobFunctionalTests { private JdbcTemplate jdbcTemplate; - private Map credits = new HashMap<>(); + private final Map credits = new HashMap<>(); @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -69,8 +65,8 @@ public class TradeJobFunctionalTests { this.jdbcTemplate = new JdbcTemplate(dataSource); } - @Before - public void onSetUp() throws Exception { + @BeforeEach + void onSetUp() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE"); List> list = jdbcTemplate.queryForList("select NAME, CREDIT from CUSTOMER"); @@ -79,13 +75,13 @@ public class TradeJobFunctionalTests { } } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE"); } @Test - public void testLaunchJob() throws Exception { + void testLaunchJob() throws Exception { jobLauncherTestUtils.launchJob(); customers = Arrays.asList(new Customer("customer1", (credits.get("customer1") - 98.34)), @@ -104,10 +100,10 @@ public class TradeJobFunctionalTests { public void processRow(ResultSet rs) throws SQLException { Trade trade = trades.get(activeRow++); - assertTrue(trade.getIsin().equals(rs.getString(1))); - assertTrue(trade.getQuantity() == rs.getLong(2)); - assertTrue(trade.getPrice().equals(rs.getBigDecimal(3))); - assertTrue(trade.getCustomer().equals(rs.getString(4))); + assertEquals(trade.getIsin(), rs.getString(1)); + assertEquals(trade.getQuantity(), rs.getLong(2)); + assertEquals(trade.getPrice(), rs.getBigDecimal(3)); + assertEquals(trade.getCustomer(), rs.getString(4)); } }); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ColumnRangePartitionerTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ColumnRangePartitionerTests.java index ab2aa818a..9bbf34a56 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ColumnRangePartitionerTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ColumnRangePartitionerTests.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,34 +15,27 @@ */ package org.springframework.batch.sample.common; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Map; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class ColumnRangePartitionerTests { - - private DataSource dataSource; +@SpringJUnitConfig +class ColumnRangePartitionerTests { @Autowired - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } + private DataSource dataSource; - private ColumnRangePartitioner partitioner = new ColumnRangePartitioner(); + private final ColumnRangePartitioner partitioner = new ColumnRangePartitioner(); @Test - public void testPartition() { + void testPartition() { partitioner.setDataSource(dataSource); partitioner.setTable("CUSTOMER"); partitioner.setColumn("ID"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemReaderTests.java index 359928f1b..8d9e431b6 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemReaderTests.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,14 +15,14 @@ */ package org.springframework.batch.sample.common; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; @@ -37,17 +37,12 @@ import org.springframework.lang.Nullable; * @author Lucas Ward * */ -public class CustomItemReaderTests { +class CustomItemReaderTests { private ItemReader itemReader; - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { List items = new ArrayList<>(); items.add("1"); items.add("2"); @@ -57,7 +52,7 @@ public class CustomItemReaderTests { } @Test - public void testRead() throws Exception { + void testRead() throws Exception { assertEquals("1", itemReader.read()); assertEquals("2", itemReader.read()); assertEquals("3", itemReader.read()); @@ -65,7 +60,7 @@ public class CustomItemReaderTests { } @Test - public void testRestart() throws Exception { + void testRestart() throws Exception { ExecutionContext executionContext = new ExecutionContext(); ((ItemStream) itemReader).open(executionContext); assertEquals("1", itemReader.read()); @@ -80,7 +75,7 @@ public class CustomItemReaderTests { assertEquals("2", itemReader.read()); } - public static class CustomItemReader implements ItemReader, ItemStream { + static class CustomItemReader implements ItemReader, ItemStream { private static final String CURRENT_INDEX = "current.index"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemWriterTests.java index 9a97b6e52..52ff595ff 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/CustomItemWriterTests.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. @@ -15,13 +15,13 @@ */ package org.springframework.batch.sample.common; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; @@ -33,10 +33,10 @@ import org.springframework.batch.support.transaction.TransactionAwareProxyFactor * @author Lucas Ward * */ -public class CustomItemWriterTests { +class CustomItemWriterTests { @Test - public void testFlush() throws Exception { + void testFlush() throws Exception { CustomItemWriter itemWriter = new CustomItemWriter<>(); itemWriter.write(Collections.singletonList("1")); assertEquals(1, itemWriter.getOutput().size()); @@ -44,7 +44,7 @@ public class CustomItemWriterTests { assertEquals(3, itemWriter.getOutput().size()); } - public static class CustomItemWriter implements ItemWriter { + static class CustomItemWriter implements ItemWriter { private List output = TransactionAwareProxyFactory.createTransactionalList(); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ExceptionThrowingItemReaderProxyTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ExceptionThrowingItemReaderProxyTests.java index 63d7a78ce..1d9268979 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ExceptionThrowingItemReaderProxyTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ExceptionThrowingItemReaderProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,47 +15,36 @@ */ package org.springframework.batch.sample.common; -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.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.repeat.context.RepeatContextSupport; import org.springframework.batch.repeat.support.RepeatSynchronizationManager; import org.springframework.batch.sample.support.ExceptionThrowingItemReaderProxy; -public class ExceptionThrowingItemReaderProxyTests { +class ExceptionThrowingItemReaderProxyTests { // expected call count before exception is thrown (exception should be thrown in next // iteration) private static final int ITER_COUNT = 5; - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() { RepeatSynchronizationManager.clear(); } - @SuppressWarnings("serial") @Test - public void testProcess() throws Exception { + void testProcess() throws Exception { // create module and set item processor and iteration count ExceptionThrowingItemReaderProxy itemReader = new ExceptionThrowingItemReaderProxy<>(); - itemReader.setDelegate(new ListItemReader<>(new ArrayList() { - { - add("a"); - add("b"); - add("c"); - add("d"); - add("e"); - add("f"); - } - })); - + itemReader.setDelegate(new ListItemReader<>(List.of("a", "b", "c", "d", "e", "f"))); itemReader.setThrowExceptionOnRecordNumber(ITER_COUNT + 1); RepeatSynchronizationManager.register(new RepeatContextSupport(null)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/OutputFileListenerTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/OutputFileListenerTests.java index aabe993c1..75fd4934a 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/OutputFileListenerTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/OutputFileListenerTests.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,33 +15,33 @@ */ package org.springframework.batch.sample.common; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class OutputFileListenerTests { +class OutputFileListenerTests { - private OutputFileListener listener = new OutputFileListener(); + private final OutputFileListener listener = new OutputFileListener(); - private StepExecution stepExecution = new StepExecution("foo", new JobExecution(0L), 1L); + private final StepExecution stepExecution = new StepExecution("foo", new JobExecution(0L), 1L); @Test - public void testCreateOutputNameFromInput() { + void testCreateOutputNameFromInput() { listener.createOutputNameFromInput(stepExecution); assertEquals("{outputFile=file:./target/output/foo.csv}", stepExecution.getExecutionContext().toString()); } @Test - public void testSetPath() { + void testSetPath() { listener.setPath("spam/"); listener.createOutputNameFromInput(stepExecution); assertEquals("{outputFile=spam/foo.csv}", stepExecution.getExecutionContext().toString()); } @Test - public void testSetOutputKeyName() { + void testSetOutputKeyName() { listener.setPath(""); listener.setOutputKeyName("spam"); listener.createOutputNameFromInput(stepExecution); @@ -49,7 +49,7 @@ public class OutputFileListenerTests { } @Test - public void testSetInputKeyName() { + void testSetInputKeyName() { listener.setPath(""); listener.setInputKeyName("spam"); stepExecution.getExecutionContext().putString("spam", "bar"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java index ec2c45496..98d50fcfc 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.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,23 +15,21 @@ */ package org.springframework.batch.sample.common; -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.fail; import java.util.Arrays; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.jdbc.JdbcTestUtils; @@ -42,9 +40,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration() -public class StagingItemReaderTests { +@SpringJUnitConfig +class StagingItemReaderTests { private JdbcTemplate jdbcTemplate; @@ -57,7 +54,7 @@ public class StagingItemReaderTests { @Autowired private StagingItemReader reader; - private Long jobId = 113L; + private final Long jobId = 113L; @Autowired public void setDataSource(DataSource dataSource) { @@ -65,7 +62,7 @@ public class StagingItemReaderTests { } @BeforeTransaction - public void onSetUpBeforeTransaction() throws Exception { + void onSetUpBeforeTransaction() { StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(jobId, "testJob"), new JobParameters())); writer.beforeStep(stepExecution); @@ -74,14 +71,14 @@ public class StagingItemReaderTests { } @AfterTransaction - public void onTearDownAfterTransaction() throws Exception { + void onTearDownAfterTransaction() throws Exception { reader.destroy(); JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_STAGING"); } @Transactional @Test - public void testReaderWithProcessorUpdatesProcessIndicator() throws Exception { + void testReaderWithProcessorUpdatesProcessIndicator() throws Exception { long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, jobId); String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); assertEquals(StagingItemWriter.NEW, before); @@ -100,7 +97,7 @@ public class StagingItemReaderTests { @Transactional @Test - public void testUpdateProcessIndicatorAfterCommit() throws Exception { + void testUpdateProcessIndicatorAfterCommit() { TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); txTemplate.execute(new TransactionCallback() { @@ -122,7 +119,7 @@ public class StagingItemReaderTests { @Transactional @Test - public void testReaderRollsBackProcessIndicator() throws Exception { + void testReaderRollsBackProcessIndicator() { TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java index eb4257e01..763f560d0 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.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,29 +15,26 @@ */ package org.springframework.batch.sample.common; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Collections; import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class StagingItemWriterTests { +@SpringJUnitConfig +class StagingItemWriterTests { private JdbcTemplate jdbcTemplate; @@ -49,8 +46,8 @@ public class StagingItemWriterTests { this.jdbcTemplate = new JdbcTemplate(dataSource); } - @Before - public void onSetUpBeforeTransaction() throws Exception { + @BeforeEach + void onSetUpBeforeTransaction() { StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(12L, "testJob"), new JobParameters())); writer.beforeStep(stepExecution); @@ -58,7 +55,7 @@ public class StagingItemWriterTests { @Transactional @Test - public void testProcessInsertsNewItem() throws Exception { + void testProcessInsertsNewItem() { int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); writer.write(Collections.singletonList("FOO")); int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java index 1f74bfcb9..f08c2423d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.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. @@ -15,7 +15,7 @@ */ package org.springframework.batch.sample.domain.football.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.ResultSet; import java.sql.SQLException; @@ -23,30 +23,27 @@ import java.util.Collections; import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.football.Game; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.annotation.Transactional; /** * @author Lucas Ward * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/data-source-context.xml" }) -public class JdbcGameDaoIntegrationTests { +@SpringJUnitConfig(locations = { "/data-source-context.xml" }) +class JdbcGameDaoIntegrationTests { private JdbcGameDao gameDao; - private Game game = new Game(); + private final Game game = new Game(); private JdbcOperations jdbcTemplate; @@ -58,8 +55,8 @@ public class JdbcGameDaoIntegrationTests { gameDao.afterPropertiesSet(); } - @Before - public void onSetUpBeforeTransaction() throws Exception { + @BeforeEach + void onSetUpBeforeTransaction() { game.setId("XXXXX00"); game.setYear(1996); game.setTeam("mia"); @@ -79,7 +76,7 @@ public class JdbcGameDaoIntegrationTests { @Transactional @Test - public void testWrite() { + void testWrite() { gameDao.write(Collections.singletonList(game)); Game tempGame = jdbcTemplate.queryForObject("SELECT * FROM GAMES where PLAYER_ID=? AND YEAR_NO=?", diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java index eb337e9bb..16757ddd6 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.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,22 +15,20 @@ */ package org.springframework.batch.sample.domain.football.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.football.Player; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; @@ -39,9 +37,8 @@ import org.springframework.transaction.annotation.Transactional; * @author Mahmoud Ben Hassine * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/data-source-context.xml" }) -public class JdbcPlayerDaoIntegrationTests { +@SpringJUnitConfig(locations = { "/data-source-context.xml" }) +class JdbcPlayerDaoIntegrationTests { private JdbcPlayerDao playerDao; @@ -66,14 +63,14 @@ public class JdbcPlayerDaoIntegrationTests { player.setDebutYear(1998); } - @Before - public void onSetUpInTransaction() throws Exception { + @BeforeEach + void onSetUpInTransaction() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS"); } @Test @Transactional - public void testSavePlayer() { + void testSavePlayer() { playerDao.savePlayer(player); jdbcTemplate.query(GET_PLAYER, new RowCallbackHandler() { @Override diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java index ed522ada9..f156f057f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.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,20 +15,18 @@ */ package org.springframework.batch.sample.domain.football.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Collections; import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.football.PlayerSummary; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; @@ -37,9 +35,8 @@ import org.springframework.transaction.annotation.Transactional; * @author Mahmoud Ben Hassine * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/data-source-context.xml" }) -public class JdbcPlayerSummaryDaoIntegrationTests { +@SpringJUnitConfig(locations = { "/data-source-context.xml" }) +class JdbcPlayerSummaryDaoIntegrationTests { private JdbcPlayerSummaryDao playerSummaryDao; @@ -68,14 +65,14 @@ public class JdbcPlayerSummaryDaoIntegrationTests { summary.setTotalTd(0); } - @Before - public void onSetUpInTransaction() throws Exception { + @BeforeEach + void onSetUpInTransaction() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYER_SUMMARY"); } @Test @Transactional - public void testWrite() { + void testWrite() { playerSummaryDao.write(Collections.singletonList(summary)); PlayerSummary testSummary = jdbcTemplate.queryForObject("SELECT * FROM PLAYER_SUMMARY", diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java index 3d88a5c65..cf23c6457 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,57 +15,51 @@ */ package org.springframework.batch.sample.domain.multiline; -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 org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.FieldSet; -public class AggregateItemFieldSetMapperTests { +class AggregateItemFieldSetMapperTests { - private AggregateItemFieldSetMapper mapper = new AggregateItemFieldSetMapper<>(); + private final AggregateItemFieldSetMapper mapper = new AggregateItemFieldSetMapper<>(); @Test - public void testDefaultBeginRecord() throws Exception { + void testDefaultBeginRecord() throws Exception { assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "BEGIN" })).isHeader()); assertFalse(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "BEGIN" })).isFooter()); } @Test - public void testSetBeginRecord() throws Exception { + void testSetBeginRecord() throws Exception { mapper.setBegin("FOO"); assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "FOO" })).isHeader()); } @Test - public void testDefaultEndRecord() throws Exception { + void testDefaultEndRecord() throws Exception { assertFalse(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "END" })).isHeader()); assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "END" })).isFooter()); } @Test - public void testSetEndRecord() throws Exception { + void testSetEndRecord() throws Exception { mapper.setEnd("FOO"); assertTrue(mapper.mapFieldSet(new DefaultFieldSet(new String[] { "FOO" })).isFooter()); } @Test - public void testMandatoryProperties() throws Exception { - try { - mapper.afterPropertiesSet(); - fail("Expected IllegalArgumentException"); - } - catch (IllegalArgumentException e) { - // expected - } + void testMandatoryProperties() { + assertThrows(IllegalArgumentException.class, mapper::afterPropertiesSet); } @Test - public void testDelegate() throws Exception { + void testDelegate() throws Exception { mapper.setDelegate(new FieldSetMapper() { @Override public String mapFieldSet(FieldSet fs) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemReaderTests.java index fa386ede4..cf09f0c75 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 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,23 +15,21 @@ */ package org.springframework.batch.sample.domain.multiline; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; 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.springframework.batch.item.ItemReader; import org.springframework.lang.Nullable; -public class AggregateItemReaderTests { - - private ItemReader> input; +class AggregateItemReaderTests { private AggregateItemReader provider; - @Before - public void setUp() { - input = new ItemReader>() { + @BeforeEach + void setUp() { + ItemReader> input = new ItemReader<>() { private int count = 0; @Nullable @@ -58,7 +56,7 @@ public class AggregateItemReaderTests { } @Test - public void testNext() throws Exception { + void testNext() throws Exception { Object result = provider.read(); Collection lines = (Collection) result; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemTests.java index b1dae3588..be2afcbe9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemTests.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. @@ -15,58 +15,38 @@ */ package org.springframework.batch.sample.domain.multiline; -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.assertFalse; +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; /** * @author Dave Syer * */ -public class AggregateItemTests { +class AggregateItemTests { - /** - * Test method for - * {@link org.springframework.batch.sample.domain.multiline.AggregateItem#getFooter()}. - */ @Test - public void testGetFooter() { + void testGetFooter() { assertTrue(AggregateItem.getFooter().isFooter()); assertFalse(AggregateItem.getFooter().isHeader()); } - /** - * Test method for - * {@link org.springframework.batch.sample.domain.multiline.AggregateItem#getHeader()}. - */ @Test - public void testGetHeader() { + void testGetHeader() { assertTrue(AggregateItem.getHeader().isHeader()); assertFalse(AggregateItem.getHeader().isFooter()); } @Test - public void testBeginRecordHasNoItem() throws Exception { - try { - AggregateItem.getHeader().getItem(); - fail("Expected IllegalStateException"); - } - catch (IllegalStateException e) { - // expected - } + void testBeginRecordHasNoItem() { + assertThrows(IllegalStateException.class, () -> AggregateItem.getHeader().getItem()); } @Test - public void testEndRecordHasNoItem() throws Exception { - try { - AggregateItem.getFooter().getItem(); - fail("Expected IllegalStateException"); - } - catch (IllegalStateException e) { - // expected - } + void testEndRecordHasNoItem() { + assertThrows(IllegalStateException.class, () -> AggregateItem.getFooter().getItem()); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/AddressFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/AddressFieldSetMapperTests.java index 500414029..d369e8da9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/AddressFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/AddressFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.order.internal.mapper.AddressFieldSetMapper; import org.springframework.batch.sample.support.AbstractFieldSetMapperTests; -public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests { +class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests { private static final String ADDRESSEE = "Jan Hrach"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/BillingFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/BillingFieldSetMapperTests.java index 9daec6487..ab3f741d3 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/BillingFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/BillingFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.order.internal.mapper.BillingFieldSetMapper; import org.springframework.batch.sample.support.AbstractFieldSetMapperTests; -public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests { +class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests { private static final String PAYMENT_ID = "777"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/CustomerFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/CustomerFieldSetMapperTests.java index 6e013d3a2..dd1b0980d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/CustomerFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/CustomerFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.order.internal.mapper.CustomerFieldSetMapper; import org.springframework.batch.sample.support.AbstractFieldSetMapperTests; -public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests { +class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests { private static final boolean BUSINESS_CUSTOMER = false; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/HeaderFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/HeaderFieldSetMapperTests.java index 451cdcc8f..4d385eb10 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/HeaderFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/HeaderFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.order.internal.mapper.HeaderFieldSetMapper; import org.springframework.batch.sample.support.AbstractFieldSetMapperTests; -public class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests { +class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests { private static final long ORDER_ID = 1; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemFieldSetMapperTests.java index 677fcc1e4..3a4922711 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.order.internal.mapper.OrderItemFieldSetMapper; import org.springframework.batch.sample.support.AbstractFieldSetMapperTests; -public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests { +class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests { private static final BigDecimal DISCOUNT_AMOUNT = new BigDecimal("1"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemReaderTests.java index d4fdaa764..659d19a26 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,30 +15,30 @@ */ package org.springframework.batch.sample.domain.order; -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.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.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.order.internal.OrderItemReader; -public class OrderItemReaderTests { +class OrderItemReaderTests { private OrderItemReader provider; private ItemReader
input; - @Before + @BeforeEach @SuppressWarnings("unchecked") - public void setUp() { + void setUp() { input = mock(ItemReader.class); provider = new OrderItemReader(); @@ -56,7 +56,7 @@ public class OrderItemReaderTests { */ @Test @SuppressWarnings("unchecked") - public void testNext() throws Exception { + void testNext() throws Exception { FieldSet headerFS = new DefaultFieldSet(new String[] { Order.LINE_ID_HEADER }); FieldSet customerFS = new DefaultFieldSet(new String[] { Customer.LINE_ID_NON_BUSINESS_CUST }); FieldSet billingFS = new DefaultFieldSet(new String[] { Address.LINE_ID_BILLING_ADDR }); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/ShippingFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/ShippingFieldSetMapperTests.java index c20add4a6..3eec81b36 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/ShippingFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/ShippingFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.order.internal.mapper.ShippingFieldSetMapper; import org.springframework.batch.sample.support.AbstractFieldSetMapperTests; -public class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests { +class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests { private static final String SHIPPER_ID = "1"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidatorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidatorTests.java index ebafe70fa..f3bf3cc2a 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidatorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidatorTests.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,16 +15,15 @@ */ package org.springframework.batch.sample.domain.order.internal.validator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.order.Address; import org.springframework.batch.sample.domain.order.BillingInfo; import org.springframework.batch.sample.domain.order.Customer; @@ -34,22 +33,17 @@ import org.springframework.batch.sample.domain.order.ShippingInfo; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.Errors; -public class OrderValidatorTests { +class OrderValidatorTests { - private OrderValidator orderValidator; - - @Before - public void setUp() throws Exception { - orderValidator = new OrderValidator(); - } + private final OrderValidator orderValidator = new OrderValidator(); @Test - public void testSupports() { + void testSupports() { assertTrue(orderValidator.supports(Order.class)); } @Test - public void testNotAnOrder() { + void testNotAnOrder() { String notAnOrder = "order"; Errors errors = new BeanPropertyBindingResult(notAnOrder, "validOrder"); @@ -65,7 +59,7 @@ public class OrderValidatorTests { } @Test - public void testValidOrder() { + void testValidOrder() { Order order = new Order(); order.setOrderId(-5); order.setOrderDate(new Date(new Date().getTime() + 1000000000L)); @@ -113,7 +107,7 @@ public class OrderValidatorTests { } @Test - public void testValidCustomer() { + void testValidCustomer() { Order order = new Order(); Customer customer = new Customer(); customer.setRegistered(false); @@ -182,7 +176,7 @@ public class OrderValidatorTests { } @Test - public void testValidAddress() { + void testValidAddress() { Order order = new Order(); Errors errors = new BeanPropertyBindingResult(order, "validOrder"); @@ -240,7 +234,7 @@ public class OrderValidatorTests { } @Test - public void testValidPayment() { + void testValidPayment() { Order order = new Order(); BillingInfo info = new BillingInfo(); info.setPaymentId("INVALID"); @@ -266,7 +260,7 @@ public class OrderValidatorTests { } @Test - public void testValidShipping() { + void testValidShipping() { Order order = new Order(); ShippingInfo info = new ShippingInfo(); info.setShipperId("INVALID"); @@ -306,7 +300,7 @@ public class OrderValidatorTests { } @Test - public void testValidLineItems() { + void testValidLineItems() { Order order = new Order(); List lineItems = new ArrayList<>(); lineItems.add(buildLineItem(-5, 5.00, 0, 0, 2, 3, 3, 30)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java index 558d1ea32..c106cbca4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 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,10 +15,11 @@ */ package org.springframework.batch.sample.domain.trade; -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.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.item.file.transform.LineTokenizer; @@ -28,18 +29,18 @@ import org.springframework.lang.Nullable; * @author Lucas Ward * */ -public class CompositeCustomerUpdateLineTokenizerTests { +class CompositeCustomerUpdateLineTokenizerTests { private StubLineTokenizer customerTokenizer; - private FieldSet customerFieldSet = new DefaultFieldSet(null); + private final FieldSet customerFieldSet = new DefaultFieldSet(null); - private FieldSet footerFieldSet = new DefaultFieldSet(null); + private final FieldSet footerFieldSet = new DefaultFieldSet(null); private CompositeCustomerUpdateLineTokenizer compositeTokenizer; - @Before - public void init() { + @BeforeEach + void init() { customerTokenizer = new StubLineTokenizer(customerFieldSet); compositeTokenizer = new CompositeCustomerUpdateLineTokenizer(); compositeTokenizer.setCustomerTokenizer(customerTokenizer); @@ -47,7 +48,7 @@ public class CompositeCustomerUpdateLineTokenizerTests { } @Test - public void testCustomerAdd() throws Exception { + void testCustomerAdd() { String customerAddLine = "AFDASFDASFDFSA"; FieldSet fs = compositeTokenizer.tokenize(customerAddLine); assertEquals(customerFieldSet, fs); @@ -55,7 +56,7 @@ public class CompositeCustomerUpdateLineTokenizerTests { } @Test - public void testCustomerDelete() throws Exception { + void testCustomerDelete() { String customerAddLine = "DFDASFDASFDFSA"; FieldSet fs = compositeTokenizer.tokenize(customerAddLine); assertEquals(customerFieldSet, fs); @@ -63,17 +64,17 @@ public class CompositeCustomerUpdateLineTokenizerTests { } @Test - public void testCustomerUpdate() throws Exception { + void testCustomerUpdate() { String customerAddLine = "UFDASFDASFDFSA"; FieldSet fs = compositeTokenizer.tokenize(customerAddLine); assertEquals(customerFieldSet, fs); assertEquals(customerAddLine, customerTokenizer.getTokenizedLine()); } - @Test(expected = IllegalArgumentException.class) - public void testInvalidLine() throws Exception { + @Test + void testInvalidLine() { String invalidLine = "INVALID"; - compositeTokenizer.tokenize(invalidLine); + assertThrows(IllegalArgumentException.class, () -> compositeTokenizer.tokenize(invalidLine)); } private static class StubLineTokenizer implements LineTokenizer { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CustomerUpdateProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CustomerUpdateProcessorTests.java index 93178702c..800356b35 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CustomerUpdateProcessorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/CustomerUpdateProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 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,8 +15,8 @@ */ package org.springframework.batch.sample.domain.trade; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.springframework.batch.sample.domain.trade.CustomerOperation.ADD; @@ -25,14 +25,14 @@ import static org.springframework.batch.sample.domain.trade.CustomerOperation.UP import java.math.BigDecimal; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Lucas Ward * */ -public class CustomerUpdateProcessorTests { +class CustomerUpdateProcessorTests { private CustomerDao customerDao; @@ -40,8 +40,8 @@ public class CustomerUpdateProcessorTests { private CustomerUpdateProcessor processor; - @Before - public void init() { + @BeforeEach + void init() { customerDao = mock(CustomerDao.class); logger = mock(InvalidCustomerLogger.class); processor = new CustomerUpdateProcessor(); @@ -50,40 +50,40 @@ public class CustomerUpdateProcessorTests { } @Test - public void testSuccessfulAdd() throws Exception { + void testSuccessfulAdd() throws Exception { CustomerUpdate customerUpdate = new CustomerUpdate(ADD, "test customer", new BigDecimal("232.2")); when(customerDao.getCustomerByName("test customer")).thenReturn(null); assertEquals(customerUpdate, processor.process(customerUpdate)); } @Test - public void testInvalidAdd() throws Exception { + void testInvalidAdd() throws Exception { CustomerUpdate customerUpdate = new CustomerUpdate(ADD, "test customer", new BigDecimal("232.2")); when(customerDao.getCustomerByName("test customer")).thenReturn(new CustomerCredit()); logger.log(customerUpdate); - assertNull("Processor should return null", processor.process(customerUpdate)); + assertNull(processor.process(customerUpdate), "Processor should return null"); } @Test - public void testDelete() throws Exception { + void testDelete() throws Exception { CustomerUpdate customerUpdate = new CustomerUpdate(DELETE, "test customer", new BigDecimal("232.2")); logger.log(customerUpdate); - assertNull("Processor should return null", processor.process(customerUpdate)); + assertNull(processor.process(customerUpdate), "Processor should return null"); } @Test - public void testSuccessfulUpdate() throws Exception { + void testSuccessfulUpdate() throws Exception { CustomerUpdate customerUpdate = new CustomerUpdate(UPDATE, "test customer", new BigDecimal("232.2")); when(customerDao.getCustomerByName("test customer")).thenReturn(new CustomerCredit()); assertEquals(customerUpdate, processor.process(customerUpdate)); } @Test - public void testInvalidUpdate() throws Exception { + void testInvalidUpdate() throws Exception { CustomerUpdate customerUpdate = new CustomerUpdate(UPDATE, "test customer", new BigDecimal("232.2")); when(customerDao.getCustomerByName("test customer")).thenReturn(null); logger.log(customerUpdate); - assertNull("Processor should return null", processor.process(customerUpdate)); + assertNull(processor.process(customerUpdate), "Processor should return null"); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/TradeTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/TradeTests.java index e71230f4a..c78cb0770 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/TradeTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/TradeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 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. @@ -17,21 +17,21 @@ package org.springframework.batch.sample.domain.trade; import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class TradeTests { +class TradeTests { @Test - public void testEquality() { + void testEquality() { Trade trade1 = new Trade("isin", 1, new BigDecimal("1.1"), "customer1"); Trade trade1Clone = new Trade("isin", 1, new BigDecimal("1.1"), "customer1"); Trade trade2 = new Trade("isin", 1, new BigDecimal("2.3"), "customer2"); assertEquals(trade1, trade1Clone); - assertFalse(trade1.equals(trade2)); + assertNotEquals(trade1, trade2); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java index 08fee4f57..ecc03ae49 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditIncreaseProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 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,11 +15,11 @@ */ package org.springframework.batch.sample.domain.trade.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.CustomerCredit; /** @@ -27,15 +27,15 @@ import org.springframework.batch.sample.domain.trade.CustomerCredit; * * @author Robert Kasanicky */ -public class CustomerCreditIncreaseProcessorTests { +class CustomerCreditIncreaseProcessorTests { - private CustomerCreditIncreaseProcessor tested = new CustomerCreditIncreaseProcessor(); + private final CustomerCreditIncreaseProcessor tested = new CustomerCreditIncreaseProcessor(); /* * Increases customer's credit by fixed value */ @Test - public void testProcess() throws Exception { + void testProcess() throws Exception { final BigDecimal oldCredit = new BigDecimal("10.54"); CustomerCredit customerCredit = new CustomerCredit(); customerCredit.setCredit(oldCredit); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditRowMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditRowMapperTests.java index f8271ab7f..9cb00ec5d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditRowMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditRowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.sample.support.AbstractRowMapperTests; import org.springframework.jdbc.core.RowMapper; -public class CustomerCreditRowMapperTests extends AbstractRowMapperTests { +class CustomerCreditRowMapperTests extends AbstractRowMapperTests { private static final int ID = 12; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.java index 34cfd43a7..a8193517b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdatePreparedStatementSetterTests.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. @@ -21,24 +21,24 @@ import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.CustomerCredit; /** * @author Dave Syer * */ -public class CustomerCreditUpdatePreparedStatementSetterTests { +class CustomerCreditUpdatePreparedStatementSetterTests { - private CustomerCreditUpdatePreparedStatementSetter setter = new CustomerCreditUpdatePreparedStatementSetter(); + private final CustomerCreditUpdatePreparedStatementSetter setter = new CustomerCreditUpdatePreparedStatementSetter(); private CustomerCredit credit; private PreparedStatement ps; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { ps = mock(PreparedStatement.class); credit = new CustomerCredit(); credit.setId(13); @@ -46,13 +46,8 @@ public class CustomerCreditUpdatePreparedStatementSetterTests { credit.setName("foo"); } - /* - * Test method for {@link org.springframework.batch.sample.domain.trade.internal. - * CustomerCreditUpdatePreparedStatementSetter#setValues(CustomerCredit, - * PreparedStatement) } - */ @Test - public void testSetValues() throws SQLException { + void testSetValues() throws SQLException { ps.setBigDecimal(1, credit.getCredit().add(CustomerCreditUpdatePreparedStatementSetter.FIXED_AMOUNT)); ps.setLong(2, credit.getId()); setter.setValues(credit, ps); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdateProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdateProcessorTests.java index 5a8b1522f..87b0b0051 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdateProcessorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerCreditUpdateProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,12 +20,12 @@ import static org.mockito.Mockito.mock; import java.math.BigDecimal; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.sample.domain.trade.CustomerCreditDao; -public class CustomerCreditUpdateProcessorTests { +class CustomerCreditUpdateProcessorTests { private CustomerCreditDao dao; @@ -33,8 +33,8 @@ public class CustomerCreditUpdateProcessorTests { private static final double CREDIT_FILTER = 355.0; - @Before - public void setUp() { + @BeforeEach + void setUp() { dao = mock(CustomerCreditDao.class); writer = new CustomerCreditUpdateWriter(); @@ -43,7 +43,7 @@ public class CustomerCreditUpdateProcessorTests { } @Test - public void testProcess() throws Exception { + void testProcess() throws Exception { CustomerCredit credit = new CustomerCredit(); credit.setCredit(new BigDecimal(CREDIT_FILTER)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerUpdateProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerUpdateProcessorTests.java index 70a650567..9496a6e39 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerUpdateProcessorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/CustomerUpdateProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +15,20 @@ */ package org.springframework.batch.sample.domain.trade.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.CustomerDebit; import org.springframework.batch.sample.domain.trade.CustomerDebitDao; import org.springframework.batch.sample.domain.trade.Trade; -public class CustomerUpdateProcessorTests { +class CustomerUpdateProcessorTests { @Test - public void testProcess() { + void testProcess() { Trade trade = new Trade(); trade.setCustomer("testCustomerName"); trade.setPrice(new BigDecimal("123.0")); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/FlatFileCustomerCreditDaoTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/FlatFileCustomerCreditDaoTests.java index 4b19ed603..1de1d2545 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/FlatFileCustomerCreditDaoTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/FlatFileCustomerCreditDaoTests.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. @@ -20,21 +20,21 @@ import static org.mockito.Mockito.mock; import java.math.BigDecimal; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.sample.domain.trade.CustomerCredit; -public class FlatFileCustomerCreditDaoTests { +class FlatFileCustomerCreditDaoTests { private ResourceLifecycleItemWriter output; private FlatFileCustomerCreditDao writer; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { output = mock(ResourceLifecycleItemWriter.class); writer = new FlatFileCustomerCreditDao(); @@ -42,7 +42,7 @@ public class FlatFileCustomerCreditDaoTests { } @Test - public void testOpen() throws Exception { + void testOpen() throws Exception { ExecutionContext executionContext = new ExecutionContext(); output.open(executionContext); @@ -51,14 +51,14 @@ public class FlatFileCustomerCreditDaoTests { } @Test - public void testClose() throws Exception { + void testClose() throws Exception { output.close(); writer.close(); } @Test - public void testWrite() throws Exception { + void testWrite() throws Exception { CustomerCredit credit = new CustomerCredit(); credit.setCredit(new BigDecimal(1)); credit.setName("testName"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/GeneratingItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/GeneratingItemReaderTests.java index 201951728..fec0f83b7 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/GeneratingItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/GeneratingItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,10 @@ */ package org.springframework.batch.sample.domain.trade.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link GeneratingTradeItemReader}. @@ -26,7 +27,7 @@ import org.junit.Test; */ public class GeneratingItemReaderTests { - private GeneratingTradeItemReader reader = new GeneratingTradeItemReader(); + private final GeneratingTradeItemReader reader = new GeneratingTradeItemReader(); /* * Generates a given number of not-null records, consecutive calls return null. @@ -41,7 +42,7 @@ public class GeneratingItemReaderTests { counter++; } - assertEquals(null, reader.read()); + assertNull(reader.read()); assertEquals(limit, counter); assertEquals(counter, reader.getCounter()); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java index 071fd1de8..49b796223 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.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. @@ -15,7 +15,7 @@ */ package org.springframework.batch.sample.domain.trade.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; import java.sql.ResultSet; @@ -23,20 +23,17 @@ import java.sql.SQLException; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.CustomerDebit; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.annotation.Transactional; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration() -public class JdbcCustomerDebitDaoTests { +@SpringJUnitConfig +class JdbcCustomerDebitDaoTests { private JdbcOperations jdbcTemplate; @@ -50,7 +47,7 @@ public class JdbcCustomerDebitDaoTests { @Test @Transactional - public void testWrite() { + void testWrite() { jdbcTemplate.execute("INSERT INTO CUSTOMER VALUES (99, 0, 'testName', 100)"); CustomerDebit customerDebit = new CustomerDebit(); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java index b08ce167d..c03736cc8 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.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. @@ -15,7 +15,7 @@ */ package org.springframework.batch.sample.domain.trade.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; import java.sql.ResultSet; @@ -23,8 +23,7 @@ import java.sql.SQLException; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; @@ -33,13 +32,11 @@ import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.annotation.Transactional; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/data-source-context.xml" }) -public class JdbcTradeWriterTests implements InitializingBean { +@SpringJUnitConfig(locations = { "/data-source-context.xml" }) +class JdbcTradeWriterTests implements InitializingBean { private JdbcOperations jdbcTemplate; @@ -62,7 +59,7 @@ public class JdbcTradeWriterTests implements InitializingBean { @Test @Transactional - public void testWrite() { + void testWrite() { Trade trade = new Trade(); trade.setCustomer("testCustomer"); trade.setIsin("5647238492"); @@ -82,7 +79,7 @@ public class JdbcTradeWriterTests implements InitializingBean { } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { this.writer.setIncrementer(incrementer); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeFieldSetMapperTests.java index 76f7b4e93..472a87068 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.sample.support.AbstractFieldSetMapperTests; -public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests { +class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests { private static final String CUSTOMER = "Mike Tomcat"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeProcessorTests.java index 793eced79..9e80746b6 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeProcessorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 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. @@ -19,19 +19,19 @@ import static org.mockito.Mockito.mock; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.sample.domain.trade.TradeDao; -public class TradeProcessorTests { +class TradeProcessorTests { private TradeDao writer; private TradeWriter processor; - @Before - public void setUp() { + @BeforeEach + void setUp() { writer = mock(TradeDao.class); processor = new TradeWriter(); @@ -39,7 +39,7 @@ public class TradeProcessorTests { } @Test - public void testProcess() { + void testProcess() { Trade trade = new Trade(); writer.writeTrade(trade); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeRowMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeRowMapperTests.java index 194c44dd0..c7ae9fd96 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeRowMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/TradeRowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.sample.support.AbstractRowMapperTests; import org.springframework.jdbc.core.RowMapper; -public class TradeRowMapperTests extends AbstractRowMapperTests { +class TradeRowMapperTests extends AbstractRowMapperTests { private static final String ISIN = "jsgk342"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/AbstractIoSampleTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/AbstractIoSampleTests.java index 9dec7260f..684c85a56 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/AbstractIoSampleTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/AbstractIoSampleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2020 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,13 +15,13 @@ */ package org.springframework.batch.sample.iosample; -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.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; @@ -36,7 +36,7 @@ import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.batch.test.MetaDataInstanceFactory; import org.springframework.batch.test.StepScopeTestExecutionListener; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; @@ -47,10 +47,10 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution * * @author Robert Kasanicky */ -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/job-runner-context.xml", "/jobs/ioSampleJob.xml" }) @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class }) -public abstract class AbstractIoSampleTests { +abstract class AbstractIoSampleTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -62,7 +62,7 @@ public abstract class AbstractIoSampleTests { * Check the resulting credits correspond to inputs increased by fixed amount. */ @Test - public void testUpdateCredit() throws Exception { + void testUpdateCredit() throws Exception { open(reader); List inputs = getCredits(reader); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/DelimitedFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/DelimitedFunctionalTests.java index ec2a529d4..96d2be099 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/DelimitedFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/DelimitedFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 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,24 +16,21 @@ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.scope.context.StepSynchronizationManager; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.test.MetaDataInstanceFactory; -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 Dave Syer * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/delimited.xml") -public class DelimitedFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/delimited.xml") +class DelimitedFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/FixedLengthFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/FixedLengthFunctionalTests.java index 9e61821c4..d2280387d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/FixedLengthFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/FixedLengthFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,16 @@ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.scope.context.StepSynchronizationManager; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.test.MetaDataInstanceFactory; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/fixedLength.xml") -public class FixedLengthFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/fixedLength.xml") +class FixedLengthFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/HibernateFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/HibernateFunctionalTests.java index cc065d651..45f8047d7 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/HibernateFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/HibernateFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,12 @@ */ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/hibernate-context.xml", "/jobs/iosample/hibernate.xml" }) -public class HibernateFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = { "/hibernate-context.xml", "/jobs/iosample/hibernate.xml" }) +class HibernateFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcCursorFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcCursorFunctionalTests.java index 72b3d9766..e39e75898 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcCursorFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcCursorFunctionalTests.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,19 +16,16 @@ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dan Garrette * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/jdbcCursor.xml") -public class JdbcCursorFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/jdbcCursor.xml") +class JdbcCursorFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcPagingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcPagingFunctionalTests.java index 68114c3b1..a6b85ea1e 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcPagingFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JdbcPagingFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 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,24 +16,21 @@ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.scope.context.StepSynchronizationManager; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.test.MetaDataInstanceFactory; -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 Dave Syer * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/jdbcPaging.xml") -public class JdbcPagingFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/jdbcPaging.xml") +class JdbcPagingFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JpaFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JpaFunctionalTests.java index f5168d6e6..053349dec 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JpaFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JpaFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,12 @@ */ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/jpa.xml") -public class JpaFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/jpa.xml") +class JpaFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiLineFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiLineFunctionalTests.java index 4406443d8..2dece7f64 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiLineFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiLineFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,23 +16,20 @@ package org.springframework.batch.sample.iosample; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.AssertFile; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.FileSystemResource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dan Garrette * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/iosample/multiLine.xml", "/job-runner-context.xml" }) -public class MultiLineFunctionalTests { +class MultiLineFunctionalTests { private static final String OUTPUT_FILE = "target/test-outputs/multiLineOutput.txt"; @@ -45,7 +42,7 @@ public class MultiLineFunctionalTests { * Output should be the same as input */ @Test - public void testJob() throws Exception { + void testJob() throws Exception { jobLauncherTestUtils.launchJob(); AssertFile.assertFileEquals(new FileSystemResource(INPUT_FILE), new FileSystemResource(OUTPUT_FILE)); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiRecordTypeFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiRecordTypeFunctionalTests.java index 3e2ae63a0..4086c9134 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiRecordTypeFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiRecordTypeFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,23 +16,20 @@ package org.springframework.batch.sample.iosample; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.test.AssertFile; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.FileSystemResource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dan Garrette * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/iosample/multiRecordType.xml", +@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/iosample/multiRecordType.xml", "/job-runner-context.xml" }) -public class MultiRecordTypeFunctionalTests { +class MultiRecordTypeFunctionalTests { private static final String OUTPUT_FILE = "target/test-outputs/multiRecordTypeOutput.txt"; @@ -45,7 +42,7 @@ public class MultiRecordTypeFunctionalTests { * Output should be the same as input */ @Test - public void testJob() throws Exception { + void testJob() throws Exception { jobLauncherTestUtils.launchJob(); AssertFile.assertFileEquals(new FileSystemResource(INPUT_FILE), new FileSystemResource(OUTPUT_FILE)); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiResourceFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiResourceFunctionalTests.java index 22af2be6a..7a962d88e 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiResourceFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/MultiResourceFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.StepExecution; @@ -24,16 +23,14 @@ import org.springframework.batch.core.scope.context.StepSynchronizationManager; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.test.MetaDataInstanceFactory; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dan Garrette * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/multiResource.xml") -public class MultiResourceFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/multiResource.xml") +class MultiResourceFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/RepositoryFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/RepositoryFunctionalTests.java index a8e086aa3..63bc43d2f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/RepositoryFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/RepositoryFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 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,19 +15,16 @@ */ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.scope.context.StepSynchronizationManager; import org.springframework.batch.item.ItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.test.MetaDataInstanceFactory; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/repository.xml") -public class RepositoryFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/repository.xml") +class RepositoryFunctionalTests extends AbstractIoSampleTests { @Override protected void pointReaderToOutput(ItemReader reader) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesDelimitedFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesDelimitedFunctionalTests.java index 5eeab39c9..bfecd2c11 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesDelimitedFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesDelimitedFunctionalTests.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,13 +16,12 @@ package org.springframework.batch.sample.iosample; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Date; import java.util.concurrent.Callable; -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; @@ -38,17 +37,15 @@ import org.springframework.batch.test.MetaDataInstanceFactory; import org.springframework.batch.test.StepScopeTestUtils; 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 * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml", "/jobs/iosample/delimited.xml" }) -public class TwoJobInstancesDelimitedFunctionalTests { +class TwoJobInstancesDelimitedFunctionalTests { @Autowired private JobLauncher launcher; @@ -64,7 +61,7 @@ public class TwoJobInstancesDelimitedFunctionalTests { private ItemStream readerStream; @Test - public void testLaunchJobTwice() throws Exception { + void testLaunchJobTwice() throws Exception { JobExecution jobExecution = launcher.run(this.job, getJobParameters("data/iosample/input/delimited.csv")); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); verifyOutput(6); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java index 379f980d3..4ec51bf10 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.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,15 +16,14 @@ package org.springframework.batch.sample.iosample; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.Date; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; @@ -33,8 +32,7 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; /** @@ -42,10 +40,9 @@ import org.springframework.test.jdbc.JdbcTestUtils; * @author Mahmoud Ben Hassine * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml", "/jobs/iosample/jdbcPaging.xml" }) -public class TwoJobInstancesPagingFunctionalTests { +class TwoJobInstancesPagingFunctionalTests { @Autowired private JobLauncher launcher; @@ -61,13 +58,13 @@ public class TwoJobInstancesPagingFunctionalTests { } @Test - public void testLaunchJobTwice() throws Exception { + void testLaunchJobTwice() throws Exception { int first = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "CUSTOMER", "credit>1000"); JobExecution jobExecution = launcher.run(this.job, getJobParameters(1000.)); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals(first, jobExecution.getStepExecutions().iterator().next().getWriteCount()); int second = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "CUSTOMER", "credit>1000000"); - assertNotSame("The number of records above the threshold did not change", first, second); + assertNotSame(first, second, "The number of records above the threshold did not change"); jobExecution = launcher.run(this.job, getJobParameters(1000000.)); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals(second, jobExecution.getStepExecutions().iterator().next().getWriteCount()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/XmlFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/XmlFunctionalTests.java index 8baa49eed..75432923b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/XmlFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/XmlFunctionalTests.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,22 +16,19 @@ package org.springframework.batch.sample.iosample; -import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.xml.StaxEventItemReader; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dan Garrette * @since 2.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/jobs/iosample/xml.xml") -public class XmlFunctionalTests extends AbstractIoSampleTests { +@SpringJUnitConfig(locations = "/jobs/iosample/xml.xml") +class XmlFunctionalTests extends AbstractIoSampleTests { @Autowired private Resource outputResource; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/jmx/JobExecutionNotificationPublisherTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/jmx/JobExecutionNotificationPublisherTests.java index 654d3e517..9781f3ba1 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/jmx/JobExecutionNotificationPublisherTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/jmx/JobExecutionNotificationPublisherTests.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. @@ -15,15 +15,15 @@ */ package org.springframework.batch.sample.jmx; -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 javax.management.Notification; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jmx.export.notification.NotificationPublisher; import org.springframework.jmx.export.notification.UnableToSendNotificationException; @@ -32,12 +32,12 @@ import org.springframework.jmx.export.notification.UnableToSendNotificationExcep * @author Thomas Risberg * */ -public class JobExecutionNotificationPublisherTests { +class JobExecutionNotificationPublisherTests { - JobExecutionNotificationPublisher publisher = new JobExecutionNotificationPublisher(); + private final JobExecutionNotificationPublisher publisher = new JobExecutionNotificationPublisher(); @Test - public void testRepeatOperationsOpenUsed() throws Exception { + void testRepeatOperationsOpenUsed() { final List list = new ArrayList<>(); publisher.setNotificationPublisher(new NotificationPublisher() { @@ -50,7 +50,7 @@ public class JobExecutionNotificationPublisherTests { publisher.onApplicationEvent(new SimpleMessageApplicationEvent(this, "foo")); assertEquals(1, list.size()); String message = list.get(0).getMessage(); - assertTrue("Message does not contain 'foo': ", message.indexOf("foo") > 0); + assertTrue(message.contains("foo"), "Message does not contain 'foo': "); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java index 43d98a1fb..42716d285 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.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. @@ -15,10 +15,11 @@ */ package org.springframework.batch.sample.launch; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -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.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Date; @@ -28,9 +29,9 @@ import javax.management.MalformedObjectNameException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.launch.support.JobRegistryBackgroundJobRunner; import org.springframework.jmx.MBeanServerNotFoundException; @@ -42,19 +43,18 @@ import org.springframework.jmx.support.MBeanServerConnectionFactoryBean; * @author Dave Syer * */ -public class RemoteLauncherTests { +class RemoteLauncherTests { - private static Log logger = LogFactory.getLog(RemoteLauncherTests.class); + private static final Log logger = LogFactory.getLog(RemoteLauncherTests.class); - private static List errors = new ArrayList<>(); + private static final List errors = new ArrayList<>(); private static JobOperator launcher; private static JobLoader loader; - static private Thread thread; @Test - public void testConnect() throws Exception { + void testConnect() throws Exception { String message = errors.isEmpty() ? "" : errors.get(0).getMessage(); if (!errors.isEmpty()) { @@ -65,29 +65,25 @@ public class RemoteLauncherTests { } @Test - public void testLaunchBadJob() throws Exception { + void testLaunchBadJob() throws Exception { assertEquals(0, errors.size()); assertTrue(isConnected()); - try { - launcher.start("foo", "time=" + (new Date().getTime())); - fail("Expected RuntimeException"); - } - catch (RuntimeException e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.contains("NoSuchJobException")); - } + Exception exception = assertThrows(RuntimeException.class, + () -> launcher.start("foo", "time=" + (new Date().getTime()))); + String message = exception.getMessage(); + assertTrue(message.contains("NoSuchJobException"), "Wrong message: " + message); } @Test - public void testAvailableJobs() throws Exception { + void testAvailableJobs() throws Exception { assertEquals(0, errors.size()); assertTrue(isConnected()); assertTrue(launcher.getJobNames().contains("loopJob")); } @Test - public void testPauseJob() throws Exception { + void testPauseJob() throws Exception { final int SLEEP_INTERVAL = 600; assertTrue(isConnected()); @@ -105,7 +101,7 @@ public class RemoteLauncherTests { logger.debug(launcher.getSummary(executionId)); long resumedId = launcher.restart(executionId); - assertNotSame("Picked up the same execution after pause and resume", executionId, resumedId); + assertNotSame(executionId, resumedId, "Picked up the same execution after pause and resume"); Thread.sleep(SLEEP_INTERVAL); launcher.stop(resumedId); @@ -113,22 +109,17 @@ public class RemoteLauncherTests { logger.debug(launcher.getSummary(resumedId)); long resumeId2 = launcher.restart(resumedId); - assertNotSame("Picked up the same execution after pause and resume", executionId, resumeId2); + assertNotSame(executionId, resumeId2, "Picked up the same execution after pause and resume"); Thread.sleep(SLEEP_INTERVAL); launcher.stop(resumeId2); } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { System.setProperty("com.sun.management.jmxremote", ""); - thread = new Thread(new Runnable() { + Thread thread = new Thread(new Runnable() { @Override public void run() { try { @@ -149,8 +140,8 @@ public class RemoteLauncherTests { } } - @AfterClass - public static void cleanUp() { + @AfterAll + static void cleanUp() { JobRegistryBackgroundJobRunner.stop(); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/quartz/JobLauncherDetailsTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/quartz/JobLauncherDetailsTests.java index 154dbd5a5..fdba326d3 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/quartz/JobLauncherDetailsTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/quartz/JobLauncherDetailsTests.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. @@ -16,15 +16,15 @@ package org.springframework.batch.sample.quartz; import static org.mockito.Mockito.mock; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.quartz.Job; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; @@ -48,16 +48,16 @@ import org.springframework.lang.Nullable; * @author Dave Syer * */ -public class JobLauncherDetailsTests { +class JobLauncherDetailsTests { - private JobLauncherDetails details = new JobLauncherDetails(); + private final JobLauncherDetails details = new JobLauncherDetails(); private TriggerFiredBundle firedBundle; - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { details.setJobLauncher(new JobLauncher() { @Override public JobExecution run(org.springframework.batch.core.Job job, JobParameters jobParameters) @@ -82,12 +82,8 @@ public class JobLauncherDetailsTests { return new StubJobExecutionContext(); } - /** - * Test method for - * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. - */ @Test - public void testExecuteWithNoJobParameters() { + void testExecuteWithNoJobParameters() { JobDetail jobDetail = new JobDetailImpl(); JobExecutionContext context = createContext(jobDetail); details.executeInternal(context); @@ -96,12 +92,8 @@ public class JobLauncherDetailsTests { assertEquals(0, parameters.getParameters().size()); } - /** - * Test method for - * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. - */ @Test - public void testExecuteWithJobName() { + void testExecuteWithJobName() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO"); JobExecutionContext context = createContext(jobDetail); @@ -110,12 +102,8 @@ public class JobLauncherDetailsTests { assertEquals("FOO", list.get(0)); } - /** - * Test method for - * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. - */ @Test - public void testExecuteWithSomeJobParameters() { + void testExecuteWithSomeJobParameters() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put("foo", "bar"); JobExecutionContext context = createContext(jobDetail); @@ -125,12 +113,8 @@ public class JobLauncherDetailsTests { assertEquals(1, parameters.getParameters().size()); } - /** - * Test method for - * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. - */ @Test - public void testExecuteWithJobNameAndParameters() { + void testExecuteWithJobNameAndParameters() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO"); jobDetail.getJobDataMap().put("foo", "bar"); @@ -142,12 +126,8 @@ public class JobLauncherDetailsTests { assertEquals(1, parameters.getParameters().size()); } - /** - * Test method for - * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. - */ @Test - public void testExecuteWithJobNameAndComplexParameters() { + void testExecuteWithJobNameAndComplexParameters() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO"); jobDetail.getJobDataMap().put("foo", this); @@ -160,7 +140,6 @@ public class JobLauncherDetailsTests { assertEquals(0, parameters.getParameters().size()); } - @SuppressWarnings("serial") private final class StubJobExecutionContext extends JobExecutionContextImpl { private StubJobExecutionContext() { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java index d0f1c4ba1..661f8d129 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 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,12 +15,12 @@ */ package org.springframework.batch.sample.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.transform.FieldSet; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Encapsulates basic logic for testing custom {@link FieldSetMapper} implementations. @@ -51,7 +51,7 @@ public abstract class AbstractFieldSetMapperTests { * equals(Object other) */ @Test - public void testRegularUse() throws Exception { + void testRegularUse() throws Exception { assertEquals(expectedDomainObject(), fieldSetMapper().mapFieldSet(fieldSet())); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractRowMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractRowMapperTests.java index c918a4537..3f74c5034 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractRowMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractRowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package org.springframework.batch.sample.support; import static org.mockito.Mockito.mock; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.ResultSet; import java.sql.SQLException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jdbc.core.RowMapper; /** @@ -36,7 +36,7 @@ public abstract class AbstractRowMapperTests { private static final int IGNORED_ROW_NUMBER = 0; // mock result set - private ResultSet rs = mock(ResultSet.class); + private final ResultSet rs = mock(ResultSet.class); /** * @return Expected result of mapping the mock ResultSet by the mapper @@ -58,7 +58,7 @@ public abstract class AbstractRowMapperTests { * Regular usage scenario. */ @Test - public void testRegularUse() throws SQLException { + void testRegularUse() throws SQLException { setUpResultSetMock(rs); assertEquals(expectedDomainObject(), rowMapper().mapRow(rs, IGNORED_ROW_NUMBER)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.java index 86609391a..3fec20d2a 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.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,13 +15,13 @@ */ package org.springframework.batch.sample.support; -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 java.io.IOException; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter; @@ -29,17 +29,12 @@ import org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeI * @author Dave Syer * */ -public class ItemTrackingItemWriterTests { +class ItemTrackingItemWriterTests { - private ItemTrackingTradeItemWriter writer = new ItemTrackingTradeItemWriter(); + private final ItemTrackingTradeItemWriter writer = new ItemTrackingTradeItemWriter(); - /** - * Test method for - * {@link org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter#write(java.util.List)}. - * @throws Exception - */ @Test - public void testWrite() throws Exception { + void testWrite() throws Exception { assertEquals(0, writer.getItems().size()); Trade a = new Trade("a", 0, null, null); Trade b = new Trade("b", 0, null, null); @@ -49,19 +44,12 @@ public class ItemTrackingItemWriterTests { } @Test - public void testWriteFailure() throws Exception { + void testWriteFailure() throws Exception { writer.setWriteFailureISIN("c"); - try { - Trade a = new Trade("a", 0, null, null); - Trade b = new Trade("b", 0, null, null); - Trade c = new Trade("c", 0, null, null); - writer.write(Arrays.asList(a, b, c)); - fail("Expected Write Failure Exception"); - } - catch (IOException e) { - // expected - } - // the failed item is removed + Trade a = new Trade("a", 0, null, null); + Trade b = new Trade("b", 0, null, null); + Trade c = new Trade("c", 0, null, null); + assertThrows(IOException.class, () -> writer.write(Arrays.asList(a, b, c))); assertEquals(0, writer.getItems().size()); Trade e = new Trade("e", 0, null, null); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/RetrySampleItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/RetrySampleItemWriterTests.java index dce1d27d3..539ae4b62 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/RetrySampleItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/RetrySampleItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 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,38 +15,32 @@ */ package org.springframework.batch.sample.support; -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 java.util.Arrays; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link RetrySampleItemWriter}. * * @author Robert Kasanicky */ -public class RetrySampleItemWriterTests { +class RetrySampleItemWriterTests { - private RetrySampleItemWriter processor = new RetrySampleItemWriter<>(); + private final RetrySampleItemWriter processor = new RetrySampleItemWriter<>(); /* * Processing throws exception on 2nd and 3rd call. */ @Test - public void testProcess() throws Exception { + void testProcess() throws Exception { Object item = null; processor.write(Collections.singletonList(item)); - try { - processor.write(Arrays.asList(item, item, item)); - fail(); - } - catch (RuntimeException e) { - // expected - } + assertThrows(RuntimeException.class, () -> processor.write(Arrays.asList(item, item, item))); processor.write(Collections.singletonList(item)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/validation/ValidationSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/validation/ValidationSampleFunctionalTests.java index d2603f846..94acad2c9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/validation/ValidationSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/validation/ValidationSampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,7 @@ package org.springframework.batch.sample.validation; import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; @@ -30,15 +28,15 @@ import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.item.support.ListItemWriter; import org.springframework.batch.sample.validation.domain.Person; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Mahmoud Ben Hassine */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = { ValidationSampleConfiguration.class }) -public class ValidationSampleFunctionalTests { +@SpringJUnitConfig(classes = { ValidationSampleConfiguration.class }) +class ValidationSampleFunctionalTests { @Autowired private Job job; @@ -50,7 +48,7 @@ public class ValidationSampleFunctionalTests { private ListItemWriter listItemWriter; @Test - public void testItemValidation() throws Exception { + void testItemValidation() throws Exception { // given JobParameters jobParameters = new JobParameters(); @@ -58,10 +56,10 @@ public class ValidationSampleFunctionalTests { JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters); // then - Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); + assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); List writtenItems = this.listItemWriter.getWrittenItems(); - Assert.assertEquals(1, writtenItems.size()); - Assert.assertEquals("foo", writtenItems.get(0).getName()); + assertEquals(1, writtenItems.size()); + assertEquals("foo", writtenItems.get(0).getName()); } }