mirror of
https://github.com/apache/commons-csv.git
synced 2025-02-27 13:34:59 +00:00
Merge pull request #352 from gbidsilva/CSV-310
[CSV-310] Misleading error message when QuoteMode set to None
This commit is contained in:
commit
c2cf3057d3
@ -2449,7 +2449,7 @@ public final class CSVFormat implements Serializable {
|
||||
}
|
||||
|
||||
if (escapeCharacter == null && quoteMode == QuoteMode.NONE) {
|
||||
throw new IllegalArgumentException("No quotes mode set but no escape character is set");
|
||||
throw new IllegalArgumentException("Quote mode set to NONE but no escape character is set");
|
||||
}
|
||||
|
||||
// Validate headers
|
||||
|
@ -1477,4 +1477,17 @@ public class CSVFormatTest {
|
||||
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
|
||||
assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
|
||||
CSVFormat.DEFAULT.builder()
|
||||
.setHeader("Col1", "Col2", "Col3", "Col4")
|
||||
.setQuoteMode(QuoteMode.NONE)
|
||||
.build();
|
||||
});
|
||||
String actualMessage = exception.getMessage();
|
||||
String expectedMessage = "Quote mode set to NONE but no escape character is set";
|
||||
assertEquals(expectedMessage, actualMessage);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user