diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemWriterTests.java index b9e75aa94..9ea689cf7 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemWriterTests.java @@ -1,59 +1,55 @@ -/* - * Copyright 2006-2007 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.sample.iosample.internal; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; -import org.springframework.batch.item.file.FlatFileItemWriter; -import org.springframework.batch.sample.domain.trade.Trade; - -/** - * @author Dan Garrette - * @since 2.0 - */ -public class MultiLineTradeItemWriterTests { - - private MultiLineTradeItemWriter writer; - - public MultiLineTradeItemWriterTests() { - FlatFileItemWriter delegate = new FlatFileItemWriter() { - List allItems = new ArrayList(); - - public void write(List items) throws Exception { - this.allItems.addAll(items); - } - - public List getAllItems() { - return this.allItems; - } - }; - - this.writer = new MultiLineTradeItemWriter(); - this.writer.setDelegate(delegate); - } - - @Test - public void testWrite() throws Exception { - Trade t1 = new Trade("ISIN001", 400, new BigDecimal("5.75"), "Customer1"); - Trade t2 = new Trade("ISIN002", 200, new BigDecimal("6.25"), "Customer2"); - this.writer.write(Arrays.asList(t1, t2)); - } -} +/* + * Copyright 2006-2007 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.sample.iosample.internal; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.springframework.batch.item.file.FlatFileItemWriter; +import org.springframework.batch.sample.domain.trade.Trade; + +/** + * @author Dan Garrette + * @since 2.0 + */ +public class MultiLineTradeItemWriterTests { + + private MultiLineTradeItemWriter writer; + + public MultiLineTradeItemWriterTests() { + FlatFileItemWriter delegate = new FlatFileItemWriter() { + List allItems = new ArrayList(); + + public void write(List items) throws Exception { + this.allItems.addAll(items); + } + }; + + this.writer = new MultiLineTradeItemWriter(); + this.writer.setDelegate(delegate); + } + + @Test + public void testWrite() throws Exception { + Trade t1 = new Trade("ISIN001", 400, new BigDecimal("5.75"), "Customer1"); + Trade t2 = new Trade("ISIN002", 200, new BigDecimal("6.25"), "Customer2"); + this.writer.write(Arrays.asList(t1, t2)); + } +} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapper.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapper.java index ae1e44d66..0557a112f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapper.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapper.java @@ -1,44 +1,44 @@ -/* - * Copyright 2006-2007 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.sample.iosample.internal; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.FieldSet; - -/** - * This class is used to delegate to a {@link FieldSetMapper} based on one field - * in the {@link FieldSet}. - * - * @author Dan Garrette - * @since 2.0 - */ -public class PrefixMatchingCompositeFieldSetMapper implements FieldSetMapper { - - private Map> mappers = new HashMap>(); - - public T mapFieldSet(FieldSet fieldSet) { - String prefix = fieldSet.readString("prefix"); - return this.mappers.get(prefix).mapFieldSet(fieldSet); - } - - public void setMappers(Map> mappers) { - this.mappers = mappers; - } -} +/* + * Copyright 2006-2007 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.sample.iosample.internal; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.batch.item.file.mapping.FieldSetMapper; +import org.springframework.batch.item.file.transform.FieldSet; + +/** + * This class is used to delegate to a {@link FieldSetMapper} based on one field + * in the {@link FieldSet}. + * + * @author Dan Garrette + * @since 2.0 + */ +public class PrefixMatchingCompositeFieldSetMapper implements FieldSetMapper { + + private Map> mappers = new HashMap>(); + + public T mapFieldSet(FieldSet fieldSet) { + String prefix = fieldSet.readString("prefix"); + return this.mappers.get(prefix).mapFieldSet(fieldSet); + } + + public void setMappers(Map> mappers) { + this.mappers = mappers; + } +} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapperTests.java index a38d20166..fe21110a1 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapperTests.java @@ -1,63 +1,63 @@ -/* - * Copyright 2006-2007 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.sample.iosample.internal; - -import static junit.framework.Assert.assertEquals; - -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.springframework.batch.item.file.mapping.FieldSetMapper; -import org.springframework.batch.item.file.transform.DefaultFieldSet; -import org.springframework.batch.item.file.transform.FieldSet; -import org.springframework.batch.sample.domain.trade.CustomerCredit; -import org.springframework.batch.sample.domain.trade.Trade; -import org.springframework.batch.sample.domain.trade.internal.CustomerCreditFieldSetMapper; -import org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper; - -/** - * @author Dan Garrette - * @since 2.0 - */ -public class PrefixMatchingCompositeFieldSetMapperTests { - - @Test - public void testMapFieldSet() { - Map mappers = new HashMap(); - mappers.put("TRAD", new TradeFieldSetMapper()); - mappers.put("CUST", new CustomerCreditFieldSetMapper()); - - PrefixMatchingCompositeFieldSetMapper mapper = new PrefixMatchingCompositeFieldSetMapper(); - mapper.setMappers(mappers); - - String[] tradeNames = new String[] { "isin", "quantity", "price", "customer", "prefix" }; - String[] tradeValues = new String[] { "ISIN001", "500", "4.50", "Customer1", "TRAD" }; - FieldSet tradeFS = new DefaultFieldSet(tradeValues, tradeNames); - - String[] customerNames = new String[] { "id", "name", "credit", "prefix" }; - String[] customerValues = new String[] { "256", "customer1", "3200.00", "CUST" }; - FieldSet customerFS = new DefaultFieldSet(customerValues, customerNames); - - Trade trade = new Trade("ISIN001", 500, new BigDecimal("4.50"), "Customer1"); - assertEquals(trade, mapper.mapFieldSet(tradeFS)); - - CustomerCredit customer = new CustomerCredit(256, "customer1", new BigDecimal("3200.00")); - assertEquals(customer, mapper.mapFieldSet(customerFS)); - } -} +/* + * Copyright 2006-2007 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.sample.iosample.internal; + +import static junit.framework.Assert.assertEquals; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.springframework.batch.item.file.mapping.FieldSetMapper; +import org.springframework.batch.item.file.transform.DefaultFieldSet; +import org.springframework.batch.item.file.transform.FieldSet; +import org.springframework.batch.sample.domain.trade.CustomerCredit; +import org.springframework.batch.sample.domain.trade.Trade; +import org.springframework.batch.sample.domain.trade.internal.CustomerCreditFieldSetMapper; +import org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper; + +/** + * @author Dan Garrette + * @since 2.0 + */ +public class PrefixMatchingCompositeFieldSetMapperTests { + + @Test + public void testMapFieldSet() { + Map> mappers = new HashMap>(); + mappers.put("TRAD", new TradeFieldSetMapper()); + mappers.put("CUST", new CustomerCreditFieldSetMapper()); + + PrefixMatchingCompositeFieldSetMapper mapper = new PrefixMatchingCompositeFieldSetMapper(); + mapper.setMappers(mappers); + + String[] tradeNames = new String[] { "isin", "quantity", "price", "customer", "prefix" }; + String[] tradeValues = new String[] { "ISIN001", "500", "4.50", "Customer1", "TRAD" }; + FieldSet tradeFS = new DefaultFieldSet(tradeValues, tradeNames); + + String[] customerNames = new String[] { "id", "name", "credit", "prefix" }; + String[] customerValues = new String[] { "256", "customer1", "3200.00", "CUST" }; + FieldSet customerFS = new DefaultFieldSet(customerValues, customerNames); + + Trade trade = new Trade("ISIN001", 500, new BigDecimal("4.50"), "Customer1"); + assertEquals(trade, mapper.mapFieldSet(tradeFS)); + + CustomerCredit customer = new CustomerCredit(256, "customer1", new BigDecimal("3200.00")); + assertEquals(customer, mapper.mapFieldSet(customerFS)); + } +}