Skip to content

Commit

Permalink
(#162) bump dependencies and use junit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
victornoel committed Sep 4, 2020
1 parent a40df7d commit c9aba90
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 95 deletions.
40 changes: 24 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<parent>
<groupId>com.jcabi</groupId>
<artifactId>parent</artifactId>
<version>0.49.4</version>
<version>0.50.5</version>
</parent>
<groupId>org.llorllale</groupId>
<artifactId>cactoos-matchers</artifactId>
Expand Down Expand Up @@ -71,28 +71,32 @@
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>0.44</version>
<version>0.45</version>
<scope>provided</scope>
</dependency>
<!--
@todo #1411: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>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>qulice</id>
Expand All @@ -106,6 +110,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<output>file</output>
</configuration>
Expand Down Expand Up @@ -179,6 +184,9 @@
<signaturesFiles>
<signaturesFile>src/test/resources/forbidden-apis.txt</signaturesFile>
</signaturesFiles>
<excludes>
<exclude>org/llorllale/cactoos/matchers/AssertionTest.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/llorllale/cactoos/matchers/HasEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
* Matcher to check that {@link Map} has particular elements.
*
* <p>Here is an example how {@link HasEntry} can be used:</p>
* <pre>
* <pre>{@code
* new Assertion<>(
* "must match",
* () -> new MapOf<>(
* new MapEntry<>("a", 1),
* new MapEntry<>("b", 2)
* ),
* new HasEntry<>("a", 1)
* ).affirm();</pre>
* ).affirm();
* }</pre>
*
* @param <K> Type of key.
* @param <V> Type of value.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/llorllale/cactoos/matchers/HasProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
* Matcher to check that {@link Properties} has particular entry.
*
* <p>Here is an example how {@link HasProperty} can be used:</p>
* <pre>
* <pre>{@code
* new Assertion<>(
* "must have an entry",
* new PropertiesOf<>(...),
* new HasProperty<>("foo", "bar")
* );</pre>
* ).affirm();
* }</pre>
*
* @since 1.0.0
*/
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/llorllale/cactoos/matchers/HasValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
* Matcher to check that {@link Iterable} has particular elements.
*
* <p>Here is an example how {@link HasValues} can be used:</p>
* <pre>
* MatcherAssert.assertThat(
* <pre>{@code
* new Assertion<>(
* "must match",
* new ListOf<>(1, 2, 3),
* new HasValues<>(2)
* );</pre>
* ).affirm();
* }</pre>
*
* @param <X> Type of item.
* @since 1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
* function.
*
* <p>Here is an example how {@link HasValuesMatching} can be used:</p>
* <pre>
* MatcherAssert.assertThat(
* <pre>{@code
* new Assertion<>(
* "must match",
* new ListOf<>(1, 2, 3),
* new HasValuesMatching<>(value -> value > 2 || value == 3)
* );</pre>
* ).affirm();
* }</pre>
*
* @param <X> Type of item.
* @since 1.0.0
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/org/llorllale/cactoos/matchers/Matches.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
* Matcher to test {@link org.hamcrest.Matcher} objects.
*
* <p>Here is an example:</p>
* <pre>{@code
* @Test
* <pre>
* <code>
* &#64;Test
* public void matches() {
* MatcherAssert.assertThat(
* new Assertion&#60;&#62;(
* "must match",
* new TextIs("abc"),
* new Matches<>(new TextOf("abc"))
* );
* new Matches&#60;&#62;(new TextOf("abc"))
* ).affirm();
* }
* }</pre>
* </code>
* </pre>
*
* @param <X> Type of item.
* @param <M> Type of tested matcher.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@
/**
* 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.
*
* <p>Here is an example how {@link MatchesBefore} can be used:</p>
* <pre>
* <pre>{@code
* new Assertion<>(
* "must run in 5 seconds maximum",
* new TextOf("test"),
* new MatchesBefore(
* 5000,
* new TextIs("test")
* )
* ).affirm();</pre>
* ).affirm();
* }</pre>
*
* @param <T> Type of the scalar's value
* @since 1.0.0
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/llorllale/cactoos/matchers/Throws.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
* Matcher to check that scalar throw the expected exception.
*
* <p>Here is an example how {@link Throws} can be used:</p>
* <pre>
* MatcherAssert.assertThat(
* <pre>{@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)
* );</pre>
* ).affirm();
* }</pre>
*
* @param <T> Type of the scalar's value
* @since 1.0.0
Expand Down
47 changes: 21 additions & 26 deletions src/test/java/org/llorllale/cactoos/matchers/AssertionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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();
}

/**
Expand All @@ -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<Scalar<String>>(
"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();
}

/**
Expand Down
40 changes: 9 additions & 31 deletions src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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<>(
Expand All @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/forbidden-apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 comment on commit c9aba90

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on c9aba90 Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

GET https://api.github.com/repos/llorllale/cactoos-matchers/issues/1411: 404 - Not Found // See: https://docs.github.com/rest/reference/issues#get-an-issue

Please, copy and paste this stack trace to GitHub:

Octokit::NotFound
GET https://api.github.com/repos/llorllale/cactoos-matchers/issues/1411: 404 - Not Found // See: https://docs.github.com/rest/reference/issues#get-an-issue
/app/vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/response/raise_error.rb:16:in `on_complete'
/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/response.rb:9:in `block in call'
/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/response.rb:61:in `on_complete'
/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/response.rb:8:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/middleware/follow_redirects.rb:73:in `perform_with_redirection'
/app/vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/middleware/follow_redirects.rb:61:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/request/retry.rb:128:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/rack_builder.rb:143:in `build_response'
/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/connection.rb:387:in `run_request'
/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/connection.rb:138:in `get'
/app/vendor/bundle/ruby/2.6.0/gems/sawyer-0.8.2/lib/sawyer/agent.rb:94:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/connection.rb:156:in `request'
/app/vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/connection.rb:19:in `get'
/app/vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/client/issues.rb:114:in `issue'
/app/objects/milestone_tickets.rb:44:in `submit'
/app/objects/logged_tickets.rb:50:in `submit'
/app/objects/github_tagged_tickets.rb:40:in `submit'
/app/objects/commit_tickets.rb:38:in `submit'
/app/objects/emailed_tickets.rb:35:in `submit'
/app/objects/sentry_tickets.rb:46:in `submit'
/app/objects/puzzles.rb:89:in `block in expose'
/app/objects/puzzles.rb:80:in `loop'
/app/objects/puzzles.rb:80:in `expose'
/app/objects/puzzles.rb:33:in `deploy'
/app/objects/job.rb:38:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:48:in `exclusive'
/app/objects/job_detached.rb:36:in `block in proceed'
/app/objects/job_detached.rb:36:in `fork'
/app/objects/job_detached.rb:36:in `proceed'
/app/0pdd.rb:358:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1635:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1635:in `block in compile!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:992:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1011:in `route_eval'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:992:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1040:in `block in process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1038:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1038:in `process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:990:in `block in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:989:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:989:in `route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1097:in `block in dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1094:in `dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:924:in `block in call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:924:in `call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:913:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/logger.rb:15:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/common_logger.rb:33:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:231:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:224:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:194:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1957:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1502:in `block in call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1729:in `synchronize'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1502:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/handler/webrick.rb:86:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'

Please sign in to comment.