Skip to content

Commit

Permalink
(#121) Replacing randomized test values with fixed ones; fixing style
Browse files Browse the repository at this point in the history
  • Loading branch information
scristalli committed Jun 28, 2019
1 parent 996efc5 commit a8e6481
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@

package org.llorllale.cactoos.matchers;

import java.util.Random;
import org.cactoos.BiProc;
import org.cactoos.Func;
import org.cactoos.Proc;
import org.cactoos.text.Randomized;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
Expand All @@ -47,20 +45,20 @@
public final class MatcherEnvelopeTest {

/**
* A rule for handling an exception.
* Test integer to use in tests.
*/
@Rule
public final ExpectedException exception = ExpectedException.none();
private static final Integer TEST_INTEGER = 42;

/**
* Randomized test integer to use in tests.
* Test string to use in tests.
*/
private final Integer testinteger = new Random().nextInt();
private static final String TEST_STRING = "TestString";

/**
* Randomized test string to use in tests.
* A rule for handling an exception.
*/
private final String teststring = new Randomized().asString();
@Rule
public final ExpectedException exception = ExpectedException.none();

/**
* Tests that MatcherEnvelope delegates matchesSafely to the encapsulated
Expand All @@ -70,7 +68,7 @@ public final class MatcherEnvelopeTest {
public void decoratesMatchesSafely() {
new Assertion<>(
"must delegate match to encapsulated matcher",
this.testinteger,
MatcherEnvelopeTest.TEST_INTEGER,
new MatcherEnvelopeChild<>(new EncapsulatedTestMatcher())
).affirm();
}
Expand All @@ -83,11 +81,11 @@ public void decoratesMatchesSafely() {
public void decoratesDescribeTo() {
this.exception.expect(AssertionError.class);
this.exception.expectMessage(
this.testinteger.toString()
MatcherEnvelopeTest.TEST_INTEGER.toString()
);
new Assertion<>(
"must delegate describeTo to encapsulated matcher",
this.testinteger + 1,
MatcherEnvelopeTest.TEST_INTEGER + 1,
new MatcherEnvelopeChild<>(new EncapsulatedTestMatcher())
).affirm();
}
Expand All @@ -101,15 +99,17 @@ public void decoratesDescribeTo() {
public void decoratesDescribeMismatchSafely() {
this.exception.expect(AssertionError.class);
this.exception.expectMessage(
this.teststring
MatcherEnvelopeTest.TEST_STRING
);
new Assertion<>(
"must delegate describeMismatchSafely to encapsulated matcher",
this.testinteger,
MatcherEnvelopeTest.TEST_INTEGER,
new MatcherEnvelopeChild<>(
(item) -> false,
(description) -> { },
(item, description) -> description.appendText(this.teststring)
(item, description) -> description.appendText(
MatcherEnvelopeTest.TEST_STRING
)
)).affirm();
}

Expand Down Expand Up @@ -149,12 +149,12 @@ private class MatcherEnvelopeChild<T> extends MatcherEnvelope<T> {
private class EncapsulatedTestMatcher extends TypeSafeMatcher<Integer> {
@Override
public void describeTo(final Description description) {
description.appendValue(MatcherEnvelopeTest.this.testinteger);
description.appendValue(MatcherEnvelopeTest.TEST_INTEGER);
}

@Override
protected boolean matchesSafely(final Integer integer) {
return integer.equals(MatcherEnvelopeTest.this.testinteger);
return integer.equals(MatcherEnvelopeTest.TEST_INTEGER);
}
}
}

0 comments on commit a8e6481

Please sign in to comment.