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:
parent
e331df694c
commit
ae47fb8432
|
@ -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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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 + "')");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -113,21 +113,21 @@ public class CSVFormatTest {
|
|||
try {
|
||||
format.withDelimiter('!').withEscape('!').validate();
|
||||
fail();
|
||||
} catch (final IllegalArgumentException e) {
|
||||
} catch (final IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withDelimiter('!').withCommentStart('!').validate();
|
||||
fail();
|
||||
} catch (final IllegalArgumentException e) {
|
||||
} catch (final IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withEncapsulator('!').withCommentStart('!').validate();
|
||||
fail();
|
||||
} catch (final IllegalArgumentException e) {
|
||||
} catch (final IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class CSVFormatTest {
|
|||
try {
|
||||
format.withEscape('!').withCommentStart('!').validate();
|
||||
fail();
|
||||
} catch (final IllegalArgumentException e) {
|
||||
} catch (final IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class CSVFormatTest {
|
|||
try {
|
||||
format.withEncapsulator('!').withDelimiter('!').validate();
|
||||
fail();
|
||||
} catch (final IllegalArgumentException e) {
|
||||
} catch (final IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue