Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some more MatcherAssert #1393

Merged
merged 1 commit into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 10 additions & 10 deletions src/test/java/org/cactoos/scalar/FallbackFromTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
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}.
Expand All @@ -41,37 +41,37 @@ public final class FallbackFromTest {

@Test
public void supportsException() {
MatcherAssert.assertThat(
"IOException class is not supported, but should be",
new Assertion<>(
"Must support exactly exception class",
new FallbackFrom<>(
new IterableOf<>(IOException.class),
Copy link
Contributor

Choose a reason for hiding this comment

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

@victornoel error log: unchecked generic array creation for varargs parameter of type java.lang.Class<? extends java.lang.Throwable>[]

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 inherited exception class",
new FallbackFrom<>(
new IterableOf<>(RuntimeException.class),
Copy link
Contributor

Choose a reason for hiding this comment

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

@victornoel error log: unchecked generic array creation for varargs parameter of type java.lang.Class<? extends java.lang.Throwable>[]

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 not support unrelated exception class",
new FallbackFrom<>(
new IterableOf<>(RuntimeException.class),
Copy link
Contributor

Choose a reason for hiding this comment

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

@victornoel error log: unchecked generic array creation for varargs parameter of type java.lang.Class<? extends java.lang.Throwable>[]

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();
}
}
55 changes: 31 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,43 @@ 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<>(exception.getMessage(), exception.getClass())
).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() {
final RuntimeException exception = new IllegalStateException("intended to fail here");
new Assertion<>(
"Must rethrow RuntimeExcepion",
() -> new IoChecked<>(
() -> {
throw exception;
}
).value(),
new Throws<>(exception.getMessage(), exception.getClass())
).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;