diff --git a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemReaderAutoConfigurationTests.java b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemReaderAutoConfigurationTests.java index 4d37bf62..00bfe4f3 100644 --- a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemReaderAutoConfigurationTests.java +++ b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemReaderAutoConfigurationTests.java @@ -21,7 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; diff --git a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemWriterAutoConfigurationTests.java b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemWriterAutoConfigurationTests.java index 11e4b427..780152d0 100644 --- a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemWriterAutoConfigurationTests.java +++ b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemWriterAutoConfigurationTests.java @@ -23,9 +23,9 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; @@ -62,12 +62,12 @@ public class FlatFileItemWriterAutoConfigurationTests { private File outputFile; - @Before + @BeforeEach public void setUp() throws Exception { this.outputFile = File.createTempFile("flatfile-config-test-output", ".tmp"); } - @After + @AfterEach public void tearDown() { this.outputFile.delete(); } diff --git a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/RangeConverterTests.java b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/RangeConverterTests.java index ee2692ac..be1ad0a2 100644 --- a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/RangeConverterTests.java +++ b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/RangeConverterTests.java @@ -16,11 +16,12 @@ package org.springframework.cloud.task.batch.autoconfigure; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.Range; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Michael Minella @@ -54,18 +55,22 @@ public class RangeConverterTests { assertThat(range.getMax()).isEqualTo(25); } - @Test(expected = NumberFormatException.class) + @Test public void testIllegalValue() { RangeConverter converter = new RangeConverter(); - converter.convert("invalid"); + assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> { + converter.convert("invalid"); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testTooManyValues() { RangeConverter converter = new RangeConverter(); - converter.convert("1-2-3-4"); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + converter.convert("1-2-3-4"); + }); } } diff --git a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java index 8c844c30..ad7de221 100644 --- a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java +++ b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; diff --git a/spring-cloud-task-batch/pom.xml b/spring-cloud-task-batch/pom.xml index 85f817b0..de4fdd3c 100644 --- a/spring-cloud-task-batch/pom.xml +++ b/spring-cloud-task-batch/pom.xml @@ -55,16 +55,6 @@ org.springframework.boot spring-boot-test - - junit - junit - test - - - org.mockito - mockito-core - test - com.h2database h2 @@ -91,5 +81,15 @@ spring-boot-autoconfigure-processor true + + org.mockito + mockito-junit-jupiter + test + + + org.junit.jupiter + junit-jupiter + test + diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java index 03ae94c5..f95f561f 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.task.batch.configuration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration; import org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner; diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java index 6a35db2d..980ce3fa 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java @@ -16,10 +16,10 @@ package org.springframework.cloud.task.batch.handler; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.function.Executable; -import org.junit.runner.RunWith; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; @@ -49,7 +49,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; @@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Glenn Renfro */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration( classes = { TaskJobLauncherCommandLineRunnerCoreTests.BatchConfiguration.class }) public class TaskJobLauncherCommandLineRunnerCoreTests { @@ -85,7 +85,7 @@ public class TaskJobLauncherCommandLineRunnerCoreTests { private Step step; - @Before + @BeforeEach public void init() { this.jobs = new JobBuilderFactory(this.jobRepository); this.steps = new StepBuilderFactory(this.jobRepository, this.transactionManager); diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java index 853b7490..e8f215ac 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java @@ -21,8 +21,8 @@ import java.util.Set; import javax.sql.DataSource; import org.assertj.core.api.Condition; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; import org.springframework.batch.core.Job; @@ -74,7 +74,7 @@ public class TaskJobLauncherCommandLineRunnerTests { private ConfigurableApplicationContext applicationContext; - @After + @AfterEach public void tearDown() { if (this.applicationContext != null && this.applicationContext.isActive()) { this.applicationContext.close(); diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java index bab570aa..9b2eaafc 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java @@ -20,8 +20,8 @@ import java.util.Set; import javax.sql.DataSource; -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.Job; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; @@ -48,7 +48,7 @@ public class PrefixTests { private ConfigurableApplicationContext applicationContext; - @After + @AfterEach public void tearDown() { if (this.applicationContext != null && this.applicationContext.isActive()) { this.applicationContext.close(); diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java index 897567b5..3ac59886 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java @@ -24,8 +24,8 @@ import java.util.Set; import javax.sql.DataSource; -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.Job; import org.springframework.batch.core.StepContribution; @@ -63,6 +63,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Michael Minella @@ -74,7 +75,7 @@ public class TaskBatchExecutionListenerTests { private ConfigurableApplicationContext applicationContext; - @After + @AfterEach public void tearDown() { if (this.applicationContext != null && this.applicationContext.isActive()) { this.applicationContext.close(); @@ -87,25 +88,31 @@ public class TaskBatchExecutionListenerTests { validateContext(); } - @Test(expected = AssertionError.class) + @Test public void testNoAutoConfigurationEnabled() { this.applicationContext = SpringApplication.run(JobConfiguration.class, "--spring.cloud.task.batch.listener.enabled=false"); - validateContext(); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> { + validateContext(); + }); } - @Test(expected = AssertionError.class) + @Test public void testNoAutoConfigurationEnable() { this.applicationContext = SpringApplication.run(JobConfiguration.class, "--spring.cloud.task.batch.listener.enable=false"); - validateContext(); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> { + validateContext(); + }); } - @Test(expected = AssertionError.class) + @Test public void testNoAutoConfigurationBothDisabled() { this.applicationContext = SpringApplication.run(JobConfiguration.class, "--spring.cloud.task.batch.listener.enable=false --spring.cloud.task.batch.listener.enabled=false"); - validateContext(); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> { + validateContext(); + }); } @Test @@ -245,9 +252,11 @@ public class TaskBatchExecutionListenerTests { assertThat(bean).isEqualTo(testObject); } - @Test(expected = IllegalArgumentException.class) + @Test public void testBatchExecutionListenerBeanPostProcessorNullJobNames() { - beanPostProcessor(null); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + beanPostProcessor(null); + }); } private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor( diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java index a0716696..31566174 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java @@ -29,11 +29,12 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeoutException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.batch.core.BatchStatus; @@ -52,6 +53,7 @@ import org.springframework.core.io.Resource; import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -84,13 +86,14 @@ public class DeployerPartitionHandlerTests { private Environment environment; - @Before + @BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); this.environment = new MockEnvironment(); TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(), new Date(), "", Collections.emptyList(), null, null, null); - when(taskRepository.createTaskExecution()).thenReturn(taskExecution); + Mockito.lenient().when(taskRepository.createTaskExecution()) + .thenReturn(taskExecution); } @Test @@ -695,7 +698,7 @@ public class DeployerPartitionHandlerTests { .isTrue(); } - @Test(expected = TimeoutException.class) + @Test public void testTimeout() throws Exception { StepExecution masterStepExecution = createMasterStepExecution(); @@ -727,14 +730,16 @@ public class DeployerPartitionHandlerTests { when(this.jobExplorer.getStepExecution(1L, 4L)) .thenReturn(workerStepExecutionFinish1); - when(this.jobExplorer.getStepExecution(1L, 5L)) + Mockito.lenient().when(this.jobExplorer.getStepExecution(1L, 5L)) .thenReturn(workerStepExecutionFinish2); handler.afterPropertiesSet(); handler.beforeTask(taskExecution); - handler.handle(this.splitter, masterStepExecution); + assertThatExceptionOfType(TimeoutException.class).isThrownBy(() -> { + handler.handle(this.splitter, masterStepExecution); + }); } @Test diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java index a92d86d6..e78c0b40 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java @@ -16,8 +16,8 @@ package org.springframework.cloud.task.batch.partition; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -39,7 +39,7 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; /** @@ -67,7 +67,7 @@ public class DeployerStepExecutionHandlerTests { private DeployerStepExecutionHandler handler; - @Before + @BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); @@ -192,7 +192,7 @@ public class DeployerStepExecutionHandlerTests { this.handler.run(); verify(this.step).execute(workerStep); - verifyZeroInteractions(this.jobRepository); + verifyNoMoreInteractions(this.jobRepository); } @Test diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java index a8bdcdda..4058527f 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java @@ -18,8 +18,8 @@ package org.springframework.cloud.task.batch.partition; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -30,7 +30,7 @@ public class NoOpEnvironmentVariablesProviderTests { private NoOpEnvironmentVariablesProvider provider; - @Before + @BeforeEach public void setUp() { this.provider = new NoOpEnvironmentVariablesProvider(); } diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java index fd9a19a7..b1110c85 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java @@ -19,18 +19,21 @@ package org.springframework.cloud.task.batch.partition; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Michael Minella */ public class PassThroughCommandLineArgsProviderTests { - @Test(expected = IllegalArgumentException.class) + @Test public void testNull() { - new PassThroughCommandLineArgsProvider(null); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + new PassThroughCommandLineArgsProvider(null); + }); } @Test diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java index a42eb384..7196f586 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.repository.TaskExecution; diff --git a/spring-cloud-task-core/pom.xml b/spring-cloud-task-core/pom.xml index a123a19c..4b3892d9 100755 --- a/spring-cloud-task-core/pom.xml +++ b/spring-cloud-task-core/pom.xml @@ -115,9 +115,13 @@ test - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine test diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationTests.java index 6524b6d2..ffc000ce 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.task; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationWithDataSourceTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationWithDataSourceTests.java index 16a12085..d2b79b35 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationWithDataSourceTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleSingleTaskAutoConfigurationWithDataSourceTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.task; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java index 779a7b94..3fed96b3 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java @@ -18,8 +18,8 @@ package org.springframework.cloud.task; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; import org.springframework.aop.framework.AopProxyUtils; @@ -61,7 +61,7 @@ public class SimpleTaskAutoConfigurationTests { private ConfigurableApplicationContext context; - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskCoreTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskCoreTests.java index 1e3956f1..e52e24fe 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskCoreTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskCoreTests.java @@ -16,15 +16,16 @@ package org.springframework.cloud.task; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.cloud.task.configuration.EnableTask; import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration; import org.springframework.context.ApplicationContextException; @@ -38,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Glenn Renfro */ +@ExtendWith(OutputCaptureExtension.class) public class TaskCoreTests { private static final String TASK_NAME = "taskEventTest"; @@ -58,15 +60,9 @@ public class TaskCoreTests { private static final String ERROR_MESSAGE = "errorMessage='java.lang.IllegalStateException: " + "Failed to execute CommandLineRunner"; - /** - * Used to capture the log output from the test task. - */ - @Rule - public OutputCaptureRule outputCapture = new OutputCaptureRule(); - private ConfigurableApplicationContext applicationContext; - @After + @AfterEach public void teardown() { if (this.applicationContext != null && this.applicationContext.isActive()) { this.applicationContext.close(); @@ -74,13 +70,13 @@ public class TaskCoreTests { } @Test - public void successfulTaskTest() { + public void successfulTaskTest(CapturedOutput capturedOutput) { this.applicationContext = SpringApplication.run(TaskConfiguration.class, "--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME, "--spring.main.web-environment=false"); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output.contains(CREATE_TASK_MESSAGE)) .as("Test results do not show create task message: " + output).isTrue(); assertThat(output.contains(UPDATE_TASK_MESSAGE)) @@ -93,14 +89,14 @@ public class TaskCoreTests { * Test to verify that deprecated annotation does not affect task execution. */ @Test - public void successfulTaskTestWithAnnotation() { + public void successfulTaskTestWithAnnotation(CapturedOutput capturedOutput) { this.applicationContext = SpringApplication.run( TaskConfigurationWithAnotation.class, "--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME, "--spring.main.web-environment=false"); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output.contains(CREATE_TASK_MESSAGE)) .as("Test results do not show create task message: " + output).isTrue(); assertThat(output.contains(UPDATE_TASK_MESSAGE)) @@ -110,7 +106,7 @@ public class TaskCoreTests { } @Test - public void exceptionTaskTest() { + public void exceptionTaskTest(CapturedOutput capturedOutput) { boolean exceptionFired = false; try { this.applicationContext = SpringApplication.run( @@ -125,7 +121,7 @@ public class TaskCoreTests { assertThat(exceptionFired).as("An IllegalStateException should have been thrown") .isTrue(); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output.contains(CREATE_TASK_MESSAGE)) .as("Test results do not show create task message: " + output).isTrue(); assertThat(output.contains(UPDATE_TASK_MESSAGE)) @@ -139,7 +135,7 @@ public class TaskCoreTests { } @Test - public void invalidExecutionId() { + public void invalidExecutionId(CapturedOutput capturedOutput) { boolean exceptionFired = false; try { this.applicationContext = SpringApplication.run( @@ -155,7 +151,7 @@ public class TaskCoreTests { assertThat(exceptionFired) .as("An ApplicationContextException should have been thrown").isTrue(); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output.contains(EXCEPTION_INVALID_TASK_EXECUTION_ID)) .as("Test results do not show the correct exception message: " + output) .isTrue(); diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerDefaultTaskConfigurerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerDefaultTaskConfigurerTests.java index cd6ce0ad..6d010e1c 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerDefaultTaskConfigurerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerDefaultTaskConfigurerTests.java @@ -21,8 +21,8 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; @@ -31,7 +31,7 @@ import org.springframework.cloud.task.configuration.TaskConfigurer; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; @@ -42,7 +42,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; * @author Glenn Renfro * @since 2.0.0 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class, EmbeddedDataSourceConfiguration.class }) @DirtiesContext diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerNoDataSourceTaskConfigurerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerNoDataSourceTaskConfigurerTests.java index 0779d7fb..c2877001 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerNoDataSourceTaskConfigurerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/TaskRepositoryInitializerNoDataSourceTaskConfigurerTests.java @@ -21,8 +21,8 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; @@ -32,7 +32,7 @@ import org.springframework.cloud.task.configuration.SingleTaskConfiguration; import org.springframework.cloud.task.configuration.TaskConfigurer; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; @@ -43,7 +43,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; * @author Glenn Renfro * @since 2.0.0 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration( classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class, EmbeddedDataSourceConfiguration.class, DefaultTaskConfigurer.class }) diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurerTests.java index d5b454df..9fb799c6 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurerTests.java @@ -19,8 +19,8 @@ package org.springframework.cloud.task.configuration; import javax.persistence.EntityManager; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; @@ -29,7 +29,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock; /** * @author Glenn Renfro */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { EmbeddedDataSourceConfiguration.class }) public class DefaultTaskConfigurerTests { diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/RepositoryTransactionManagerConfigurationTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/RepositoryTransactionManagerConfigurationTests.java index b61de918..9e9699bd 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/RepositoryTransactionManagerConfigurationTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/RepositoryTransactionManagerConfigurationTests.java @@ -21,7 +21,7 @@ import java.util.Date; import javax.sql.DataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/TaskPropertiesTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/TaskPropertiesTests.java index 0a8393a1..4dc66639 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/TaskPropertiesTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/TaskPropertiesTests.java @@ -16,25 +16,22 @@ package org.springframework.cloud.task.configuration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Suite.class) -@SuiteClasses({ TaskPropertiesTests.CloseContextEnabledTest.class - -}) - @DirtiesContext +@ExtendWith(SpringExtension.class) +@SpringBootTest( + classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class }, + properties = { "spring.cloud.task.closecontextEnabled=false", + "spring.cloud.task.initialize-enabled=false" }) public class TaskPropertiesTests { @Autowired @@ -46,20 +43,4 @@ public class TaskPropertiesTests { assertThat(this.taskProperties.isInitializeEnabled()).isFalse(); } - @RunWith(SpringRunner.class) - @SpringBootTest( - classes = { TaskPropertiesTests.Config.class, - SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class }, - properties = { "spring.cloud.task.closecontextEnabled=false", - "spring.cloud.task.initialize-enabled=false" }) - @DirtiesContext - public static class CloseContextEnabledTest extends TaskPropertiesTests { - - } - - @Configuration - public static class Config { - - } - } diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExceptionTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExceptionTests.java index a263648e..271cb42c 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExceptionTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExceptionTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.task.listener; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExecutionListenerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExecutionListenerTests.java index b4403c4f..8b0d4904 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExecutionListenerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskExecutionListenerTests.java @@ -19,8 +19,8 @@ package org.springframework.cloud.task.listener; import java.util.ArrayList; import java.util.Date; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -64,7 +64,7 @@ public class TaskExecutionListenerTests { failedTaskDidFireOnError = false; } - @After + @AfterEach public void tearDown() { if (this.context != null && this.context.isActive()) { this.context.close(); diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java index a1211406..688e9e7c 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java @@ -23,10 +23,10 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ExitCodeEvent; @@ -34,7 +34,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.cloud.task.repository.TaskExecution; import org.springframework.cloud.task.repository.TaskExplorer; import org.springframework.cloud.task.util.TestDefaultConfiguration; @@ -52,6 +53,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Verifies that the TaskLifecycleListener Methods record the appropriate log header @@ -60,19 +62,14 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Glenn Renfro * @author Michael Minella */ +@ExtendWith(OutputCaptureExtension.class) public class TaskLifecycleListenerTests { - /** - * Used to capture the log output from the test task. - */ - @Rule - public OutputCaptureRule outputCapture = new OutputCaptureRule(); - private AnnotationConfigApplicationContext context; private TaskExplorer taskExplorer; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext(); this.context.setId("testTask"); @@ -84,7 +81,7 @@ public class TaskLifecycleListenerTests { } - @After + @AfterEach public void tearDown() { if (this.context != null && this.context.isActive()) { this.context.close(); @@ -175,25 +172,27 @@ public class TaskLifecycleListenerTests { } } - @Test(expected = ApplicationContextException.class) + @Test public void testInvalidTaskExecutionId() { - ConfigurableEnvironment environment = new StandardEnvironment(); - MutablePropertySources propertySources = environment.getPropertySources(); - Map myMap = new HashMap<>(); - myMap.put("spring.cloud.task.executionid", "55"); - propertySources - .addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap)); - this.context.setEnvironment(environment); - this.context.refresh(); + assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> { + ConfigurableEnvironment environment = new StandardEnvironment(); + MutablePropertySources propertySources = environment.getPropertySources(); + Map myMap = new HashMap<>(); + myMap.put("spring.cloud.task.executionid", "55"); + propertySources + .addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap)); + this.context.setEnvironment(environment); + this.context.refresh(); + }); } @Test - public void testRestartExistingTask() { + public void testRestartExistingTask(CapturedOutput capturedOutput) { this.context.refresh(); TaskLifecycleListener taskLifecycleListener = this.context .getBean(TaskLifecycleListener.class); taskLifecycleListener.start(); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output.contains("Multiple start events have been received")) .as("Test results do not show error message: " + output).isTrue(); } diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskListenerExecutorObjectFactoryTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskListenerExecutorObjectFactoryTests.java index 732f6513..71c93639 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskListenerExecutorObjectFactoryTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskListenerExecutorObjectFactoryTests.java @@ -19,9 +19,9 @@ package org.springframework.cloud.task.listener; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.task.listener.annotation.AfterTask; @@ -34,7 +34,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Glenn Renfro * @since 2.1.0 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class }) @DirtiesContext @@ -78,7 +78,7 @@ public class TaskListenerExecutorObjectFactoryTests { private TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory; - @Before + @BeforeEach public void setup() { taskExecutionListenerResults.clear(); this.taskListenerExecutorObjectFactory = new TaskListenerExecutorObjectFactory( diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/AbstractMicrometerTest.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/AbstractMicrometerTest.java index 97bc286d..9e02efaa 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/AbstractMicrometerTest.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/AbstractMicrometerTest.java @@ -25,10 +25,10 @@ import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.simple.SimpleConfig; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import io.pivotal.cfenv.test.CfEnvTestUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -39,7 +39,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Christian Tzolov * @author Soby Chacko */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = { AbstractMicrometerTest.AutoConfigurationApplication.class }) @DirtiesContext public class AbstractMicrometerTest { @@ -61,7 +61,7 @@ public class AbstractMicrometerTest { protected Meter meter; - @Before + @BeforeEach public void before() { Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove); assertThat(simpleMeterRegistry).isNotNull(); @@ -70,12 +70,12 @@ public class AbstractMicrometerTest { "The spring.integration.handlers meter must be present in SpringBoot apps!"); } - @After + @AfterEach public void after() { Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove); } - @BeforeClass + @BeforeAll public static void setup() throws IOException { String serviceJson = StreamUtils.copyToString(new DefaultResourceLoader() .getResource("classpath:/micrometer/pcf-scs-info.json").getInputStream(), diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/CloudFoundryMicrometerTagsConfigurationTest.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/CloudFoundryMicrometerTagsConfigurationTest.java index 17385606..010bb9ef 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/CloudFoundryMicrometerTagsConfigurationTest.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/CloudFoundryMicrometerTagsConfigurationTest.java @@ -16,9 +16,8 @@ package org.springframework.cloud.task.micrometer; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; @@ -28,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Christian Tzolov */ -@RunWith(Enclosed.class) +@Nested public class CloudFoundryMicrometerTagsConfigurationTest { @ActiveProfiles("cloud") diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/SpringCloudTaskMicrometerCommonTagsConfigurationTest.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/SpringCloudTaskMicrometerCommonTagsConfigurationTest.java index d00c013e..19f74d62 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/SpringCloudTaskMicrometerCommonTagsConfigurationTest.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/SpringCloudTaskMicrometerCommonTagsConfigurationTest.java @@ -16,9 +16,8 @@ package org.springframework.cloud.task.micrometer; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -27,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Christian Tzolov */ -@RunWith(Enclosed.class) +@Nested public class SpringCloudTaskMicrometerCommonTagsConfigurationTest { public static class TestDefaultTagValues extends AbstractMicrometerTest { diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/TaskMetricsTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/TaskMetricsTests.java index e2504d31..9cb74c3a 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/TaskMetricsTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/micrometer/TaskMetricsTests.java @@ -23,9 +23,9 @@ import io.micrometer.core.instrument.LongTaskTimer; import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.listener.TaskMetrics; import org.springframework.cloud.task.repository.TaskExecution; @@ -41,7 +41,7 @@ public class TaskMetricsTests { private SimpleMeterRegistry simpleMeterRegistry; - @Before + @BeforeEach public void before() { Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove); simpleMeterRegistry = new SimpleMeterRegistry(); @@ -49,7 +49,7 @@ public class TaskMetricsTests { taskMetrics = new TaskMetrics(); } - @After + @AfterEach public void after() { Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove); } diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/BaseTaskExecutionDaoTestCases.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/BaseTaskExecutionDaoTestCases.java index 3cf75134..3d140502 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/BaseTaskExecutionDaoTestCases.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/BaseTaskExecutionDaoTestCases.java @@ -21,7 +21,7 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.repository.TaskExecution; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDaoTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDaoTests.java index d65c4ac9..e18535f0 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDaoTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDaoTests.java @@ -24,9 +24,9 @@ import java.util.UUID; 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.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; @@ -42,9 +42,10 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Executes unit tests on JdbcTaskExecutionDao. @@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Glenn Renfro * @author Gunnar Hillert */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration( classes = { TestConfiguration.class, EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) @@ -64,7 +65,7 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases { @Autowired private DataSource dataSource; - @Before + @BeforeEach public void setup() { final JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(this.dataSource); dao.setTaskIncrementer(TestDBUtils.getIncrementer(this.dataSource)); @@ -135,16 +136,19 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases { expectedTaskExecution.getExecutionId())); } - @Test(expected = IllegalStateException.class) + @Test @DirtiesContext public void completeTaskExecutionWithNoCreate() { JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(this.dataSource); TaskExecution expectedTaskExecution = TestVerifierUtils .endSampleTaskExecutionNoArg(); - dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), - expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(), - expectedTaskExecution.getExitMessage()); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), + expectedTaskExecution.getExitCode(), + expectedTaskExecution.getEndTime(), + expectedTaskExecution.getExitMessage()); + }); } @Test diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java index 154628b6..415e783b 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java @@ -25,13 +25,14 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.repository.TaskExecution; import org.springframework.cloud.task.util.TestVerifierUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Executes unit tests on MapTaskExecutionDaoTests. @@ -43,7 +44,7 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases { private MapTaskExecutionDao mapTaskExecutionDao; - @Before + @BeforeEach public void setUp() { this.mapTaskExecutionDao = new MapTaskExecutionDao(); super.dao = this.mapTaskExecutionDao; @@ -81,13 +82,16 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases { taskExecutionMap.get(expectedTaskExecution.getExecutionId())); } - @Test(expected = IllegalStateException.class) + @Test public void completeTaskExecutionWithNoCreate() { TaskExecution expectedTaskExecution = TestVerifierUtils .createSampleTaskExecutionNoArg(); - this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), - expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(), - expectedTaskExecution.getExitMessage()); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), + expectedTaskExecution.getExitCode(), + expectedTaskExecution.getEndTime(), + expectedTaskExecution.getExitMessage()); + }); } @Test diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/FindAllPagingQueryProviderTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/FindAllPagingQueryProviderTests.java index 0a7b76e8..f091e3b6 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/FindAllPagingQueryProviderTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/FindAllPagingQueryProviderTests.java @@ -19,9 +19,8 @@ package org.springframework.cloud.task.repository.database.support; import java.util.Arrays; import java.util.Collection; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.cloud.task.util.TestDBUtils; import org.springframework.data.domain.PageRequest; @@ -32,23 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Glenn Renfro */ -@RunWith(Parameterized.class) public class FindAllPagingQueryProviderTests { - private String databaseProductName; - - private String expectedQuery; - private Pageable pageable = PageRequest.of(0, 10); - public FindAllPagingQueryProviderTests(String databaseProductName, - String expectedQuery) { - this.databaseProductName = databaseProductName; - this.expectedQuery = expectedQuery; - } - - // @checkstyle:off - @Parameterized.Parameters public static Collection data() { return Arrays.asList(new Object[][] { { "Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, " @@ -82,16 +68,17 @@ public class FindAllPagingQueryProviderTests { + "WHERE TMP_ROW_NUM >= 1 AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, " + "TASK_EXECUTION_ID DESC" } }); } - // @checkstyle:on - @Test - public void testGeneratedQuery() throws Exception { - String actualQuery = TestDBUtils.getPagingQueryProvider(this.databaseProductName) + @ParameterizedTest + @MethodSource("data") + public void testGeneratedQuery(String databaseProductName, String expectedQuery) + throws Exception { + String actualQuery = TestDBUtils.getPagingQueryProvider(databaseProductName) .getPageQuery(this.pageable); assertThat(actualQuery).as( String.format("the generated query for %s, was not the expected query", - this.databaseProductName)) - .isEqualTo(this.expectedQuery); + databaseProductName)) + .isEqualTo(expectedQuery); } } diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/InvalidPagingQueryProviderTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/InvalidPagingQueryProviderTests.java index e1e98991..5894fe60 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/InvalidPagingQueryProviderTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/InvalidPagingQueryProviderTests.java @@ -16,21 +16,25 @@ package org.springframework.cloud.task.repository.database.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.util.TestDBUtils; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + /** * @author Glenn Renfro */ public class InvalidPagingQueryProviderTests { - @Test(expected = IllegalStateException.class) + @Test public void testInvalidDatabase() throws Exception { Pageable pageable = PageRequest.of(0, 10); - TestDBUtils.getPagingQueryProvider("Invalid").getPageQuery(pageable); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + TestDBUtils.getPagingQueryProvider("Invalid").getPageQuery(pageable); + }); } } diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/SqlPagingQueryProviderFactoryBeanTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/SqlPagingQueryProviderFactoryBeanTests.java index a5a76b1c..7af7a1bd 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/SqlPagingQueryProviderFactoryBeanTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/SqlPagingQueryProviderFactoryBeanTests.java @@ -19,8 +19,8 @@ package org.springframework.cloud.task.repository.database.support; import java.util.Map; import java.util.TreeMap; -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.database.Order; import org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao; @@ -36,7 +36,7 @@ public class SqlPagingQueryProviderFactoryBeanTests { private SqlPagingQueryProviderFactoryBean factoryBean; - @Before + @BeforeEach public void setup() throws Exception { this.factoryBean = new SqlPagingQueryProviderFactoryBean(); this.factoryBean.setDataSource(TestDBUtils.getMockDataSource("MySQL")); diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/WhereClausePagingQueryProviderTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/WhereClausePagingQueryProviderTests.java index bb0e2f52..6535494f 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/WhereClausePagingQueryProviderTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/database/support/WhereClausePagingQueryProviderTests.java @@ -19,9 +19,8 @@ package org.springframework.cloud.task.repository.database.support; import java.util.Arrays; import java.util.Collection; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.cloud.task.repository.database.PagingQueryProvider; import org.springframework.cloud.task.util.TestDBUtils; @@ -33,23 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Glenn Renfro */ -@RunWith(Parameterized.class) public class WhereClausePagingQueryProviderTests { - private String databaseProductName; - - private String expectedQuery; - private Pageable pageable = PageRequest.of(0, 10); - public WhereClausePagingQueryProviderTests(String databaseProductName, - String expectedQuery) { - this.databaseProductName = databaseProductName; - this.expectedQuery = expectedQuery; - } - - // @checkstyle:off - @Parameterized.Parameters public static Collection data() { return Arrays.asList(new Object[][] { { "Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, " @@ -87,17 +73,18 @@ public class WhereClausePagingQueryProviderTests { + "'0000') TASK_EXECUTION_PAGE WHERE TMP_ROW_NUM >= 1 " + "AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC" } }); } - // @checkstyle:on - @Test - public void testGeneratedQuery() throws Exception { + @ParameterizedTest + @MethodSource("data") + public void testGeneratedQuery(String databaseProductName, String expectedQuery) + throws Exception { PagingQueryProvider pagingQueryProvider = TestDBUtils.getPagingQueryProvider( - this.databaseProductName, "TASK_EXECUTION_ID = '0000'"); + databaseProductName, "TASK_EXECUTION_ID = '0000'"); String actualQuery = pagingQueryProvider.getPageQuery(this.pageable); assertThat(actualQuery).as( String.format("the generated query for %s, was not the expected query", - this.databaseProductName)) - .isEqualTo(this.expectedQuery); + databaseProductName)) + .isEqualTo(expectedQuery); } } diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/DatabaseTypeTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/DatabaseTypeTests.java index ddecf587..0cee6515 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/DatabaseTypeTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/DatabaseTypeTests.java @@ -18,11 +18,12 @@ package org.springframework.cloud.task.repository.support; import javax.sql.DataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.util.TestDBUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.springframework.cloud.task.repository.support.DatabaseType.HSQL; import static org.springframework.cloud.task.repository.support.DatabaseType.MYSQL; import static org.springframework.cloud.task.repository.support.DatabaseType.ORACLE; @@ -48,9 +49,10 @@ public class DatabaseTypeTests { assertThat(fromProductName("MariaDB")).isEqualTo(MYSQL); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidProductName() { - fromProductName("bad product name"); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> fromProductName("bad product name")); } @Test diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskExplorerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskExplorerTests.java index cbb95a34..de2dd71d 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskExplorerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskExplorerTests.java @@ -29,13 +29,9 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -58,19 +54,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Glenn Renfro * @author Gunnar Hillert */ -@RunWith(Parameterized.class) public class SimpleTaskExplorerTests { private final static String TASK_NAME = "FOOBAR"; private final static String EXTERNAL_EXECUTION_ID = "123ABC"; - /** - * Establishes that a Exception is not expected. - */ - @Rule - public ExpectedException expected = ExpectedException.none(); - private AnnotationConfigApplicationContext context; @Autowired @@ -79,21 +68,12 @@ public class SimpleTaskExplorerTests { @Autowired private TaskRepository taskRepository; - private DaoType testType; - - public SimpleTaskExplorerTests(DaoType testType) { - this.testType = testType; - } - - @Parameterized.Parameters public static Collection data() { return Arrays.asList(new Object[] { DaoType.jdbc, DaoType.map }); } - @Before - public void testDefaultContext() throws Exception { - - if (this.testType == DaoType.jdbc) { + public void testDefaultContext(DaoType testType) { + if (testType == DaoType.jdbc) { initializeJdbcExplorerTest(); } else { @@ -101,70 +81,80 @@ public class SimpleTaskExplorerTests { } } - @After + @AfterEach public void close() { if (this.context != null) { this.context.close(); } } - @Test - public void getTaskExecution() { + @ParameterizedTest + @MethodSource("data") + public void getTaskExecution(DaoType testType) { + testDefaultContext(testType); Map expectedResults = createSampleDataSet(5); for (Long taskExecutionId : expectedResults.keySet()) { TaskExecution actualTaskExecution = this.taskExplorer .getTaskExecution(taskExecutionId); assertThat(actualTaskExecution).as(String.format( - "expected a taskExecution but got null for test type %s", - this.testType)).isNotNull(); + "expected a taskExecution but got null for test type %s", testType)) + .isNotNull(); TestVerifierUtils.verifyTaskExecution(expectedResults.get(taskExecutionId), actualTaskExecution); } } - @Test - public void taskExecutionNotFound() { + @ParameterizedTest + @MethodSource("data") + public void taskExecutionNotFound(DaoType testType) { + testDefaultContext(testType); createSampleDataSet(5); TaskExecution actualTaskExecution = this.taskExplorer.getTaskExecution(-5); - assertThat(actualTaskExecution).as( - String.format("expected null for actualTaskExecution %s", this.testType)) + assertThat(actualTaskExecution) + .as(String.format("expected null for actualTaskExecution %s", testType)) .isNull(); } - @Test - public void getTaskCountByTaskName() { + @ParameterizedTest + @MethodSource("data") + public void getTaskCountByTaskName(DaoType testType) { + testDefaultContext(testType); Map expectedResults = createSampleDataSet(5); for (Map.Entry entry : expectedResults.entrySet()) { String taskName = entry.getValue().getTaskName(); assertThat(this.taskExplorer.getTaskExecutionCountByTaskName(taskName)) .as(String.format( "task count for task name did not match expected result for testType %s", - this.testType)) + testType)) .isEqualTo(1); } } - @Test - public void getTaskCount() { + @ParameterizedTest + @MethodSource("data") + public void getTaskCount(DaoType testType) { + testDefaultContext(testType); createSampleDataSet(33); - assertThat(this.taskExplorer.getTaskExecutionCount()).as( - String.format("task count did not match expected result for test Type %s", - this.testType)) + assertThat(this.taskExplorer.getTaskExecutionCount()).as(String.format( + "task count did not match expected result for test Type %s", testType)) .isEqualTo(33); } - @Test - public void getRunningTaskCount() { + @ParameterizedTest + @MethodSource("data") + public void getRunningTaskCount(DaoType testType) { + testDefaultContext(testType); createSampleDataSet(33); - assertThat(this.taskExplorer.getRunningTaskExecutionCount()).as( - String.format("task count did not match expected result for test Type %s", - this.testType)) + assertThat(this.taskExplorer.getRunningTaskExecutionCount()).as(String.format( + "task count did not match expected result for test Type %s", testType)) .isEqualTo(33); } - @Test - public void findRunningTasks() { + @ParameterizedTest + @MethodSource("data") + public void findRunningTasks(DaoType testType) { + testDefaultContext(testType); final int TEST_COUNT = 2; final int COMPLETE_COUNT = 5; @@ -187,21 +177,23 @@ public class SimpleTaskExplorerTests { .findRunningTaskExecutions(TASK_NAME, pageable); assertThat(actualResults.getNumberOfElements()).as(String.format( "Running task count for task name did not match expected result for testType %s", - this.testType)).isEqualTo(TEST_COUNT); + testType)).isEqualTo(TEST_COUNT); for (TaskExecution result : actualResults) { assertThat(expectedResults.containsKey(result.getExecutionId())).as(String .format("result returned from repo %s not expected for testType %s", - result.getExecutionId(), this.testType)) + result.getExecutionId(), testType)) .isTrue(); assertThat(result.getEndTime()).as(String.format( - "result had non null for endTime for the testType %s", this.testType)) + "result had non null for endTime for the testType %s", testType)) .isNull(); } } - @Test - public void findTasksByName() { + @ParameterizedTest + @MethodSource("data") + public void findTasksByName(DaoType testType) { + testDefaultContext(testType); final int TEST_COUNT = 5; final int COMPLETE_COUNT = 7; @@ -223,21 +215,23 @@ public class SimpleTaskExplorerTests { .findTaskExecutionsByName(TASK_NAME, pageable); assertThat(resultSet.getNumberOfElements()).as(String.format( "Running task count for task name did not match expected result for testType %s", - this.testType)).isEqualTo(TEST_COUNT); + testType)).isEqualTo(TEST_COUNT); for (TaskExecution result : resultSet) { assertThat(expectedResults.containsKey(result.getExecutionId())) .as(String.format("result returned from %s repo %s not expected", - this.testType, result.getExecutionId())) + testType, result.getExecutionId())) .isTrue(); assertThat(result.getTaskName()).as(String.format( - "taskName for taskExecution is incorrect for testType %s", - this.testType)).isEqualTo(TASK_NAME); + "taskName for taskExecution is incorrect for testType %s", testType)) + .isEqualTo(TASK_NAME); } } - @Test - public void getTaskNames() { + @ParameterizedTest + @MethodSource("data") + public void getTaskNames(DaoType testType) { + testDefaultContext(testType); final int TEST_COUNT = 5; Set expectedResults = new HashSet<>(); for (int i = 0; i < TEST_COUNT; i++) { @@ -246,50 +240,63 @@ public class SimpleTaskExplorerTests { } List actualTaskNames = this.taskExplorer.getTaskNames(); for (String taskName : actualTaskNames) { - assertThat(expectedResults.contains(taskName)).as( - String.format("taskName was not in expected results for testType %s", - this.testType)) + assertThat(expectedResults.contains(taskName)).as(String.format( + "taskName was not in expected results for testType %s", testType)) .isTrue(); } } - @Test - public void findAllExecutionsOffBoundry() { + @ParameterizedTest + @MethodSource("data") + public void findAllExecutionsOffBoundry(DaoType testType) { + testDefaultContext(testType); Pageable pageable = PageRequest.of(0, 10); verifyPageResults(pageable, 103); } - @Test - public void findAllExecutionsOffBoundryByOne() { + @ParameterizedTest + @MethodSource("data") + public void findAllExecutionsOffBoundryByOne(DaoType testType) { + testDefaultContext(testType); Pageable pageable = PageRequest.of(0, 10); verifyPageResults(pageable, 101); } - @Test - public void findAllExecutionsOnBoundry() { + @ParameterizedTest + @MethodSource("data") + public void findAllExecutionsOnBoundry(DaoType testType) { + testDefaultContext(testType); Pageable pageable = PageRequest.of(0, 10); verifyPageResults(pageable, 100); } - @Test - public void findAllExecutionsNoResult() { + @ParameterizedTest + @MethodSource("data") + public void findAllExecutionsNoResult(DaoType testType) { + testDefaultContext(testType); Pageable pageable = PageRequest.of(0, 10); verifyPageResults(pageable, 0); } - @Test - public void findTasksForInvalidJob() { + @ParameterizedTest + @MethodSource("data") + public void findTasksForInvalidJob(DaoType testType) { + testDefaultContext(testType); assertThat(this.taskExplorer.getTaskExecutionIdByJobExecutionId(55555L)).isNull(); } - @Test - public void findJobsExecutionIdsForInvalidTask() { + @ParameterizedTest + @MethodSource("data") + public void findJobsExecutionIdsForInvalidTask(DaoType testType) { + testDefaultContext(testType); assertThat(this.taskExplorer.getJobExecutionIdsByTaskExecutionId(555555L).size()) .isEqualTo(0); } - @Test - public void getLatestTaskExecutionForTaskName() { + @ParameterizedTest + @MethodSource("data") + public void getLatestTaskExecutionForTaskName(DaoType testType) { + testDefaultContext(testType); Map expectedResults = createSampleDataSet(5); for (Map.Entry taskExecutionMapEntry : expectedResults .entrySet()) { @@ -297,16 +304,18 @@ public class SimpleTaskExplorerTests { .getLatestTaskExecutionForTaskName( taskExecutionMapEntry.getValue().getTaskName()); assertThat(latestTaskExecution).as(String.format( - "expected a taskExecution but got null for test type %s", - this.testType)).isNotNull(); + "expected a taskExecution but got null for test type %s", testType)) + .isNotNull(); TestVerifierUtils.verifyTaskExecution( expectedResults.get(latestTaskExecution.getExecutionId()), latestTaskExecution); } } - @Test - public void getLatestTaskExecutionsByTaskNames() { + @ParameterizedTest + @MethodSource("data") + public void getLatestTaskExecutionsByTaskNames(DaoType testType) { + testDefaultContext(testType); Map expectedResults = createSampleDataSet(5); final List taskNamesAsList = new ArrayList<>(); @@ -321,8 +330,8 @@ public class SimpleTaskExplorerTests { for (TaskExecution latestTaskExecution : latestTaskExecutions) { assertThat(latestTaskExecution).as(String.format( - "expected a taskExecution but got null for test type %s", - this.testType)).isNotNull(); + "expected a taskExecution but got null for test type %s", testType)) + .isNotNull(); TestVerifierUtils.verifyTaskExecution( expectedResults.get(latestTaskExecution.getExecutionId()), latestTaskExecution); diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskNameResolverTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskNameResolverTests.java index 8ab4e113..e75298c6 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskNameResolverTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskNameResolverTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.task.repository.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.GenericApplicationContext; diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryJdbcTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryJdbcTests.java index b553f017..987bbbd9 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryJdbcTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryJdbcTests.java @@ -22,8 +22,8 @@ import java.util.UUID; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; @@ -36,9 +36,10 @@ import org.springframework.cloud.task.util.TestDBUtils; import org.springframework.cloud.task.util.TestVerifierUtils; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Tests for the SimpleTaskRepository that uses JDBC as a datastore. @@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Michael Minella * @author Ilayaperumal Gopinathan */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { EmbeddedDataSourceConfiguration.class, SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) @DirtiesContext @@ -153,13 +154,15 @@ public class SimpleTaskRepositoryJdbcTests { expectedTaskExecution.getExecutionId())); } - @Test(expected = IllegalStateException.class) + @Test public void testInvalidExecutionIdForExternalExecutionIdUpdate() { TaskExecution expectedTaskExecution = TaskExecutionCreator .createAndStoreTaskExecutionNoParams(this.taskRepository); expectedTaskExecution.setExternalExecutionId(null); - this.taskRepository.updateExternalExecutionId(-1, - expectedTaskExecution.getExternalExecutionId()); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + this.taskRepository.updateExternalExecutionId(-1, + expectedTaskExecution.getExternalExecutionId()); + }); } @Test @@ -260,7 +263,7 @@ public class SimpleTaskRepositoryJdbcTests { assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMaxTaskNameSizeForConstructor() { final int MAX_EXIT_MESSAGE_SIZE = 10; final int MAX_ERROR_MESSAGE_SIZE = 20; @@ -271,10 +274,12 @@ public class SimpleTaskRepositoryJdbcTests { TaskExecution expectedTaskExecution = TestVerifierUtils .createSampleTaskExecutionNoArg(); expectedTaskExecution.setTaskName(new String(new char[MAX_TASK_NAME_SIZE + 1])); - simpleTaskRepository.createTaskExecution(expectedTaskExecution); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + simpleTaskRepository.createTaskExecution(expectedTaskExecution); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testDefaultMaxTaskNameSizeForConstructor() { SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository( new TaskExecutionDaoFactoryBean(this.dataSource), null, null, null); @@ -282,7 +287,9 @@ public class SimpleTaskRepositoryJdbcTests { .createSampleTaskExecutionNoArg(); expectedTaskExecution.setTaskName( new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1])); - simpleTaskRepository.createTaskExecution(expectedTaskExecution); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + simpleTaskRepository.createTaskExecution(expectedTaskExecution); + }); } @Test @@ -304,17 +311,19 @@ public class SimpleTaskRepositoryJdbcTests { SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE, simpleTaskRepository); } - @Test(expected = IllegalArgumentException.class) + @Test @DirtiesContext public void testCreateTaskExecutionNoParamMaxTaskName() { TaskExecution taskExecution = new TaskExecution(); taskExecution.setTaskName( new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1])); taskExecution.setStartTime(new Date()); - this.taskRepository.createTaskExecution(taskExecution); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + this.taskRepository.createTaskExecution(taskExecution); + }); } - @Test(expected = IllegalArgumentException.class) + @Test @DirtiesContext public void testCreateTaskExecutionNegativeException() { TaskExecution expectedTaskExecution = TaskExecutionCreator @@ -322,19 +331,24 @@ public class SimpleTaskRepositoryJdbcTests { expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setExitCode(-1); - TaskExecution actualTaskExecution = TaskExecutionCreator - .completeExecution(this.taskRepository, expectedTaskExecution); - TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + TaskExecution actualTaskExecution = TaskExecutionCreator + .completeExecution(this.taskRepository, expectedTaskExecution); + TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, + actualTaskExecution); + }); } - @Test(expected = IllegalArgumentException.class) + @Test @DirtiesContext public void testCreateTaskExecutionNullEndTime() { TaskExecution expectedTaskExecution = TaskExecutionCreator .createAndStoreTaskExecutionNoParams(this.taskRepository); expectedTaskExecution.setExitCode(-1); - TaskExecutionCreator.completeExecution(this.taskRepository, - expectedTaskExecution); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + TaskExecutionCreator.completeExecution(this.taskRepository, + expectedTaskExecution); + }); } private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution, diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryMapTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryMapTests.java index 5d58198b..2e3ebd8a 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryMapTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/SimpleTaskRepositoryMapTests.java @@ -21,8 +21,8 @@ import java.util.Date; import java.util.Map; import java.util.UUID; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.repository.TaskExecution; import org.springframework.cloud.task.repository.TaskRepository; @@ -30,6 +30,7 @@ import org.springframework.cloud.task.repository.dao.MapTaskExecutionDao; import org.springframework.cloud.task.util.TaskExecutionCreator; import org.springframework.cloud.task.util.TestVerifierUtils; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.springframework.test.util.AssertionErrors.assertTrue; /** @@ -42,7 +43,7 @@ public class SimpleTaskRepositoryMapTests { private TaskRepository taskRepository; - @Before + @BeforeEach public void setUp() { this.taskRepository = new SimpleTaskRepository(new TaskExecutionDaoFactoryBean()); } @@ -91,13 +92,15 @@ public class SimpleTaskRepositoryMapTests { expectedTaskExecution.getExecutionId())); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidExecutionIdForExternalExecutionIdUpdate() { TaskExecution expectedTaskExecution = TaskExecutionCreator .createAndStoreTaskExecutionNoParams(this.taskRepository); expectedTaskExecution.setExternalExecutionId(null); - this.taskRepository.updateExternalExecutionId(-1, - expectedTaskExecution.getExternalExecutionId()); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + this.taskRepository.updateExternalExecutionId(-1, + expectedTaskExecution.getExternalExecutionId()); + }); } @Test @@ -183,13 +186,15 @@ public class SimpleTaskRepositoryMapTests { return taskMap.get(taskExecutionId); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCreateTaskExecutionNullEndTime() { TaskExecution expectedTaskExecution = TaskExecutionCreator .createAndStoreTaskExecutionNoParams(this.taskRepository); expectedTaskExecution.setExitCode(-1); - TaskExecutionCreator.completeExecution(this.taskRepository, - expectedTaskExecution); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + TaskExecutionCreator.completeExecution(this.taskRepository, + expectedTaskExecution); + }); } } diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskDatabaseInitializerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskDatabaseInitializerTests.java index b7d468cc..3eb53b37 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskDatabaseInitializerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskDatabaseInitializerTests.java @@ -18,10 +18,8 @@ package org.springframework.cloud.task.repository.support; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; @@ -34,6 +32,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.JdbcTemplate; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.mock; /** @@ -43,15 +42,9 @@ import static org.mockito.Mockito.mock; */ public class TaskDatabaseInitializerTests { - /** - * Establishes that a Exception is not expected. - */ - @Rule - public ExpectedException expected = ExpectedException.none(); - private AnnotationConfigApplicationContext context; - @After + @AfterEach public void close() { if (this.context != null) { this.context.close(); @@ -91,7 +84,7 @@ public class TaskDatabaseInitializerTests { .isEqualTo(0); } - @Test(expected = BeanCreationException.class) + @Test public void testMultipleDataSourcesContext() { this.context = new AnnotationConfigApplicationContext(); this.context.register(SimpleTaskAutoConfiguration.class, @@ -99,7 +92,9 @@ public class TaskDatabaseInitializerTests { PropertyPlaceholderAutoConfiguration.class); DataSource dataSource = mock(DataSource.class); this.context.getBeanFactory().registerSingleton("mockDataSource", dataSource); - this.context.refresh(); + assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> { + this.context.refresh(); + }); } @Configuration diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBeanTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBeanTests.java index 2b5bf0dc..9ccca16a 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBeanTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBeanTests.java @@ -18,8 +18,8 @@ package org.springframework.cloud.task.repository.support; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao; import org.springframework.cloud.task.repository.dao.MapTaskExecutionDao; @@ -33,6 +33,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Michael Minella @@ -41,7 +42,7 @@ public class TaskExecutionDaoFactoryBeanTests { private ConfigurableApplicationContext context; - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); @@ -59,9 +60,11 @@ public class TaskExecutionDaoFactoryBeanTests { assertThat(new TaskExecutionDaoFactoryBean().isSingleton()).isTrue(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorValidation() { - new TaskExecutionDaoFactoryBean(null); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + new TaskExecutionDaoFactoryBean(null); + }); } @Test diff --git a/spring-cloud-task-integration-tests/pom.xml b/spring-cloud-task-integration-tests/pom.xml index 7bcc4195..355158a3 100644 --- a/spring-cloud-task-integration-tests/pom.xml +++ b/spring-cloud-task-integration-tests/pom.xml @@ -12,6 +12,12 @@ org.springframework.cloud spring-cloud-task-integration-tests + + 1.9.1 + 1.12.5 + 1.0.8 + + @@ -95,6 +101,24 @@ spring-integration-jdbc test + + org.testcontainers + testcontainers + ${test.containers.version} + test + + + org.testcontainers + rabbitmq + ${test.rabbit.containers.version} + test + + + org.rnorth.duct-tape + duct-tape + ${test.ducttape.version} + test + diff --git a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/executionid/TaskStartTests.java b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/executionid/TaskStartTests.java index d930d1cf..e6df7247 100644 --- a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/executionid/TaskStartTests.java +++ b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/executionid/TaskStartTests.java @@ -28,10 +28,10 @@ import java.util.UUID; import javax.sql.DataSource; import org.h2.tools.Server; -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.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -58,12 +58,13 @@ import org.springframework.jdbc.core.simple.SimpleJdbcInsert; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.init.DataSourceInitializer; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.SocketUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = { TaskStartTests.TaskLauncherConfiguration.class }) public class TaskStartTests { @@ -102,7 +103,7 @@ public class TaskStartTests { private ConfigurableApplicationContext applicationContext; - @After + @AfterEach public void tearDown() { if (this.applicationContext != null && this.applicationContext.isActive()) { this.applicationContext.close(); @@ -118,7 +119,7 @@ public class TaskStartTests { this.taskRepository = new SimpleTaskRepository(factoryBean); } - @Before + @BeforeEach public void setup() { this.properties = new HashMap<>(); this.properties.put("spring.datasource.url", DATASOURCE_URL); @@ -196,18 +197,22 @@ public class TaskStartTests { .isEqualTo("batchEvents"); } - @Test(expected = ApplicationContextException.class) + @Test public void testWithNoTaskExecution() throws Exception { - this.applicationContext = getTaskApplication(55).run(new String[0]); + assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> { + this.applicationContext = getTaskApplication(55).run(new String[0]); + }); } - @Test(expected = ApplicationContextException.class) + @Test public void testCompletedTaskExecution() throws Exception { this.taskRepository.createTaskExecution(); assertThat(this.taskExplorer.getTaskExecutionCount()) .as("Only one row is expected").isEqualTo(1); this.taskRepository.completeTaskExecution(1, 0, new Date(), ""); - this.applicationContext = getTaskApplication(1).run(new String[0]); + assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> { + this.applicationContext = getTaskApplication(1).run(new String[0]); + }); } @Test diff --git a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/initializer/TaskInitializerTests.java b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/initializer/TaskInitializerTests.java index 4005e760..bb466028 100644 --- a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/initializer/TaskInitializerTests.java +++ b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/initializer/TaskInitializerTests.java @@ -23,10 +23,10 @@ import java.sql.SQLException; import javax.sql.DataSource; import org.h2.tools.Server; -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.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -44,12 +44,13 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.SocketUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = { TaskInitializerTests.TaskLauncherConfiguration.class }) public class TaskInitializerTests { @@ -84,7 +85,7 @@ public class TaskInitializerTests { private ConfigurableApplicationContext applicationContext; - @After + @AfterEach public void tearDown() { if (this.applicationContext != null && this.applicationContext.isActive()) { this.applicationContext.close(); @@ -99,7 +100,7 @@ public class TaskInitializerTests { this.taskExplorer = new SimpleTaskExplorer(factoryBean); } - @Before + @BeforeEach public void setup() { JdbcTemplate template = new JdbcTemplate(this.dataSource); @@ -120,11 +121,13 @@ public class TaskInitializerTests { template.execute("DROP SEQUENCE IF EXISTS TASK_SEQ"); } - @Test(expected = ApplicationContextException.class) + @Test public void testNotInitialized() throws Exception { SpringApplication myapp = new SpringApplication(TaskStartApplication.class); String[] properties = { "--spring.cloud.task.initialize-enabled=false" }; - this.applicationContext = myapp.run(properties); + assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> { + this.applicationContext = myapp.run(properties); + }); } @Test @@ -143,11 +146,13 @@ public class TaskInitializerTests { .as("return code should be 0").isEqualTo(0); } - @Test(expected = ApplicationContextException.class) + @Test public void testNotInitializedOriginalProperty() throws Exception { SpringApplication myapp = new SpringApplication(TaskStartApplication.class); String[] properties = { "--spring.cloud.task.initialize.enable=false" }; - this.applicationContext = myapp.run(properties); + assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> { + this.applicationContext = myapp.run(properties); + }); } @Test diff --git a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java index 28ffa0db..1427aa20 100644 --- a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java +++ b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java @@ -25,17 +25,16 @@ import java.util.Map; import javax.sql.DataSource; import org.h2.tools.Server; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.testcontainers.containers.GenericContainer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.deployer.spi.local.LocalDeployerProperties; import org.springframework.cloud.deployer.spi.local.LocalTaskLauncher; import org.springframework.cloud.deployer.spi.task.TaskLauncher; -import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport; import org.springframework.cloud.stream.messaging.Sink; import org.springframework.cloud.task.launcher.app.TaskLauncherSinkApplication; import org.springframework.cloud.task.repository.TaskExecution; @@ -52,12 +51,12 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.init.DataSourceInitializer; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.SocketUtils; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest( classes = { TaskLauncherSinkApplication.class, TaskLauncherSinkTests.TaskLauncherConfiguration.class }, @@ -82,15 +81,17 @@ public class TaskLauncherSinkTests { private final static String TASK_NAME = "TASK_LAUNCHER_SINK_TEST"; - @ClassRule - public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport(); - private static int randomPort; static { randomPort = SocketUtils.findAvailableTcpPort(); DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort + "/mem:dataflow;DB_CLOSE_DELAY=-1;" + "DB_CLOSE_ON_EXIT=FALSE"; + GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3") + .withExposedPorts(5672); + rabbitmq.start(); + final Integer mappedPort = rabbitmq.getMappedPort(5672); + System.setProperty("spring.rabbitmq.test.port", mappedPort.toString()); } @Autowired @@ -109,7 +110,7 @@ public class TaskLauncherSinkTests { new TaskExecutionDaoFactoryBean(dataSource)); } - @Before + @BeforeEach public void setup() { this.properties = new HashMap<>(); this.properties.put("spring.datasource.url", DATASOURCE_URL); diff --git a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/BatchExecutionEventTests.java b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/BatchExecutionEventTests.java index a63c3908..d6e6fe47 100644 --- a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/BatchExecutionEventTests.java +++ b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/BatchExecutionEventTests.java @@ -23,16 +23,15 @@ import java.util.concurrent.TimeUnit; import configuration.JobConfiguration; import configuration.JobSkipConfiguration; import org.assertj.core.api.Assertions; -import org.junit.After; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; -import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport; import org.springframework.cloud.stream.messaging.Sink; import org.springframework.cloud.task.batch.listener.BatchEventAutoConfiguration; import org.springframework.cloud.task.batch.listener.support.JobExecutionEvent; @@ -50,8 +49,13 @@ public class BatchExecutionEventTests { private static final String TASK_NAME = "jobEventTest"; - @ClassRule - public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport(); + static { + GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3") + .withExposedPorts(5672); + rabbitmq.start(); + final Integer mappedPort = rabbitmq.getMappedPort(5672); + System.setProperty("spring.rabbitmq.test.port", mappedPort.toString()); + } // Count for two job execution events per job static CountDownLatch jobExecutionLatch = new CountDownLatch(2); @@ -80,7 +84,7 @@ public class BatchExecutionEventTests { private ConfigurableApplicationContext applicationContext; - @After + @AfterEach public void tearDown() { if (this.applicationContext != null && this.applicationContext.isActive()) { this.applicationContext.close(); diff --git a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java index c5bffbac..0eff023e 100644 --- a/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java +++ b/spring-cloud-task-integration-tests/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java @@ -20,9 +20,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.assertj.core.api.Assertions; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.testcontainers.containers.GenericContainer; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -33,7 +33,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; import org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration; -import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport; import org.springframework.cloud.stream.config.BindingServiceConfiguration; import org.springframework.cloud.stream.messaging.Sink; import org.springframework.cloud.task.configuration.EnableTask; @@ -42,7 +41,7 @@ import org.springframework.cloud.task.repository.TaskExecution; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -50,14 +49,19 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Michael Minella * @author Ilayaperumal Gopinathan */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = { TaskEventTests.ListenerBinding.class }) public class TaskEventTests { private static final String TASK_NAME = "taskEventTest"; - @ClassRule - public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport(); + static { + GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3") + .withExposedPorts(5672); + rabbitmq.start(); + final Integer mappedPort = rabbitmq.getMappedPort(5672); + System.setProperty("spring.rabbitmq.test.port", mappedPort.toString()); + } // Count for two task execution events per task static CountDownLatch latch = new CountDownLatch(2); diff --git a/spring-cloud-task-samples/batch-events/pom.xml b/spring-cloud-task-samples/batch-events/pom.xml index b4b23de4..4807105c 100644 --- a/spring-cloud-task-samples/batch-events/pom.xml +++ b/spring-cloud-task-samples/batch-events/pom.xml @@ -20,6 +20,9 @@ UTF-8 1.8 + 1.9.1 + 1.12.5 + 1.0.8 @@ -75,6 +78,24 @@ org.hsqldb hsqldb + + org.testcontainers + testcontainers + ${test.containers.version} + test + + + org.testcontainers + rabbitmq + ${test.rabbit.containers.version} + test + + + org.rnorth.duct-tape + duct-tape + ${test.ducttape.version} + test + diff --git a/spring-cloud-task-samples/batch-events/src/test/java/io/spring/cloud/BatchEventsApplicationTests.java b/spring-cloud-task-samples/batch-events/src/test/java/io/spring/cloud/BatchEventsApplicationTests.java index 830d5a1d..5f0a38db 100644 --- a/spring-cloud-task-samples/batch-events/src/test/java/io/spring/cloud/BatchEventsApplicationTests.java +++ b/spring-cloud-task-samples/batch-events/src/test/java/io/spring/cloud/BatchEventsApplicationTests.java @@ -20,13 +20,12 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.assertj.core.api.BDDAssertions; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; import org.springframework.boot.SpringApplication; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; -import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport; import org.springframework.cloud.stream.messaging.Sink; import org.springframework.cloud.task.batch.listener.support.JobExecutionEvent; import org.springframework.context.annotation.Configuration; @@ -36,12 +35,20 @@ import static org.assertj.core.api.Assertions.assertThat; public class BatchEventsApplicationTests { - @ClassRule - public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport(); + static { + GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3") + .withExposedPorts(5672); + rabbitmq.start(); + final Integer mappedPort = rabbitmq.getMappedPort(5672); + System.setProperty("spring.rabbitmq.test.port", mappedPort.toString()); + rabbitPort = mappedPort.toString(); + } // Count for two job execution events per task static CountDownLatch jobExecutionLatch = new CountDownLatch(2); + private static String rabbitPort; + @Test public void testExecution() throws Exception { SpringApplication @@ -49,7 +56,8 @@ public class BatchEventsApplicationTests { SpringApplication.run(BatchEventsApplication.class, "--server.port=0", "--spring.cloud.stream.bindings.output.producer.requiredGroups=testgroup", "--spring.jmx.default-domain=fakedomain", - "--spring.main.webEnvironment=false"); + "--spring.main.webEnvironment=false", + "--spring.rabbitmq.port=" + rabbitPort); assertThat(jobExecutionLatch.await(60, TimeUnit.SECONDS)) .as("The latch did not count down to zero before timeout").isTrue(); } diff --git a/spring-cloud-task-samples/batch-job/src/test/java/io/spring/BatchJobApplicationTests.java b/spring-cloud-task-samples/batch-job/src/test/java/io/spring/BatchJobApplicationTests.java index 2e9ff779..9e1c3f8a 100644 --- a/spring-cloud-task-samples/batch-job/src/test/java/io/spring/BatchJobApplicationTests.java +++ b/spring-cloud-task-samples/batch-job/src/test/java/io/spring/BatchJobApplicationTests.java @@ -19,11 +19,12 @@ package io.spring; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import static junit.framework.TestCase.assertTrue; @@ -34,13 +35,12 @@ import static org.junit.Assert.assertEquals; * * @author Michael Minella */ +@ExtendWith(OutputCaptureExtension.class) public class BatchJobApplicationTests { - @Rule - public OutputCaptureRule outputCapture = new OutputCaptureRule(); @Test - public void testBatchJobApp() throws Exception { + public void testBatchJobApp(CapturedOutput capturedOutput) throws Exception { final String JOB_RUN_MESSAGE = " was run"; final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId="; final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId="; @@ -49,7 +49,7 @@ public class BatchJobApplicationTests { SpringApplication.run(BatchJobApplication.class); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertTrue("Unable to find the timestamp: " + output, output.contains(JOB_RUN_MESSAGE)); assertTrue("Test results do not show create task message: " + output, diff --git a/spring-cloud-task-samples/jpa-sample/src/test/java/io/spring/JpaApplicationTests.java b/spring-cloud-task-samples/jpa-sample/src/test/java/io/spring/JpaApplicationTests.java index e01f36cf..0ef95846 100644 --- a/spring-cloud-task-samples/jpa-sample/src/test/java/io/spring/JpaApplicationTests.java +++ b/spring-cloud-task-samples/jpa-sample/src/test/java/io/spring/JpaApplicationTests.java @@ -22,13 +22,15 @@ import java.util.Map; import javax.sql.DataSource; import org.h2.tools.Server; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; @@ -41,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Glenn Renfro */ +@ExtendWith(OutputCaptureExtension.class) public class JpaApplicationTests { private final static String DATASOURCE_URL; @@ -59,13 +62,11 @@ public class JpaApplicationTests { + "DB_CLOSE_ON_EXIT=FALSE"; } - @Rule - public OutputCaptureRule outputCapture = new OutputCaptureRule(); private ConfigurableApplicationContext context; private DataSource dataSource; private Server server; - @Before + @BeforeEach public void setup() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME); @@ -84,7 +85,7 @@ public class JpaApplicationTests { } } - @After + @AfterEach public void tearDown() { if (this.context != null && this.context.isActive()) { this.context.close(); @@ -93,14 +94,14 @@ public class JpaApplicationTests { } @Test - public void testBatchJobApp() { + public void testBatchJobApp(CapturedOutput capturedOutput) { final String INSERT_MESSAGE = "Hibernate: insert into task_run_output ("; this.context = SpringApplication .run(JpaApplication.class, "--spring.datasource.url=" + DATASOURCE_URL, "--spring.datasource.username=" + DATASOURCE_USER_NAME, "--spring.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME, "--spring.jpa.database-platform=org.hibernate.dialect.H2Dialect"); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output .contains(INSERT_MESSAGE)).as("Unable to find the insert message: " + output) .isTrue(); diff --git a/spring-cloud-task-samples/multiple-datasources/src/test/java/io/spring/MultiDataSourcesApplicationTests.java b/spring-cloud-task-samples/multiple-datasources/src/test/java/io/spring/MultiDataSourcesApplicationTests.java index 022b9424..d71dfb07 100644 --- a/spring-cloud-task-samples/multiple-datasources/src/test/java/io/spring/MultiDataSourcesApplicationTests.java +++ b/spring-cloud-task-samples/multiple-datasources/src/test/java/io/spring/MultiDataSourcesApplicationTests.java @@ -16,28 +16,28 @@ package io.spring; -import org.junit.Rule; -import org.junit.Test; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import static org.assertj.core.api.Assertions.assertThat; /** * @author Michael Minella */ +@ExtendWith(OutputCaptureExtension.class) public class MultiDataSourcesApplicationTests { - @Rule - public OutputCaptureRule outputCapture = new OutputCaptureRule(); - @Test - public void testTimeStampApp() throws Exception { + public void testTimeStampApp(CapturedOutput capturedOutput) throws Exception { SpringApplication.run(MultipleDataSourcesApplication.class, new String[0]); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output.contains("There are 2 DataSources within this application")) .as("Unable to find CommandLineRunner output: " + output).isTrue(); diff --git a/spring-cloud-task-samples/partitioned-batch-job/src/test/java/org/springframework/cloud/task/partitioner/TaskPartitionerTests.java b/spring-cloud-task-samples/partitioned-batch-job/src/test/java/org/springframework/cloud/task/partitioner/TaskPartitionerTests.java index 00575850..233516df 100644 --- a/spring-cloud-task-samples/partitioned-batch-job/src/test/java/org/springframework/cloud/task/partitioner/TaskPartitionerTests.java +++ b/spring-cloud-task-samples/partitioned-batch-job/src/test/java/org/springframework/cloud/task/partitioner/TaskPartitionerTests.java @@ -23,9 +23,9 @@ import javax.sql.DataSource; import io.spring.PartitionedBatchJobApplication; import org.h2.tools.Server; -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.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -40,12 +40,12 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.SocketUtils; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = {TaskPartitionerTests.TaskLauncherConfiguration.class}) public class TaskPartitionerTests { @@ -70,7 +70,7 @@ public class TaskPartitionerTests { this.taskExplorer = new SimpleTaskExplorer(new TaskExecutionDaoFactoryBean(dataSource)); } - @Before + @BeforeEach public void setup() { JdbcTemplate template = new JdbcTemplate(this.dataSource); template.execute("DROP TABLE IF EXISTS TASK_TASK_BATCH"); diff --git a/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java b/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java index 7b7b0f06..7ff7acbe 100644 --- a/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java +++ b/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java @@ -21,8 +21,9 @@ import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -31,14 +32,14 @@ import org.springframework.cloud.stream.test.binder.MessageCollector; import org.springframework.cloud.task.launcher.TaskLaunchRequest; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; /** * @author Glenn Renfro */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = TaskProcessorApplication.class) public class TaskProcessorApplicationTests { diff --git a/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java b/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java index eddcd595..1716a880 100644 --- a/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java +++ b/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java @@ -20,8 +20,9 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.ArgumentCaptor; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +33,7 @@ import org.springframework.cloud.stream.messaging.Sink; import org.springframework.cloud.task.launcher.TaskLaunchRequest; import org.springframework.context.ApplicationContext; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; @@ -40,7 +41,7 @@ import static org.mockito.Mockito.verify; /** * @author Glenn Renfro */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = TaskSinkApplication.class) public class TaskSinkApplicationTests { diff --git a/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TaskApplicationTests.java b/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TaskApplicationTests.java index 7d947fdf..740540d5 100644 --- a/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TaskApplicationTests.java +++ b/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TaskApplicationTests.java @@ -19,11 +19,12 @@ package org.springframework.cloud.task.timestamp; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -32,13 +33,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Glenn Renfro */ +@ExtendWith(OutputCaptureExtension.class) public class TaskApplicationTests { - @Rule - public OutputCaptureRule outputCapture = new OutputCaptureRule(); @Test - public void testTimeStampApp() throws Exception { + public void testTimeStampApp(CapturedOutput capturedOutput) throws Exception { final String TEST_DATE_DOTS = "......."; final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId="; final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId="; @@ -47,7 +47,7 @@ public class TaskApplicationTests { SpringApplication.run(TaskApplication.class, args); - String output = this.outputCapture.toString(); + String output = capturedOutput.toString(); assertThat(output.contains(TEST_DATE_DOTS)) .as("Unable to find the timestamp: " + output).isTrue(); assertThat(output.contains(CREATE_TASK_MESSAGE)) diff --git a/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TimestampTaskPropertiesTests.java b/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TimestampTaskPropertiesTests.java index 1da85db3..8e61501c 100644 --- a/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TimestampTaskPropertiesTests.java +++ b/spring-cloud-task-samples/timestamp/src/test/java/org/springframework/cloud/task/timestamp/TimestampTaskPropertiesTests.java @@ -16,7 +16,8 @@ package org.springframework.cloud.task.timestamp; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.TestPropertyValues; @@ -24,13 +25,14 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Glenn Renfro */ public class TimestampTaskPropertiesTests { - @Test(expected = IllegalArgumentException.class) + @Test public void testEmptyFormat() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); TestPropertyValues testPropertyValues = TestPropertyValues.of("format:"); @@ -39,7 +41,9 @@ public class TimestampTaskPropertiesTests { context.refresh(); TimestampTaskProperties properties = context .getBean(TimestampTaskProperties.class); - properties.getFormat(); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + properties.getFormat(); + }); } @Test diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/EventListenerTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/EventListenerTests.java index 462632e6..e489fbfb 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/EventListenerTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/EventListenerTests.java @@ -20,8 +20,8 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -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.JobExecution; import org.springframework.batch.core.JobInstance; @@ -59,7 +59,7 @@ public class EventListenerTests { private EventEmittingChunkListener eventEmittingChunkListener; - @Before + @BeforeEach public void beforeTests() { this.queueChannel = new QueueChannel(1); this.eventEmittingSkipListener = new EventEmittingSkipListener(this.queueChannel); diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobExecutionEventTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobExecutionEventTests.java index 21b8d8a9..ffbe0935 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobExecutionEventTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobExecutionEventTests.java @@ -23,8 +23,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -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.BatchStatus; import org.springframework.batch.core.JobExecution; @@ -75,7 +75,7 @@ public class JobExecutionEventTests { private JobInstance jobInstance; - @Before + @BeforeEach public void setup() { this.jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME); this.jobParameters = new JobParameters(); diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java index 531a3c91..c5642792 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.task.batch.listener; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.task.batch.listener.support.JobInstanceEvent; diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParameterEventTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParameterEventTests.java index 33c89994..8044b96a 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParameterEventTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParameterEventTests.java @@ -18,7 +18,7 @@ package org.springframework.cloud.task.batch.listener; import java.util.Date; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.JobParameter; import org.springframework.cloud.task.batch.listener.support.JobParameterEvent; @@ -73,16 +73,6 @@ public class JobParameterEventTests { assertTrue(jobParameterEvent.equals(anotherJobParameterEvent)); } - @Test(expected = NullPointerException.class) - public void testInvalidHashCode() { - JobParameterEvent jobParameterEvent = new JobParameterEvent(); - assertThat(jobParameterEvent.hashCode()).isNull(); - final String EXPECTED_VALUE = "FOO"; - JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true); - jobParameterEvent = new JobParameterEvent(jobParameter); - assertThat(jobParameterEvent.hashCode()).isNotNull(); - } - @Test public void testValidHashCode() { final String EXPECTED_VALUE = "FOO"; diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParametersEventTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParametersEventTests.java index 3b9a4528..df0f9f75 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParametersEventTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobParametersEventTests.java @@ -21,7 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.JobParameter; import org.springframework.cloud.task.batch.listener.support.JobParametersEvent; diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/StepExecutionEventTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/StepExecutionEventTests.java index b908e152..27441dfe 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/StepExecutionEventTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/StepExecutionEventTests.java @@ -18,7 +18,7 @@ package org.springframework.cloud.task.batch.listener; import java.util.Date; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchEventListenerBeanPostProcessorTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchEventListenerBeanPostProcessorTests.java index 10649c4a..2b55f572 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchEventListenerBeanPostProcessorTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchEventListenerBeanPostProcessorTests.java @@ -16,9 +16,9 @@ package org.springframework.cloud.task.batch.listener; -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.junit.jupiter.api.extension.ExtendWith; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.ItemProcessListener; @@ -38,7 +38,7 @@ import org.springframework.cloud.task.batch.listener.support.TaskBatchEventListe import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -46,7 +46,7 @@ import static org.mockito.Mockito.when; /** * @author Glenn Renfro */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest public class TaskBatchEventListenerBeanPostProcessorTests { @@ -80,7 +80,7 @@ public class TaskBatchEventListenerBeanPostProcessorTests { @Autowired private GenericApplicationContext context; - @Before + @BeforeEach public void setupMock() { when(this.taskletStep.getTasklet()).thenReturn( new ChunkOrientedTasklet(this.chunkProvider, this.chunkProcessor)); diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java index df759e48..4d428db8 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java @@ -16,8 +16,8 @@ package org.springframework.cloud.task.launcher; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -27,7 +27,7 @@ import org.springframework.cloud.deployer.spi.task.TaskLauncher; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Glenn Renfro */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = { TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class }) public class TaskLaunchConfigurationExistingTests { diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java index 56b99b02..c9897ea5 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java index f41ce20f..3f2b28c5 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java @@ -22,9 +22,9 @@ import java.util.List; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; -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.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -34,11 +34,11 @@ import org.springframework.cloud.task.launcher.app.TaskLauncherSinkApplication; import org.springframework.cloud.task.launcher.configuration.TaskConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = { TaskLauncherSinkApplication.class, TaskConfiguration.class }) public class TaskLauncherSinkTests { @@ -66,7 +66,7 @@ public class TaskLauncherSinkTests { @Autowired private Sink sink; - @Before + @BeforeEach public void setup() { this.properties = new HashMap<>(); this.properties.put("server.port", "0"); diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java index 0a75bfe2..6133df9f 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/listener/TaskEventTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.task.listener; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;