Skip to content

Commit

Permalink
Change to a proper exception
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Jul 8, 2017
1 parent d700b46 commit 6eecf69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/cactoos/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ public NoNulls(final Text text) {
@Override
public String asString() throws IOException {
if (this.origin == null) {
throw new IOException("NULL instead of a valid text");
throw new IllegalArgumentException(
"NULL instead of a valid text"
);
}
final String string = this.origin.asString();
if (string == null) {
throw new IOException("NULL instead of a valid result string");
throw new IllegalStateException(
"NULL instead of a valid result string"
);
}
return string;
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/cactoos/TextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
*/
public final class TextTest {

@Test(expected = IOException.class)
public void failForNullText() throws IOException {
@Test(expected = IllegalArgumentException.class)
public void failForNullArgument() throws IOException {
new Text.NoNulls(null).asString();
}

@Test(expected = IOException.class)
public void failForReturnNullString() throws IOException {
@Test(expected = IllegalStateException.class)
public void failForNullResult() throws IOException {
new Text.NoNulls(
new Text() {
@Override
Expand All @@ -59,7 +59,7 @@ public int compareTo(final Text text) {
}

@Test
public void checkForNullText() throws Exception {
public void okForNoNulls() throws Exception {
final String message = "Hello";
MatcherAssert.assertThat(
"Can't work with null text",
Expand Down

0 comments on commit 6eecf69

Please sign in to comment.