Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 24, 2020
2 parents 3843e86 + 787d258 commit 9a1dc05
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 56 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
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),
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),
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),
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;

2 comments on commit 9a1dc05

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 9a1dc05 May 24, 2020

Choose a reason for hiding this comment

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

Puzzle 1389-b5541bca disappeared from src/test/java/org/cactoos/scalar/package-info.java, that's why I closed #1391. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 9a1dc05 May 24, 2020

Choose a reason for hiding this comment

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

Puzzle 1391-715b3f6c discovered in src/test/java/org/cactoos/scalar/package-info.java and submitted as #1396. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.