Fix line tokenizer validation in FlatFileItemReaderBuilder

Resolves #766
This commit is contained in:
Mahmoud Ben Hassine
2020-03-17 23:27:47 +01:00
parent 5874257419
commit 1a6ecfdb5d
2 changed files with 21 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-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.
@@ -474,7 +474,7 @@ public class FlatFileItemReaderBuilder<T> {
DefaultLineMapper<T> lineMapper = new DefaultLineMapper<>();
if(this.lineTokenizer != null && this.fieldSetMapper != null) {
if(this.lineTokenizer != null) {
lineMapper.setLineTokenizer(this.lineTokenizer);
}
else if(this.fixedLengthBuilder != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-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.
@@ -524,6 +524,24 @@ public class FlatFileItemReaderBuilderTests {
assertEquals(encoding, ReflectionTestUtils.getField(reader, "encoding"));
}
@Test
public void testErrorMessageWhenNoFieldSetMapperIsProvided() {
try {
new FlatFileItemReaderBuilder<Foo>()
.name("fooReader")
.resource(getResource("1;2;3"))
.lineTokenizer(line -> new DefaultFieldSet(line.split(";")))
.build();
} catch (IllegalStateException exception) {
String exceptionMessage = exception.getMessage();
if (exceptionMessage.equals("No LineTokenizer implementation was provided.")) {
fail("Error message should not be 'No LineTokenizer implementation was provided.'" +
" when a LineTokenizer is provided");
}
assertEquals("No FieldSetMapper implementation was provided.", exceptionMessage);
}
}
private Resource getResource(String contents) {
return new ByteArrayResource(contents.getBytes());
}