Skip to content

Commit 59c9adf

Browse files
cppwfsmminella
authored andcommitted
Updated all Junit tests to 5.x
resolves TASK-675
1 parent f3bbc37 commit 59c9adf

File tree

74 files changed

+617
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+617
-534
lines changed

spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemReaderAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.batch.core.Job;
2727
import org.springframework.batch.core.JobExecution;

spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/FlatFileItemWriterAutoConfigurationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import java.util.List;
2424
import java.util.Map;
2525

26-
import org.junit.After;
27-
import org.junit.Before;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
2929

3030
import org.springframework.batch.core.Job;
3131
import org.springframework.batch.core.JobExecution;
@@ -62,12 +62,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
6262

6363
private File outputFile;
6464

65-
@Before
65+
@BeforeEach
6666
public void setUp() throws Exception {
6767
this.outputFile = File.createTempFile("flatfile-config-test-output", ".tmp");
6868
}
6969

70-
@After
70+
@AfterEach
7171
public void tearDown() {
7272
this.outputFile.delete();
7373
}

spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/RangeConverterTests.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
package org.springframework.cloud.task.batch.autoconfigure;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.batch.item.file.transform.Range;
2222

2323
import static org.assertj.core.api.Assertions.assertThat;
24+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2425

2526
/**
2627
* @author Michael Minella
@@ -54,18 +55,22 @@ public void testStartAndEndValue() {
5455
assertThat(range.getMax()).isEqualTo(25);
5556
}
5657

57-
@Test(expected = NumberFormatException.class)
58+
@Test
5859
public void testIllegalValue() {
5960
RangeConverter converter = new RangeConverter();
6061

61-
converter.convert("invalid");
62+
assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> {
63+
converter.convert("invalid");
64+
});
6265
}
6366

64-
@Test(expected = IllegalArgumentException.class)
67+
@Test
6568
public void testTooManyValues() {
6669
RangeConverter converter = new RangeConverter();
6770

68-
converter.convert("1-2-3-4");
71+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
72+
converter.convert("1-2-3-4");
73+
});
6974
}
7075

7176
}

spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.batch.core.Job;
2727
import org.springframework.batch.core.JobExecution;

spring-cloud-task-batch/pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@
5555
<groupId>org.springframework.boot</groupId>
5656
<artifactId>spring-boot-test</artifactId>
5757
</dependency>
58-
<dependency>
59-
<groupId>junit</groupId>
60-
<artifactId>junit</artifactId>
61-
<scope>test</scope>
62-
</dependency>
63-
<dependency>
64-
<groupId>org.mockito</groupId>
65-
<artifactId>mockito-core</artifactId>
66-
<scope>test</scope>
67-
</dependency>
6858
<dependency>
6959
<groupId>com.h2database</groupId>
7060
<artifactId>h2</artifactId>
@@ -91,5 +81,15 @@
9181
<artifactId>spring-boot-autoconfigure-processor</artifactId>
9282
<optional>true</optional>
9383
</dependency>
84+
<dependency>
85+
<groupId>org.mockito</groupId>
86+
<artifactId>mockito-junit-jupiter</artifactId>
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.junit.jupiter</groupId>
91+
<artifactId>junit-jupiter</artifactId>
92+
<scope>test</scope>
93+
</dependency>
9494
</dependencies>
9595
</project>

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.cloud.task.batch.configuration;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
2222
import org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner;

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package org.springframework.cloud.task.batch.handler;
1818

19-
import org.junit.Before;
20-
import org.junit.Test;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.extension.ExtendWith;
2122
import org.junit.jupiter.api.function.Executable;
22-
import org.junit.runner.RunWith;
2323

2424
import org.springframework.batch.core.Job;
2525
import org.springframework.batch.core.JobExecution;
@@ -49,7 +49,7 @@
4949
import org.springframework.core.task.SyncTaskExecutor;
5050
import org.springframework.test.annotation.DirtiesContext;
5151
import org.springframework.test.context.ContextConfiguration;
52-
import org.springframework.test.context.junit4.SpringRunner;
52+
import org.springframework.test.context.junit.jupiter.SpringExtension;
5353
import org.springframework.transaction.PlatformTransactionManager;
5454

5555
import static org.assertj.core.api.Assertions.assertThat;
@@ -58,7 +58,7 @@
5858
/**
5959
* @author Glenn Renfro
6060
*/
61-
@RunWith(SpringRunner.class)
61+
@ExtendWith(SpringExtension.class)
6262
@ContextConfiguration(
6363
classes = { TaskJobLauncherCommandLineRunnerCoreTests.BatchConfiguration.class })
6464
public class TaskJobLauncherCommandLineRunnerCoreTests {
@@ -85,7 +85,7 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
8585

8686
private Step step;
8787

88-
@Before
88+
@BeforeEach
8989
public void init() {
9090
this.jobs = new JobBuilderFactory(this.jobRepository);
9191
this.steps = new StepBuilderFactory(this.jobRepository, this.transactionManager);

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import javax.sql.DataSource;
2222

2323
import org.assertj.core.api.Condition;
24-
import org.junit.After;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.Test;
2626
import org.junit.jupiter.api.function.Executable;
2727

2828
import org.springframework.batch.core.Job;
@@ -74,7 +74,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
7474

7575
private ConfigurableApplicationContext applicationContext;
7676

77-
@After
77+
@AfterEach
7878
public void tearDown() {
7979
if (this.applicationContext != null && this.applicationContext.isActive()) {
8080
this.applicationContext.close();

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import javax.sql.DataSource;
2222

23-
import org.junit.After;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.batch.core.Job;
2727
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
@@ -48,7 +48,7 @@ public class PrefixTests {
4848

4949
private ConfigurableApplicationContext applicationContext;
5050

51-
@After
51+
@AfterEach
5252
public void tearDown() {
5353
if (this.applicationContext != null && this.applicationContext.isActive()) {
5454
this.applicationContext.close();

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import javax.sql.DataSource;
2626

27-
import org.junit.After;
28-
import org.junit.Test;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.Test;
2929

3030
import org.springframework.batch.core.Job;
3131
import org.springframework.batch.core.StepContribution;
@@ -63,6 +63,7 @@
6363
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
6464

6565
import static org.assertj.core.api.Assertions.assertThat;
66+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6667

6768
/**
6869
* @author Michael Minella
@@ -74,7 +75,7 @@ public class TaskBatchExecutionListenerTests {
7475

7576
private ConfigurableApplicationContext applicationContext;
7677

77-
@After
78+
@AfterEach
7879
public void tearDown() {
7980
if (this.applicationContext != null && this.applicationContext.isActive()) {
8081
this.applicationContext.close();
@@ -87,25 +88,31 @@ public void testAutobuiltDataSource() {
8788
validateContext();
8889
}
8990

90-
@Test(expected = AssertionError.class)
91+
@Test
9192
public void testNoAutoConfigurationEnabled() {
9293
this.applicationContext = SpringApplication.run(JobConfiguration.class,
9394
"--spring.cloud.task.batch.listener.enabled=false");
94-
validateContext();
95+
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
96+
validateContext();
97+
});
9598
}
9699

97-
@Test(expected = AssertionError.class)
100+
@Test
98101
public void testNoAutoConfigurationEnable() {
99102
this.applicationContext = SpringApplication.run(JobConfiguration.class,
100103
"--spring.cloud.task.batch.listener.enable=false");
101-
validateContext();
104+
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
105+
validateContext();
106+
});
102107
}
103108

104-
@Test(expected = AssertionError.class)
109+
@Test
105110
public void testNoAutoConfigurationBothDisabled() {
106111
this.applicationContext = SpringApplication.run(JobConfiguration.class,
107112
"--spring.cloud.task.batch.listener.enable=false --spring.cloud.task.batch.listener.enabled=false");
108-
validateContext();
113+
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
114+
validateContext();
115+
});
109116
}
110117

111118
@Test
@@ -245,9 +252,11 @@ public void testBatchExecutionListenerBeanPostProcessorWithEmptyJobNames() {
245252
assertThat(bean).isEqualTo(testObject);
246253
}
247254

248-
@Test(expected = IllegalArgumentException.class)
255+
@Test
249256
public void testBatchExecutionListenerBeanPostProcessorNullJobNames() {
250-
beanPostProcessor(null);
257+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
258+
beanPostProcessor(null);
259+
});
251260
}
252261

253262
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(

0 commit comments

Comments
 (0)