BATCH-1723: Updated JobParameters to return wrapper classes

This commit is contained in:
Michael Minella
2013-03-05 10:23:49 -06:00
parent e1c038b6ac
commit 12317a0e0c
6 changed files with 51 additions and 53 deletions

View File

@@ -1,6 +1,3 @@
/**
*
*/
package org.springframework.batch.core;
import static org.junit.Assert.assertEquals;
@@ -14,6 +11,7 @@ import org.junit.Test;
/**
* @author Lucas Ward
* @author Michael Minella
*
*/
public class JobParametersBuilderTests {
@@ -29,7 +27,7 @@ public class JobParametersBuilderTests {
parametersBuilder.addString("STRING", "string value", false);
JobParameters parameters = parametersBuilder.toJobParameters();
assertEquals(date, parameters.getDate("SCHEDULE_DATE"));
assertEquals(1L, parameters.getLong("LONG"));
assertEquals(1L, parameters.getLong("LONG").longValue());
assertEquals("string value", parameters.getString("STRING"));
assertFalse(parameters.getParameters().get("SCHEDULE_DATE").isIdentifying());
assertFalse(parameters.getParameters().get("LONG").isIdentifying());
@@ -43,7 +41,7 @@ public class JobParametersBuilderTests {
parametersBuilder.addString("STRING", "string value");
JobParameters parameters = parametersBuilder.toJobParameters();
assertEquals(date, parameters.getDate("SCHEDULE_DATE"));
assertEquals(1L, parameters.getLong("LONG"));
assertEquals(1L, parameters.getLong("LONG").longValue());
assertEquals("string value", parameters.getString("STRING"));
}
@@ -54,7 +52,7 @@ public class JobParametersBuilderTests {
parametersBuilder.addString("STRING", null);
JobParameters parameters = parametersBuilder.toJobParameters();
assertEquals(null, parameters.getDate("SCHEDULE_DATE"));
assertEquals(0L, parameters.getLong("LONG"));
assertEquals(0L, parameters.getLong("LONG").longValue());
assertEquals(null, parameters.getString("STRING"));
}

View File

@@ -1,6 +1,3 @@
/**
*
*/
package org.springframework.batch.core;
import static org.junit.Assert.assertEquals;
@@ -21,6 +18,7 @@ import org.springframework.batch.support.SerializationUtils;
/**
* @author Lucas Ward
* @author Dave Syer
* @author Michael Minella
*
*/
public class JobParametersTests {
@@ -66,8 +64,8 @@ public class JobParametersTests {
@Test
public void testGetLong() {
assertEquals(1L, parameters.getLong("long.key1"));
assertEquals(2L, parameters.getLong("long.key2"));
assertEquals(1L, parameters.getLong("long.key1").longValue());
assertEquals(2L, parameters.getLong("long.key2").longValue());
}
@Test
@@ -91,12 +89,12 @@ public class JobParametersTests {
@Test
public void testGetEmptyLong() {
parameters = new JobParameters(Collections.singletonMap("long1", new JobParameter((Long)null, true)));
assertEquals(0L, parameters.getLong("long1"));
assertEquals(0L, parameters.getLong("long1").longValue());
}
@Test
public void testGetMissingLong() {
assertEquals(0L, parameters.getLong("missing.long1"));
assertEquals(0L, parameters.getLong("missing.long1").longValue());
}
@Test
@@ -197,7 +195,7 @@ public class JobParametersTests {
@Test
public void testLongReturns0WhenKeyDoesntExit(){
assertEquals(0L,new JobParameters().getLong("keythatdoesntexist"));
assertEquals(0L,new JobParameters().getLong("keythatdoesntexist").longValue());
}
@Test

View File

@@ -116,7 +116,7 @@ public class DefaultJobParametersConverterTests {
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
assertNotNull(props);
assertEquals("myKey", props.getString("job.key"));
assertEquals(33243243L, props.getLong("vendor.id"));
assertEquals(33243243L, props.getLong("vendor.id").longValue());
Date date = dateFormat.parse("01/23/2008");
assertEquals(date, props.getDate("schedule.date"));
}
@@ -156,7 +156,7 @@ public class DefaultJobParametersConverterTests {
factory.setNumberFormat(new DecimalFormat("#,###"));
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
assertNotNull(props);
assertEquals(1000L, props.getLong("value"));
assertEquals(1000L, props.getLong("value").longValue());
}
@Test
@@ -225,7 +225,7 @@ public class DefaultJobParametersConverterTests {
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
assertNotNull(props);
assertEquals(1.23456, props.getDouble("value"), Double.MIN_VALUE);
assertEquals(123456, props.getLong("long"));
assertEquals(123456, props.getLong("long").longValue());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2010 the original author or authors.
* Copyright 2006-2013 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.
@@ -15,7 +15,7 @@
*/
package org.springframework.batch.core.launch.support;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.batch.core.JobParameters;
@@ -23,23 +23,24 @@ import org.springframework.batch.core.JobParametersBuilder;
/**
* @author Dave Syer
* @author Michael Minella
*
*/
public class RunIdIncrementerTests {
private RunIdIncrementer incrementer = new RunIdIncrementer();
@Test
public void testGetNext() {
JobParameters next = incrementer.getNext(null);
assertEquals(1, next.getLong("run.id"));
assertEquals(2, incrementer.getNext(next).getLong("run.id"));
assertEquals(1, next.getLong("run.id").intValue());
assertEquals(2, incrementer.getNext(next).getLong("run.id").intValue());
}
@Test
public void testGetNextAppends() {
JobParameters next = incrementer.getNext(new JobParametersBuilder().addString("foo", "bar").toJobParameters());
assertEquals(1, next.getLong("run.id"));
assertEquals(1, next.getLong("run.id").intValue());
assertEquals("bar", next.getString("foo"));
}
@@ -47,7 +48,7 @@ public class RunIdIncrementerTests {
public void testGetNextNamed() {
incrementer.setKey("foo");
JobParameters next = incrementer.getNext(null);
assertEquals(1, next.getLong("foo"));
assertEquals(1, next.getLong("foo").intValue());
}
}