Skip to content

Commit

Permalink
(#1391) - Remove some more MatcherAssert
Browse files Browse the repository at this point in the history
  • Loading branch information
victornoel committed May 19, 2020
1 parent 47cd894 commit 39e2635
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 57 deletions.
32 changes: 19 additions & 13 deletions src/test/java/org/cactoos/scalar/EqualityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.cactoos.scalar;

import org.cactoos.Bytes;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.ScalarHasValue;

/**
Expand All @@ -38,62 +38,68 @@ public final class EqualityTest {

@Test
public void notEqualLeft() throws Exception {
MatcherAssert.assertThat(
new Assertion<>(
"Must compare smaller to greater",
new Equality<>(
new EqualityTest.Letters("A"), new EqualityTest.Letters("AB")
),
new ScalarHasValue<>(-1)
);
).affirm();
}

@Test
public void notEqualRight() throws Exception {
MatcherAssert.assertThat(
new Assertion<>(
"Must compare greater to smaller",
new Equality<>(
new EqualityTest.Letters("AB"), new EqualityTest.Letters("A")
),
new ScalarHasValue<>(1)
);
).affirm();
}

@Test
public void notEqualLeftWithSameSize() throws Exception {
MatcherAssert.assertThat(
new Assertion<>(
"Must compare smaller to smaller with same size",
new Equality<>(
new EqualityTest.Letters("A"), new EqualityTest.Letters("B")
),
new ScalarHasValue<>(-1)
);
).affirm();
}

@Test
public void notEqualRightWithSameSize() throws Exception {
MatcherAssert.assertThat(
new Assertion<>(
"Must compare greater to smaller with same size",
new Equality<>(
new EqualityTest.Letters("B"), new EqualityTest.Letters("A")
),
new ScalarHasValue<>(1)
);
).affirm();
}

@Test
public void equal() throws Exception {
MatcherAssert.assertThat(
new Assertion<>(
"Must compare equals",
new Equality<>(
new EqualityTest.Letters("A"), new EqualityTest.Letters("A")
),
new ScalarHasValue<>(0)
);
).affirm();
}

@Test
public void compareEmptyArrays() throws Exception {
MatcherAssert.assertThat(
new Assertion<>(
"Must compare empty",
new Equality<>(
new EqualityTest.Letters(""), new EqualityTest.Letters("")
),
new ScalarHasValue<>(0)
);
).affirm();
}

/**
Expand Down
21 changes: 10 additions & 11 deletions src/test/java/org/cactoos/scalar/FallbackFromTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,51 @@
import java.io.IOException;
import java.util.IllegalFormatException;
import org.cactoos.iterable.IterableOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link FallbackFrom}.
*
* @since 0.31
* @checkstyle JavadocMethodCheck (500 lines)
*/
@SuppressWarnings("unchecked")
public final class FallbackFromTest {

@Test
public void supportsException() {
MatcherAssert.assertThat(
"IOException class is not supported, but should be",
new Assertion<>(
"Must support IOException class",
new FallbackFrom<>(
new IterableOf<>(IOException.class),
exp -> "IOException fallback"
).support(IOException.class),
new IsEqual<>(0)
);
).affirm();
}

@Test
public void supportsInheritedException() {
MatcherAssert.assertThat(
"RuntimeException class is not supported, but should be",
new Assertion<>(
"Must support RuntimeException class",
new FallbackFrom<>(
new IterableOf<>(RuntimeException.class),
exp -> "RuntimeException fallback #1"
).support(IllegalFormatException.class),
new IsEqual<>(2)
);
).affirm();
}

@Test
public void doesNotSupportException() {
MatcherAssert.assertThat(
"RuntimeException class is supported, but should not be",
new Assertion<>(
"Must support RuntimeException class",
new FallbackFrom<>(
new IterableOf<>(RuntimeException.class),
exp -> "RuntimeException fallback #2"
).support(ClassNotFoundException.class),
new IsEqual<>(Integer.MIN_VALUE)
);
).affirm();
}
}
20 changes: 15 additions & 5 deletions src/test/java/org/cactoos/scalar/FalseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
*/
package org.cactoos.scalar;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.ScalarHasValue;

/**
* Test case for {@link False}.
Expand All @@ -37,10 +38,19 @@ public final class FalseTest {

@Test
public void asValue() throws Exception {
MatcherAssert.assertThat(
new Assertion<>(
"Must return false",
new False().value(),
Matchers.equalTo(false)
);
new IsEqual<>(false)
).affirm();
}

@Test
public void asScalar() throws Exception {
new Assertion<>(
"Must be false",
new False(),
new ScalarHasValue<>(false)
).affirm();
}
}
57 changes: 33 additions & 24 deletions src/test/java/org/cactoos/scalar/IoCheckedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
package org.cactoos.scalar;

import java.io.IOException;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.Throws;

/**
* Test case for {@link IoChecked}.
Expand All @@ -39,36 +39,45 @@ public final class IoCheckedTest {
@Test
public void rethrowsIoException() {
final IOException exception = new IOException("intended");
try {
new IoChecked<>(
new Assertion<>(
"Must rethrow IOException",
() -> new IoChecked<>(
() -> {
throw exception;
}
).value();
} catch (final IOException ex) {
MatcherAssert.assertThat(
ex, Matchers.is(exception)
);
}
).value(),
new Throws<>("intended", IOException.class)
).affirm();
}

@Test
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
@Test(expected = IOException.class)
public void throwsException() throws Exception {
new IoChecked<>(
() -> {
throw new Exception("intended to fail");
}
).value();
public void throwsException() {
new Assertion<>(
"Must throw IOException from Exception",
() -> new IoChecked<>(
() -> {
throw new Exception("intended to fail");
}
).value(),
new Throws<>(IOException.class)
).affirm();
}

@Test(expected = IllegalStateException.class)
public void runtimeExceptionGoesOut() throws IOException {
new IoChecked<>(
() -> {
throw new IllegalStateException("intended to fail here");
}
).value();
@Test
public void runtimeExceptionGoesOut() {
new Assertion<>(
"Must rethrow RuntimeExcepion",
() -> new IoChecked<>(
() -> {
throw new IllegalStateException("intended to fail here");
}
).value(),
new Throws<>(
"intended to fail here",
IllegalStateException.class
)
).affirm();
}

}
8 changes: 4 additions & 4 deletions src/test/java/org/cactoos/scalar/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
/**
* Scalars, tests.
*
* @todo #1389:30min Continue replacing usage of MatcherAssert.assertThat with
* Assertion from cactoos-matchers. Once there is no more usage of
* MatcherAssert.assertThat, add the signature of MatcherAssert.assertThat to
* forbidden-apis.txt
* @todo #1391:30min Continue replacing usage of MatcherAssert.assertThat with
* Assertion from cactoos-matchers in this package as well as in other packages.
* Once there is no more usage of MatcherAssert.assertThat, add the signature
* of MatcherAssert.assertThat to forbidden-apis.txt
* @since 0.12
*/
package org.cactoos.scalar;

0 comments on commit 39e2635

Please sign in to comment.