Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into issue-136
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Jul 13, 2020
2 parents c4140f9 + 4daa27a commit 7ebaceb
Show file tree
Hide file tree
Showing 23 changed files with 461 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .rultor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ docker:
as_root: true
architect:
- llorllale
- paulodamaso
- victornoel
merge:
script: |
pdd -f /dev/null
Expand All @@ -22,4 +22,4 @@ release:
[[ "${tag}" =~ ^[0-9]+(\.[0-9]+)*$ ]] || exit -1
mvn versions:set "-DnewVersion=${tag}"
git commit -am "${tag}"
mvn clean deploy -Psonar -Pqulice -Psonatype --errors --settings ../settings.xml
mvn clean deploy -Psonar -Pqulice -Psonatype --errors --settings ../settings.xml
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<plugin>
<groupId>com.qulice</groupId>
<artifactId>qulice-maven-plugin</artifactId>
<version>0.17.3</version>
<version>0.18.19</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/llorllale/cactoos/matchers/Assertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@
* @todo #18:30min Replace all uses of MatcherAssert.assertThat() with
* Assertion, and ban all overloads of the former in forbidden-apis.txt.
* We should also look into banning common matchers like Matchers.is(), etc.
* @todo #67:30min Assertion should rely on mismatch description when forming
* error message (as assertThat does). Currently 'was' is being used by this
* class as part of description, it causes duplication of the word with
* Matchers derived from BaseMatcher, such as IsEqual.
*/
public final class Assertion<T> {
/**
* Whether this assertion is refuted.
*/
private final Unchecked<Boolean> refuted;

/**
* Refutation error.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public final class FuncApplies<X, Y> extends MatcherEnvelope<Func<X, Y>> {

/**
* Ctor.
* @param result The result expected
* @param inpt Input for the function
* @param result The result expected
*/
public FuncApplies(final X inpt, final Y result) {
this(inpt, new IsEqual<>(result));
Expand All @@ -57,7 +57,6 @@ public FuncApplies(final X inpt, final Y result) {
*/
public FuncApplies(final X input, final Matcher<Y> mtr) {
super(
// @checkstyle IndentationCheck (7 line)
func -> mtr.matches(
new UncheckedFunc<>(func).apply(input)
),
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/llorllale/cactoos/matchers/HasEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public final class HasEntry<K, V> extends MatcherEnvelope<Map<K, V>> {
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public HasEntry(final K key, final V value) {
super(
// @checkstyle IndentationCheck (16 lines)
input -> Optional.ofNullable(input.get(key))
.map(vl -> vl.equals(value))
.orElse(false),
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/llorllale/cactoos/matchers/HasLines.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private HasLines(
final Func<String, Collection<String>> split
) {
super(
// @checkstyle IndentationCheck (5 line)
actual -> match.apply(split.apply(actual), expected),
desc -> desc.appendText("Lines are ").appendValue(expected),
(actual, desc) -> desc.appendValue(split.apply(actual))
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/org/llorllale/cactoos/matchers/HasProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* The MIT License (MIT)
*
* Copyright (c) for portions of project cactoos-matchers are held by
* Yegor Bugayenko, 2017-2018, as part of project cactoos.
* All other copyright for project cactoos-matchers are held by
* George Aristy, 2018.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.llorllale.cactoos.matchers;

import java.util.Map;
import java.util.Properties;
import org.hamcrest.Matcher;
import org.hamcrest.core.IsAnything;
import org.hamcrest.core.IsEqual;

/**
* Matcher to check that {@link Properties} has particular entry.
*
* <p>Here is an example how {@link HasProperty} can be used:</p>
* <pre>
* new Assertion<>(
* "must have an entry",
* new PropertiesOf<>(...),
* new HasProperty<>("foo", "bar")
* );</pre>
*
* @since 1.0.0
*/
public final class HasProperty extends MatcherEnvelope<Properties> {

/**
* Ctor.
*
* @param key Literal key.
* @param value Literal value.
*/
HasProperty(final String key, final String value) {
this(new IsEqual<>(key), new IsEqual<>(value));
}

/**
* Ctor.
*
* @param key Matcher for key.
* @param value Matcher for value.
*/
public HasProperty(final Matcher<String> key, final Matcher<String> value) {
this(new IsEntry<>(key, value));
}

/**
* Ctor.
*
* @param key Literal key.
*/
public HasProperty(final String key) {
this(new IsEntry<>(new IsEqual<>(key), new IsAnything<>()));
}

/**
* Ctor.
*
* @param entr Entry matcher.
*/
private HasProperty(final Matcher<Map.Entry<String, String>> entr) {
super(
// @checkstyle IndentationCheck (10 line)
properties -> new HasValuesMatching<>(
entr::matches
).matches(properties.entrySet()),
desc -> desc
.appendText("has property ")
.appendDescriptionOf(entr),
(properties, desc) -> desc
.appendText("has properties ")
.appendValue(properties)
);
}

}
11 changes: 5 additions & 6 deletions src/main/java/org/llorllale/cactoos/matchers/HasSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ public final class HasSize extends MatcherEnvelope<Iterable<?>> {
*/
public HasSize(final Integer size) {
super(
// @checkstyle IndentationCheck (5 line)
input -> new LengthOf(input).intValue() == size,
desc -> desc.appendText("has size ")
.appendValue(size),
(input, desc) -> desc.appendText("has size ")
.appendValue(new LengthOf(input).intValue())
input -> new LengthOf(input).intValue() == size,
desc -> desc.appendText("has size ")
.appendValue(size),
(input, desc) -> desc.appendText("has size ")
.appendValue(new LengthOf(input).intValue())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public HasValues(final X... expected) {
*/
public HasValues(final Iterable<X> expected) {
super(
// @checkstyle IndentationCheck (4 line)
actual -> new ListOf<>(actual).containsAll(new ListOf<>(expected)),
desc -> desc.appendText("contains ")
.appendValue(new TextOf(expected)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public final class HasValuesMatching<X> extends MatcherEnvelope<Iterable<X>> {
*/
public HasValuesMatching(final Func<X, Boolean> fnc) {
super(
// @checkstyle IndentationCheck (7 line)
actual -> new Or(fnc, actual).value(),
desc -> desc.appendText("The function matches at least 1 element."),
(actual, desc) -> desc.appendText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
* are satisfactory. The matchers should not expose publicly the xxxSafely
* method and the tests should rely on actual real use with assertThat.
* See ScalarHasValueTest for an example of a satisfactory result.
* @todo #75:30min Remove checkstyle suppression when qulice will fix this issue
* See https://github.com/teamed/qulice/issues/985.
* When new version will be released, update qulice and remove this puzzle.
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class InputHasContent extends MatcherEnvelope<Input> {
Expand Down Expand Up @@ -72,7 +69,6 @@ public InputHasContent(final Text text) {
*/
public InputHasContent(final Matcher<String> mtr) {
super(
// @checkstyle IndentationCheck (9 line)
input -> mtr.matches(
new TextOf(input).asString()
),
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/llorllale/cactoos/matchers/IsBlank.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public final class IsBlank extends MatcherEnvelope<String> {
*/
public IsBlank() {
super(
// @checkstyle IndentationCheck (3 line)
text -> text.trim().isEmpty(),
desc -> desc.appendText("is blank"),
(text, desc) -> desc.appendValue(text)
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/org/llorllale/cactoos/matchers/IsEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* The MIT License (MIT)
*
* Copyright (c) for portions of project cactoos-matchers are held by
* Yegor Bugayenko, 2017-2018, as part of project cactoos.
* All other copyright for project cactoos-matchers are held by
* George Aristy, 2018.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.llorllale.cactoos.matchers;

import java.util.Map;
import org.cactoos.scalar.And;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.core.IsEqual;

/**
* Matcher to check that {@link Map.Entry} has particular key and value.
*
* @param <K> Type of key
* @param <V> Type of value
* @since 1.0.0
*/
public final class IsEntry<K, V> extends MatcherEnvelope<Map.Entry<K, V>> {

/**
* Ctor.
*
* @param key Literal key.
* @param value Literal value.
*/
public IsEntry(final K key, final V value) {
this(new IsEqual<>(key), new IsEqual<>(value));
}

/**
* Ctor.
*
* @param key Matcher for key.
* @param value Matcher for value.
*/
public IsEntry(final Matcher<K> key, final Matcher<V> value) {
super(
// @checkstyle IndentationCheck (20 line)
entry -> new And(
() -> key.matches(entry.getKey()),
() -> value.matches(entry.getValue())
).value(),
desc -> {
IsEntry.descriptionOfKey(desc).appendDescriptionOf(key);
IsEntry.descriptionOfValue(desc).appendDescriptionOf(value);
},
(entry, desc) -> {
IsEntry.descriptionOfKey(desc);
key.describeMismatch(entry.getKey(), desc);
IsEntry.descriptionOfValue(desc);
value.describeMismatch(entry.getValue(), desc);
}
);
}

/**
* Start describing value.
*
* @param desc Description.
* @return Altered description
*/
private static Description descriptionOfValue(final Description desc) {
return desc.appendText(", value ");
}

/**
* Start describing key.
*
* @param desc Description.
* @return Altered description
*/
private static Description descriptionOfKey(final Description desc) {
return desc.appendText("key ");
}
}
1 change: 0 additions & 1 deletion src/main/java/org/llorllale/cactoos/matchers/IsTrue.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public final class IsTrue extends MatcherEnvelope<Boolean> {
*/
public IsTrue() {
super(
// @checkstyle IndentationCheck (3 line)
bool -> bool,
desc -> desc.appendValue(true),
(bool, desc) -> desc.appendValue(bool)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public MatcherOf(final Func<T, Boolean> fnc) {
*/
public MatcherOf(final Func<T, Boolean> fnc, final Text description) {
super(
// @checkstyle IndentationCheck (5 line)
fnc,
desc -> desc.appendText(
new FormattedText("\"%s\"", description).asString()
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ public final class MatchesBefore<T> extends MatcherEnvelope<T> {
*/
public MatchesBefore(final long millisec, final Matcher<T> matcher) {
super(
// @checkstyle IndentationCheck (6 line)
new Timed<>(matcher::matches, millisec),
desc -> desc
.appendDescriptionOf(matcher)
.appendText(" runs in less than ")
.appendValue(millisec).appendText(" milliseconds"),
matcher::describeMismatch
new Timed<>(matcher::matches, millisec),
desc -> desc
.appendDescriptionOf(matcher)
.appendText(" runs in less than ")
.appendValue(millisec).appendText(" milliseconds"),
matcher::describeMismatch
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public RunsInThreads(final T object) {
/**
* Ctor.
* @param object Input object
* @param threads Size of thread pool
*/
public RunsInThreads(final T object, final int threads) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ public ScalarHasValue(final T value) {
*/
public ScalarHasValue(final Matcher<T> mtr) {
super(
// @checkstyle IndentationCheck (3 line)
scalar -> mtr.matches(scalar.value()),
desc -> desc.appendText("Scalar with ").appendDescriptionOf(mtr),
(scalar, desc) -> desc.appendValue(scalar.value())
(scalar, desc) -> mtr.describeMismatch(scalar.value(), desc)
);
}
}
Loading

0 comments on commit 7ebaceb

Please sign in to comment.