From c9aba9001b89fd2e5f88d3e405bf6dd9b0cb3050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20No=C3=ABl?= Date: Fri, 17 Jul 2020 19:31:38 +0200 Subject: [PATCH] (#162) bump dependencies and use junit 5 --- pom.xml | 40 +++++++++------- .../llorllale/cactoos/matchers/HasEntry.java | 5 +- .../cactoos/matchers/HasProperty.java | 5 +- .../llorllale/cactoos/matchers/HasValues.java | 8 ++-- .../cactoos/matchers/HasValuesMatching.java | 8 ++-- .../llorllale/cactoos/matchers/Matches.java | 15 +++--- .../cactoos/matchers/MatchesBefore.java | 7 +-- .../llorllale/cactoos/matchers/Throws.java | 7 +-- .../cactoos/matchers/AssertionTest.java | 47 +++++++++---------- .../cactoos/matchers/MatcherOfTest.java | 40 ++++------------ src/test/resources/forbidden-apis.txt | 1 + 11 files changed, 88 insertions(+), 95 deletions(-) diff --git a/pom.xml b/pom.xml index 24efc9dd..bdaf6e80 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ com.jcabi parent - 0.49.4 + 0.50.5 org.llorllale cactoos-matchers @@ -71,28 +71,32 @@ org.cactoos cactoos - 0.44 + 0.45 provided + + + org.junit.vintage + junit-vintage-engine + test + + + junit + junit + 4.13 + test + org.hamcrest hamcrest-core + 1.3 - - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - - qulice @@ -106,6 +110,7 @@ org.jacoco jacoco-maven-plugin + 0.8.5 file @@ -179,6 +184,9 @@ src/test/resources/forbidden-apis.txt + + org/llorllale/cactoos/matchers/AssertionTest.class + diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java b/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java index 282473dd..19953d38 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java @@ -34,7 +34,7 @@ * Matcher to check that {@link Map} has particular elements. * *

Here is an example how {@link HasEntry} can be used:

- *
+ * 
{@code
  *  new Assertion<>(
  *     "must match",
  *     () -> new MapOf<>(
@@ -42,7 +42,8 @@
  *         new MapEntry<>("b", 2)
  *     ),
  *     new HasEntry<>("a", 1)
- * ).affirm();
+ * ).affirm(); + * }
* * @param Type of key. * @param Type of value. diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java b/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java index 66833052..8f214e8b 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java @@ -37,12 +37,13 @@ * Matcher to check that {@link Properties} has particular entry. * *

Here is an example how {@link HasProperty} can be used:

- *
+ * 
{@code
  *  new Assertion<>(
  *     "must have an entry",
  *     new PropertiesOf<>(...),
  *     new HasProperty<>("foo", "bar")
- * );
+ * ).affirm(); + * }
* * @since 1.0.0 */ diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasValues.java b/src/main/java/org/llorllale/cactoos/matchers/HasValues.java index 7f30e63d..6b1f532d 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasValues.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasValues.java @@ -34,11 +34,13 @@ * Matcher to check that {@link Iterable} has particular elements. * *

Here is an example how {@link HasValues} can be used:

- *
- *  MatcherAssert.assertThat(
+ * 
{@code
+ *  new Assertion<>(
+ *     "must match",
  *     new ListOf<>(1, 2, 3),
  *     new HasValues<>(2)
- * );
+ * ).affirm(); + * }
* * @param Type of item. * @since 1.0.0 diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java b/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java index 919960f8..75aaa5a7 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java @@ -36,11 +36,13 @@ * function. * *

Here is an example how {@link HasValuesMatching} can be used:

- *
- *  MatcherAssert.assertThat(
+ * 
{@code
+ *  new Assertion<>(
+ *     "must match",
  *     new ListOf<>(1, 2, 3),
  *     new HasValuesMatching<>(value -> value > 2 || value == 3)
- * );
+ * ).affirm(); + * }
* * @param Type of item. * @since 1.0.0 diff --git a/src/main/java/org/llorllale/cactoos/matchers/Matches.java b/src/main/java/org/llorllale/cactoos/matchers/Matches.java index 991bb1c5..eb554c76 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/Matches.java +++ b/src/main/java/org/llorllale/cactoos/matchers/Matches.java @@ -34,15 +34,18 @@ * Matcher to test {@link org.hamcrest.Matcher} objects. * *

Here is an example:

