Skip to content

Commit

Permalink
(#170) Migrate to Junit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Jan 12, 2021
1 parent 4870f33 commit bdaff61
Show file tree
Hide file tree
Showing 26 changed files with 134 additions and 151 deletions.
17 changes: 0 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,6 @@
<artifactId>cactoos</artifactId>
<version>0.48</version>
</dependency>
<!--
@todo #162:30min Migrate existing tests to JUnit 5. It mainly means
changing the imports and move from Ignore to Disabled annotation as
well as replace rules with corresponding annotations. Once this is done
remove the dependency for junit 4 and junit-vintage-engine below.
-->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/llorllale/cactoos/matchers/AssertionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
import org.cactoos.text.Joined;
import org.cactoos.text.TextOf;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Tests for {@link Assertion}.
* @since 1.0.0
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class AssertionTest {
final class AssertionTest {
/**
* Assertion can be affirmed if the operation being tested matches.
*/
@Test
public void affirmIfResultMatches() {
void affirmIfResultMatches() {
final String expected = "abc123";
new Assertion<>(
"must affirm the assertion if the test's result is as expected",
Expand All @@ -61,7 +61,7 @@ public void affirmIfResultMatches() {
* @throws Exception if something goes wrong.
*/
@Test
public void refuteIfResultDoesNotMatch() throws Exception {
void refuteIfResultDoesNotMatch() throws Exception {
Assertions.assertThrows(
AssertionError.class,
() -> new Assertion<>(
Expand All @@ -83,7 +83,7 @@ public void refuteIfResultDoesNotMatch() throws Exception {
* unexpected error.
*/
@Test
public void refuteIfErrorDoesNotMatch() {
void refuteIfErrorDoesNotMatch() {
Assertions.assertThrows(
IllegalStateException.class,
() -> new Assertion<Scalar<String>>(
Expand All @@ -101,7 +101,7 @@ public void refuteIfErrorDoesNotMatch() {
* expected error.
*/
@Test
public void affirmIfErrorMatches() {
void affirmIfErrorMatches() {
new Assertion<>(
"must affirm the assertion if the test throws the expected error",
() -> {
Expand All @@ -115,7 +115,7 @@ public void affirmIfErrorMatches() {
* The scalar within Assertion executed is only once.
*/
@Test
public void scalarIsExecutedOnce() {
void scalarIsExecutedOnce() {
final AtomicInteger quantity = new AtomicInteger(0);
new Assertion<>(
"must match the exception",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
package org.llorllale.cactoos.matchers;

import org.cactoos.text.TextOf;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link EndsWith}.
*
* @since 1.0.0
*/
public final class EndsWithTest {
final class EndsWithTest {

@Test
public void matches() {
void matches() {
new Assertion<>(
"The matcher gives positive result for the valid arguments",
new EndsWith("know it."),
Expand All @@ -47,7 +47,7 @@ public void matches() {
}

@Test
public void mismatches() {
void mismatches() {
new Assertion<>(
"The matcher gives negative result for the invalid arguments",
new EndsWith("!"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
package org.llorllale.cactoos.matchers;

import org.hamcrest.core.IsNot;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link FuncApplies}.
Expand All @@ -36,10 +36,10 @@
* @checkstyle JavadocMethodCheck (100 lines)
* @checkstyle MagicNumber (100 line)
*/
public final class FuncAppliesTest {
final class FuncAppliesTest {

@Test
public void matchFuncs() {
void matchFuncs() {
new Assertion<>(
"matches function that produces same output from the given input",
new FuncApplies<>(1, 1),
Expand All @@ -48,7 +48,7 @@ public void matchFuncs() {
}

@Test
public void mismatchFuncs() {
void mismatchFuncs() {
new Assertion<>(
// @checkstyle LineLength (1 line)
"does not match function that produces different output from the given input",
Expand All @@ -58,7 +58,7 @@ public void mismatchFuncs() {
}

@Test
public void describesMismatch() {
void describesMismatch() {
new Assertion<>(
"describes mismatch",
new FuncApplies<>(1, 1),
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/llorllale/cactoos/matchers/HasEntryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link HasEntry}.
Expand All @@ -38,13 +38,13 @@
* @checkstyle JavadocMethodCheck (200 lines)
*/
@SuppressWarnings("unchecked")
public final class HasEntryTest {
final class HasEntryTest {

/**
* Example of {@link HasEntry} usage.
*/
@Test
public void matches() {
void matches() {
new Assertion<>(
"must match an entry in the map",
new HasEntry<>("a", 1),
Expand All @@ -58,7 +58,7 @@ public void matches() {
}

@Test
public void doesNotMatchAMissingEntry() {
void doesNotMatchAMissingEntry() {
new Assertion<>(
"must not match a missing entry in the map",
new HasEntry<>("c", 1),
Expand All @@ -71,7 +71,7 @@ public void doesNotMatchAMissingEntry() {
}

@Test
public void doesNotMatchAnIncorrectEntry() {
void doesNotMatchAnIncorrectEntry() {
new Assertion<>(
"must not match an existing entry in the map",
new HasEntry<>("b", 1),
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/llorllale/cactoos/matchers/HasLinesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@
package org.llorllale.cactoos.matchers;

import org.cactoos.text.TextOf;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link HasLines}.
*
* @since 1.0.0
*/
public final class HasLinesTest {
final class HasLinesTest {

/**
* Example of {@link HasLines} behavior for positive results.
*/
@Test
public void matches() {
void matches() {
new Assertion<>(
"matches lines containing the given strings",
new HasLines("A", "C"),
Expand All @@ -53,7 +53,7 @@ public void matches() {
* Example of {@link HasLines} behavior for positive results.
*/
@Test
public void matchesWithText() {
void matchesWithText() {
new Assertion<>(
"matches lines containing the given Text",
new HasLines(new TextOf("A"), new TextOf("D")),
Expand All @@ -67,7 +67,7 @@ public void matchesWithText() {
* - The matcher should explain the mismatch between comparing objects.
*/
@Test
public void failed() {
void failed() {
new Assertion<>(
"must not match lines that do not contain the given strings",
new HasLines("Tom", "Mike"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
import org.hamcrest.Matcher;
import org.hamcrest.core.AllOf;
import org.hamcrest.text.IsEqualIgnoringCase;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link HasProperty}.
*
* @since 1.0.0
* @checkstyle ClassDataAbstractionCoupling (100 lines)
*/
public final class HasPropertyTest {
final class HasPropertyTest {

/**
* Simple positive case.
*/
@Test
public void positiveMatch() {
void positiveMatch() {
new Assertion<>(
"must match 'a=1'",
new ScalarHasValue<>(new HasProperty("a", "1")),
Expand All @@ -59,7 +59,7 @@ public void positiveMatch() {
* Simple positive case only for key.
*/
@Test
public void positiveMachKey() {
void positiveMachKey() {
new Assertion<>(
"must match 'b=...'",
new ScalarHasValue<>(new HasProperty("b")),
Expand All @@ -71,7 +71,7 @@ public void positiveMachKey() {
* Positive case with Matchers.
*/
@Test
public void positiveFuzzyMatch() {
void positiveFuzzyMatch() {
new Assertion<>(
"must match 'f=q'",
new ScalarHasValue<>(
Expand All @@ -94,7 +94,7 @@ public void positiveFuzzyMatch() {
* Negative case.
*/
@Test
public void negativeMatch() {
void negativeMatch() {
final String expected =
"Scalar with has property key \"abc\", value \"1\"";
new Assertion<>(
Expand All @@ -121,7 +121,7 @@ public void negativeMatch() {
* Test for mismatch description readability.
*/
@Test
public void describesCorrectly() {
void describesCorrectly() {
new Assertion<>(
"must have a message that describes the properties",
new ScalarHasValue<>(new HasProperty("c", "3")),
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/llorllale/cactoos/matchers/HasSizeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.hamcrest.Description;
import org.hamcrest.StringDescription;
import org.hamcrest.core.IsNot;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link HasSize}.
Expand All @@ -44,10 +44,10 @@
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle ClassDataAbstractionCoupling (2 lines)
*/
public final class HasSizeTest {
final class HasSizeTest {

@Test
public void matchesIterableSize() {
void matchesIterableSize() {
new Assertion<>(
"matches iterable with given size",
new HasSize(2),
Expand All @@ -56,7 +56,7 @@ public void matchesIterableSize() {
}

@Test
public void doesNotMatchIterableSize() {
void doesNotMatchIterableSize() {
new Assertion<>(
"does not match an iterable with a different size",
new IsNot<>(new HasSize(2)),
Expand All @@ -65,7 +65,7 @@ public void doesNotMatchIterableSize() {
}

@Test
public void matchesEmptyCollection() {
void matchesEmptyCollection() {
new Assertion<>(
"matches empty iterable if given size arg is 0",
new HasSize(0),
Expand All @@ -74,7 +74,7 @@ public void matchesEmptyCollection() {
}

@Test
public void describesMismatch() {
void describesMismatch() {
final Description description = new StringDescription();
new HasSize(2).describeMismatchSafely(new ListOf<>(), description);
new Assertion<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package org.llorllale.cactoos.matchers;

import org.cactoos.list.ListOf;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link HasValuesMatching}.
Expand All @@ -37,13 +37,13 @@
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumberCheck (500 lines)
*/
public final class HasValuesMatchingTest {
final class HasValuesMatchingTest {

/**
* Example of {@link HasValues} usage.
*/
@Test
public void matches() {
void matches() {
new Assertion<>(
"matches iterable with any elements that satisfy predicate",
new HasValuesMatching<>(value -> value == 3),
Expand All @@ -52,7 +52,7 @@ public void matches() {
}

@Test
public void mismatches() {
void mismatches() {
new Assertion<>(
"must throw an exception that describes the values",
new HasValuesMatching<>(value -> value > 5),
Expand Down
Loading

0 comments on commit bdaff61

Please sign in to comment.