changing the exception message to be more meaningful

This commit is contained in:
gbidsilva 2023-09-06 18:42:13 +05:30
parent 710459843c
commit eb95e6dff7
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);
}
}