- *
{@code
- *  @Test
+ * 
+ * 
+ *  @Test
  *  public void matches() {
- *      MatcherAssert.assertThat(
+ *      new Assertion<>(
+ *          "must match",
  *          new TextIs("abc"),
- *          new Matches<>(new TextOf("abc"))
- *      );
+ *          new Matches<>(new TextOf("abc"))
+ *      ).affirm();
  *  }
- * }
+ * + *
* * @param Type of item. * @param Type of tested matcher. diff --git a/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java b/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java index 57f88007..30902d9a 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java +++ b/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java @@ -32,10 +32,10 @@ /** * Matcher to check that scalar finishes before some timeout. * - * This is a {@link Matcher} alternative to JUnit's {@link Test#timeout}. + * This is a {@link Matcher} alternative to JUnit's {@code Timeout} annotation. * *

Here is an example how {@link MatchesBefore} can be used:

- *
+ * 
{@code
  *  new Assertion<>(
  *       "must run in 5 seconds maximum",
  *       new TextOf("test"),
@@ -43,7 +43,8 @@
  *           5000,
  *           new TextIs("test")
  *       )
- *  ).affirm();
+ * ).affirm(); + * }
* * @param Type of the scalar's value * @since 1.0.0 diff --git a/src/main/java/org/llorllale/cactoos/matchers/Throws.java b/src/main/java/org/llorllale/cactoos/matchers/Throws.java index 8f8e6de0..2dfa3b33 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/Throws.java +++ b/src/main/java/org/llorllale/cactoos/matchers/Throws.java @@ -37,14 +37,15 @@ * Matcher to check that scalar throw the expected exception. * *

Here is an example how {@link Throws} can be used:

- *
- *  MatcherAssert.assertThat(
+ * 
{@code
+ *  new Assertion<>(
  *       "The matcher check that [1,2,3] contains [2]",
  *       () -> {
  *            throw new IllegalArgumentException("No object(s) found.");
  *       },
  *       new Throws("No object(s) found.", IllegalArgumentException.class)
- *  );
+ * ).affirm(); + * }
* * @param Type of the scalar's value * @since 1.0.0 diff --git a/src/test/java/org/llorllale/cactoos/matchers/AssertionTest.java b/src/test/java/org/llorllale/cactoos/matchers/AssertionTest.java index 7c76605f..b09dde98 100644 --- a/src/test/java/org/llorllale/cactoos/matchers/AssertionTest.java +++ b/src/test/java/org/llorllale/cactoos/matchers/AssertionTest.java @@ -28,26 +28,20 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; +import org.cactoos.Scalar; import org.cactoos.text.Joined; import org.cactoos.text.TextOf; import org.hamcrest.core.IsEqual; -import org.hamcrest.core.IsInstanceOf; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; /** * Tests for {@link Assertion}. * @since 1.0.0 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") public final class AssertionTest { - /** - * A rule for handling an exception. - */ - @Rule - public final ExpectedException exception = ExpectedException.none(); - /** * Assertion can be affirmed if the operation being tested matches. */ @@ -69,19 +63,20 @@ public void affirmIfResultMatches() { */ @Test public void refuteIfResultDoesNotMatch() throws IOException { - this.exception.expect(AssertionError.class); - this.exception.expectMessage( + Assertions.assertThrows( + AssertionError.class, + () -> new Assertion<>( + "must refute the assertion if the test's result is not as expected", + new TextOf("test"), + new TextIs("no match") + ).affirm(), new Joined( System.lineSeparator(), - "Text with value \"no match\"", + "must refute the assertion if the test's result is not as expected", + "Expected: Text with value \"no match\"", " but was: Text is \"test\"" ).asString() ); - new Assertion<>( - "must refute the assertion if the test's result is not as expected", - new TextOf("test"), - new TextIs("no match") - ).affirm(); } /** @@ -90,16 +85,16 @@ public void refuteIfResultDoesNotMatch() throws IOException { */ @Test public void refuteIfErrorDoesNotMatch() { - this.exception.expectCause( - IsInstanceOf.instanceOf(IllegalStateException.class) + Assertions.assertThrows( + IllegalStateException.class, + () -> new Assertion>( + "must fail if the test throws an unexpected error", + () -> { + throw new IllegalStateException(); + }, + new ScalarHasValue<>("no match") + ).affirm() ); - new Assertion<>( - "must fail if the test throws an unexpected error", - () -> { - throw new IllegalStateException(); - }, - new TextIs("no match") - ).affirm(); } /** diff --git a/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java b/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java index 65719be5..6bfea58a 100644 --- a/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java +++ b/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java @@ -26,14 +26,9 @@ */ package org.llorllale.cactoos.matchers; -import org.cactoos.text.FormattedText; import org.cactoos.text.Joined; import org.cactoos.text.TextOf; -import org.cactoos.text.UncheckedText; -import org.hamcrest.core.IsNot; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Test case for {@link MatcherOf}. @@ -45,12 +40,6 @@ */ public final class MatcherOfTest { - /** - * A rule for handling an exception. - */ - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void matchesFunc() { new Assertion<>( @@ -64,26 +53,15 @@ public void matchesFunc() { public void mismatchesFunc() { new Assertion<>( "mismatches when arg does not satisfy the predicate", - new MatcherOf<>(x -> x > 5), - new IsNot<>(new Matches<>(1)) - ).affirm(); - } - - @Test - public void describesMismatch() { - this.exception.expect(AssertionError.class); - this.exception.expectMessage( - new UncheckedText( - new FormattedText( - // @checkstyle LineLength (1 line) - "describes mismatch%nExpected: \"Must be > 5\"%n but was: <1>" - ) - ).asString() - ); - new Assertion<>( - "describes mismatch", - 1, - new MatcherOf<>(x -> x > 5, new TextOf("Must be > 5")) + new MatcherOf<>( + x -> x > 5, + new TextOf("Must be > 5") + ), + new Mismatches<>( + 1, + "\"Must be > 5\"", + "<1>" + ) ).affirm(); } diff --git a/src/test/resources/forbidden-apis.txt b/src/test/resources/forbidden-apis.txt index aaa9f2ad..bdc950a3 100644 --- a/src/test/resources/forbidden-apis.txt +++ b/src/test/resources/forbidden-apis.txt @@ -3,6 +3,7 @@ org.hamcrest.Matchers @defaultMessage Please do not use org.junit.Assert class. Use org.llorllale.cactoos.matchers.Assertion instead. org.junit.Assert +org.junit.jupiter.api.Assertions @defaultMessage Please do not use org.hamcrest.MatcherAssert class. Use org.llorllale.cactoos.matchers.Assertion instead. org.hamcrest.MatcherAssert