Skip to content

Commit cfbe884

Browse files
committed
Adapt contribution #4043
This commit adapts the code contributed in #4043 to be Java 8-compatible with the v4 branch
1 parent dab89cc commit cfbe884

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ allprojects {
7171
derbyVersion = '10.14.2.0'
7272
groovyVersion = '2.5.14'
7373
hamcrestVersion = '2.2'
74-
h2databaseVersion = '1.4.200'
74+
h2databaseVersion = '2.0.206'
7575
hibernateVersion = '5.4.32.Final'
7676
hibernateValidatorVersion = '6.1.7.Final'
7777
javaxElVersion = '3.0.0'
@@ -425,6 +425,7 @@ project('spring-batch-core-tests') {
425425
compile "org.springframework:spring-aop:$springVersion"
426426

427427
testCompile "org.hsqldb:hsqldb:$hsqldbVersion"
428+
testCompile "com.h2database:h2:$h2databaseVersion"
428429
testCompile "commons-io:commons-io:$commonsIoVersion"
429430
testCompile "org.apache.derby:derby:$derbyVersion"
430431
testCompile "junit:junit:${junitVersion}"
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Arrays;
1919
import java.util.List;
2020
import java.util.UUID;
21+
import java.util.stream.Collectors;
2122

2223
import javax.sql.DataSource;
2324

@@ -29,6 +30,7 @@
2930

3031
import org.springframework.batch.core.ExitStatus;
3132
import org.springframework.batch.core.Job;
33+
import org.springframework.batch.core.JobExecution;
3234
import org.springframework.batch.core.JobParameters;
3335
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
3436
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
@@ -39,13 +41,15 @@
3941
import org.springframework.context.annotation.Bean;
4042
import org.springframework.context.annotation.Configuration;
4143
import org.springframework.core.io.DefaultResourceLoader;
44+
import org.springframework.core.io.Resource;
4245
import org.springframework.jdbc.core.JdbcTemplate;
4346
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
4447
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
4548
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
4649

4750
/**
4851
* @author Henning Pöttker
52+
* @author Mahmoud Ben Hassine
4953
*/
5054
@RunWith(Parameterized.class)
5155
public class H2CompatibilityModeJobRepositoryIntegrationTests {
@@ -58,31 +62,31 @@ public H2CompatibilityModeJobRepositoryIntegrationTests(String compatibilityMode
5862

5963
@Test
6064
public void testJobExecution() throws Exception {
61-
var context = new AnnotationConfigApplicationContext();
65+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
6266
context.register(TestConfiguration.class);
6367
context.registerBean(DataSource.class, this::buildDataSource);
6468
context.refresh();
65-
var jobLauncher = context.getBean(JobLauncher.class);
66-
var job = context.getBean(Job.class);
69+
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
70+
Job job = context.getBean(Job.class);
6771

68-
var jobExecution = jobLauncher.run(job, new JobParameters());
72+
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
6973

7074
Assert.assertNotNull(jobExecution);
7175
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
7276

73-
var jdbcTemplate = new JdbcTemplate(context.getBean(DataSource.class));
77+
JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getBean(DataSource.class));
7478
jdbcTemplate.execute("SHUTDOWN");
7579
}
7680

7781
private DataSource buildDataSource() {
78-
var connectionUrl = String.format(
82+
String connectionUrl = String.format(
7983
"jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false;MODE=%s",
8084
UUID.randomUUID(),
8185
this.compatibilityMode
8286
);
83-
var dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", "");
84-
var populator = new ResourceDatabasePopulator();
85-
var resource = new DefaultResourceLoader()
87+
DataSource dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", "");
88+
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
89+
Resource resource = new DefaultResourceLoader()
8690
.getResource("/org/springframework/batch/core/schema-h2.sql");
8791
populator.addScript(resource);
8892
DatabasePopulatorUtils.execute(populator, dataSource);
@@ -106,6 +110,6 @@ Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
106110
public static List<Object[]> data() throws Exception {
107111
return Arrays.stream(org.h2.engine.Mode.ModeEnum.values())
108112
.map(mode -> new Object[]{mode.toString()})
109-
.toList();
113+
.collect(Collectors.toList());
110114
}
111115
}

0 commit comments

Comments
 (0)