diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java index acd1b1237..fa6ce2c1f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java @@ -2,6 +2,8 @@ package org.springframework.batch.item.file.mapping; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.item.file.transform.LineTokenizer; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** * Two-phase {@link LineMapper} implementation consisting of tokenization of the @@ -11,7 +13,7 @@ import org.springframework.batch.item.file.transform.LineTokenizer; * * @param type of the item */ -public class DefaultLineMapper implements LineMapper { +public class DefaultLineMapper implements LineMapper, InitializingBean { private LineTokenizer tokenizer; @@ -29,4 +31,9 @@ public class DefaultLineMapper implements LineMapper { this.fieldSetMapper = fieldSetMapper; } + public void afterPropertiesSet() { + Assert.notNull(tokenizer, "The LineTokenizer must be set"); + Assert.notNull(fieldSetMapper, "The FieldSetMapper must be set"); + } + } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java index 1bf4a5276..f95905dca 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java @@ -5,6 +5,7 @@ import static org.junit.Assert.*; import org.junit.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; +import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.item.file.transform.LineTokenizer; @@ -14,6 +15,19 @@ import org.springframework.batch.item.file.transform.LineTokenizer; public class DefaultLineMapperTests { private DefaultLineMapper tested = new DefaultLineMapper(); + + @Test(expected=IllegalArgumentException.class) + public void testMandatoryTokenizer() throws Exception { + tested.afterPropertiesSet(); + tested.mapLine("foo", 1); + } + + @Test(expected=IllegalArgumentException.class) + public void testMandatoryMapper() throws Exception { + tested.setLineTokenizer(new DelimitedLineTokenizer()); + tested.afterPropertiesSet(); + tested.mapLine("foo", 1); + } @Test public void testMapping() throws Exception {