Fix ClassCastException in RunIdIncrementer

Before this commit, the RunIdIncrementer was failing
with a ClassCastException if the run.id parameter is
not passed as a Long.

This commit makes the RunIdIncrementer more liberal
in what it accepts by trying to parse the parameter
to a Long.

Resolves #3799
This commit is contained in:
Mahmoud Ben Hassine
2020-11-09 11:54:22 +01:00
parent 9d2e6c6d2a
commit f2c1296e7f
2 changed files with 46 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013 the original author or authors.
* Copyright 2006-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import org.springframework.batch.core.JobParametersBuilder;
/**
* @author Dave Syer
* @author Michael Minella
* @author Mahmoud Ben Hassine
*
*/
public class RunIdIncrementerTests {
@@ -51,4 +52,25 @@ public class RunIdIncrementerTests {
assertEquals(1, next.getLong("foo").intValue());
}
@Test
public void testGetNextWhenRunIdIsString() {
// given
JobParameters parameters = new JobParametersBuilder()
.addString("run.id", "5")
.toJobParameters();
// when
JobParameters next = this.incrementer.getNext(parameters);
// then
assertEquals(Long.valueOf(6), next.getLong("run.id"));
}
@Test(expected = IllegalArgumentException.class)
public void testGetNextWhenRunIdIsInvalidString() {
this.incrementer.getNext(new JobParametersBuilder()
.addString("run.id", "foo")
.toJobParameters());
}
}