diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactory.java index 3074cbf5a..02b0c30ef 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactory.java @@ -56,7 +56,7 @@ public class DefaultFieldSetFactory implements FieldSetFactory { fieldSet.setDateFormat(dateFormat); } if (numberFormat!=null) { - fieldSet.setDateFormat(dateFormat); + fieldSet.setNumberFormat(numberFormat); } return fieldSet; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactoryTests.java new file mode 100644 index 000000000..c959adbed --- /dev/null +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactoryTests.java @@ -0,0 +1,61 @@ +/* + * Copyright 2006-2010 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.item.file.transform; + +import static org.junit.Assert.assertEquals; + +import java.text.NumberFormat; +import java.text.SimpleDateFormat; +import java.util.Locale; + +import org.junit.Test; + +/** + * @author Dave Syer + * + */ +public class DefaultFieldSetFactoryTests { + + private DefaultFieldSetFactory factory = new DefaultFieldSetFactory(); + + @Test + public void testVanillaFieldSet() throws Exception { + FieldSet fieldSet = factory.create(new String[] {"foo", "bar"} ); + assertEquals("foo", fieldSet.readString(0)); + } + + @Test + public void testVanillaFieldSetWithNames() throws Exception { + FieldSet fieldSet = factory.create(new String[] {"1", "bar"}, new String[] {"foo", "bar"} ); + assertEquals(1, fieldSet.readInt("foo")); + } + + @Test + public void testFieldSetWithDateFormat() throws Exception { + SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); + factory.setDateFormat(format); + FieldSet fieldSet = factory.create(new String[] {"1999/12/18", "bar"} ); + assertEquals(format.parse("1999/12/18"), fieldSet.readDate(0)); + } + + @Test + public void testFieldSetWithNumberFormat() throws Exception { + factory.setNumberFormat(NumberFormat.getNumberInstance(Locale.GERMAN)); + FieldSet fieldSet = factory.create(new String[] {"19.991.218", "bar"} ); + assertEquals(19991218, fieldSet.readInt(0)); + } + +}