Updated all Junit tests to 5.x

resolves TASK-675
This commit is contained in:
Glenn Renfro
2020-06-17 16:38:20 -04:00
committed by Michael Minella
parent f3bbc37293
commit 59c9adf047
74 changed files with 617 additions and 534 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();

View File

@@ -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(

View File

@@ -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

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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;