CSVFormat.validate() throws IllegalStateException instead of IllegalArgumentException because the method validates the state of the object.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1397876 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2012-10-13 16:08:44 +00:00
parent e331df694c
commit ae47fb8432
2 changed files with 14 additions and 12 deletions

View File

@ -168,29 +168,31 @@ public class CSVFormat implements Serializable {
} }
/** /**
* Verifies the consistency of the parameters and throws an IllegalArgumentException if necessary. * Verifies the consistency of the parameters and throws an IllegalStateException if necessary.
*
* @throws IllegalStateException
*/ */
void validate() throws IllegalArgumentException { void validate() throws IllegalStateException {
if (delimiter == encapsulator) { if (delimiter == encapsulator) {
throw new IllegalArgumentException("The encapsulator character and the delimiter cannot be the same ('" + encapsulator + ")"); throw new IllegalStateException("The encapsulator character and the delimiter cannot be the same ('" + encapsulator + ")");
} }
if (delimiter == escape) { if (delimiter == escape) {
throw new IllegalArgumentException("The escape character and the delimiter cannot be the same ('" + escape + "')"); throw new IllegalStateException("The escape character and the delimiter cannot be the same ('" + escape + "')");
} }
if (delimiter == commentStart) { if (delimiter == commentStart) {
throw new IllegalArgumentException("The comment start character and the delimiter cannot be the same ('" + commentStart + throw new IllegalStateException("The comment start character and the delimiter cannot be the same ('" + commentStart +
"')"); "')");
} }
if (encapsulator != null && encapsulator == commentStart) { if (encapsulator != null && encapsulator == commentStart) {
throw new IllegalArgumentException("The comment start character and the encapsulator cannot be the same ('" + commentStart + throw new IllegalStateException("The comment start character and the encapsulator cannot be the same ('" + commentStart +
"')"); "')");
} }
if (escape != null && escape == commentStart) { if (escape != null && escape == commentStart) {
throw new IllegalArgumentException("The comment start and the escape character cannot be the same ('" + commentStart + "')"); throw new IllegalStateException("The comment start and the escape character cannot be the same ('" + commentStart + "')");
} }
} }

View File

@ -113,21 +113,21 @@ public class CSVFormatTest {
try { try {
format.withDelimiter('!').withEscape('!').validate(); format.withDelimiter('!').withEscape('!').validate();
fail(); fail();
} catch (final IllegalArgumentException e) { } catch (final IllegalStateException e) {
// expected // expected
} }
try { try {
format.withDelimiter('!').withCommentStart('!').validate(); format.withDelimiter('!').withCommentStart('!').validate();
fail(); fail();
} catch (final IllegalArgumentException e) { } catch (final IllegalStateException e) {
// expected // expected
} }
try { try {
format.withEncapsulator('!').withCommentStart('!').validate(); format.withEncapsulator('!').withCommentStart('!').validate();
fail(); fail();
} catch (final IllegalArgumentException e) { } catch (final IllegalStateException e) {
// expected // expected
} }
@ -136,7 +136,7 @@ public class CSVFormatTest {
try { try {
format.withEscape('!').withCommentStart('!').validate(); format.withEscape('!').withCommentStart('!').validate();
fail(); fail();
} catch (final IllegalArgumentException e) { } catch (final IllegalStateException e) {
// expected // expected
} }
@ -146,7 +146,7 @@ public class CSVFormatTest {
try { try {
format.withEncapsulator('!').withDelimiter('!').validate(); format.withEncapsulator('!').withDelimiter('!').validate();
fail(); fail();
} catch (final IllegalArgumentException e) { } catch (final IllegalStateException e) {
// expected // expected
} }
} }