Merge pull request #352 from gbidsilva/CSV-310

[CSV-310] Misleading error message when QuoteMode set to None
This commit is contained in:
Gary Gregory 2023-09-13 08:59:55 -04:00 committed by GitHub
commit c2cf3057d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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);
}
}