Skip to content

Commit

Permalink
Migrate test to Junit 5 #1453
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier B. OURA committed Apr 5, 2021
1 parent 3e37919 commit 1143ab3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The MIT License (MIT)
</exclusions>
</dependency>
<!--
@todo #1416:30min Migrate the rest of tests to JUnit 5 Junit 4 Rule
@todo #1453:30min Continue migration of tests to JUnit 5. Junit 4 Rule
should be replaced with a Jupiter counterpart. `@Text(expected=..)`
with `Throws`. After that remove this dependencies.
-->
Expand Down
18 changes: 13 additions & 5 deletions src/test/java/org/cactoos/BytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
package org.cactoos;

import org.cactoos.bytes.NoNulls;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.Throws;

/**
* Test case for {@link NoNulls}.
Expand All @@ -33,14 +35,20 @@
*/
public final class BytesTest {

@Test(expected = IllegalArgumentException.class)
public void failForNullArgument() throws Exception {
new NoNulls(null).asBytes();
new Assertion<>(
"Must fail for null argument.",
() -> new NoNulls(null).asBytes(),
new Throws<>(IllegalArgumentException.class)
).affirm();
}

@Test(expected = IllegalStateException.class)
public void failForNullResult() throws Exception {
new NoNulls(() -> null).asBytes();
new Assertion<>(
"Must fail for null result.",
() -> new NoNulls(() -> null).asBytes(),
new Throws<>(IllegalStateException.class)
).affirm();
}

@Test
Expand Down
18 changes: 13 additions & 5 deletions src/test/java/org/cactoos/bytes/HexOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
import java.io.IOException;
import org.cactoos.text.TextOf;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.Throws;
import org.llorllale.cactoos.matchers.Verifies;

/**
Expand All @@ -37,6 +38,7 @@
* @since 0.29
* @checkstyle MagicNumberCheck (500 line)
* @checkstyle JavadocMethodCheck (500 line)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class HexOfTest {

Expand Down Expand Up @@ -66,13 +68,19 @@ public void validHex() throws Exception {
).affirm();
}

@Test(expected = IOException.class)
public void invalidHexLength() throws Exception {
new HexOf(new TextOf("ABF")).asBytes();
new Assertion<>(
"Must invalid hex length",
() -> new HexOf(new TextOf("ABF")).asBytes(),
new Throws<>(IOException.class)
).affirm();
}

@Test(expected = IOException.class)
public void invalidHex() throws Exception {
new HexOf(new TextOf("ABG!")).asBytes();
new Assertion<>(
"Must invalid hex",
() -> new HexOf(new TextOf("ABG!")).asBytes(),
new Throws<>(IOException.class)
).affirm();
}
}
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/bytes/ReaderAsBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.io.StringReader;
import org.cactoos.text.TextOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.rules.TemporaryFolder;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.IsText;
Expand Down
19 changes: 12 additions & 7 deletions src/test/java/org/cactoos/bytes/UncheckedBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
import org.cactoos.Text;
import org.cactoos.text.TextOf;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.Throws;

/**
* Test case for {@link UncheckedBytes}.
Expand All @@ -38,13 +39,17 @@
*/
public final class UncheckedBytesTest {

@Test(expected = RuntimeException.class)
@Test
public void rethrowsCheckedToUncheckedException() {
new UncheckedBytes(
() -> {
throw new IOException("intended");
}
).asBytes();
new Assertion<>(
"Must rethrow checked to unchecked exception",
() -> new UncheckedBytes(
() -> {
throw new IOException("intended");
}
).asBytes(),
new Throws<>(RuntimeException.class)
).affirm();
}

@Test
Expand Down

0 comments on commit 1143ab3

Please sign in to comment.