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 000ec5a commit 265c85b
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/Bytes.java
Expand Up @@ -66,11 +66,15 @@ public NoNulls(final Bytes bytes) {
@Override
public byte[] asBytes() throws IOException {
if (this.origin == null) {
throw new IOException("NULL instead of a valid bytes");
throw new IllegalArgumentException(
"NULL instead of a valid bytes"
);
}
final byte[] bytes = this.origin.asBytes();
if (bytes == null) {
throw new IOException("NULL instead of a valid byte array");
throw new IllegalStateException(
"NULL instead of a valid byte array"
);
}
return bytes;
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/cactoos/BytesTest.java
Expand Up @@ -35,18 +35,18 @@
*/
public final class BytesTest {

@Test(expected = IOException.class)
public void failForNullBytes() throws IOException {
@Test(expected = IllegalArgumentException.class)
public void failForNullArgument() throws IOException {
new Bytes.NoNulls(null).asBytes();
}

@Test(expected = IOException.class)
public void failForNullArray() throws IOException {
@Test(expected = IllegalStateException.class)
public void failForNullResult() throws IOException {
new Bytes.NoNulls(() -> null).asBytes();
}

@Test
public void okForNoNullBytes() throws IOException {
public void okForNoNulls() throws IOException {
new Bytes.NoNulls(() -> new byte[1]).asBytes();
}
}

0 comments on commit 265c85b

Please sign in to comment.