Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 17, 2020
2 parents 033b34e + 39dbbf4 commit de9e21d
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 171 deletions.
2 changes: 0 additions & 2 deletions src/main/java/org/cactoos/iterable/IterableOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
import org.cactoos.iterator.IteratorOf;
import org.cactoos.scalar.And;
import org.cactoos.scalar.FallbackFrom;
import org.cactoos.scalar.False;
import org.cactoos.scalar.Folded;
import org.cactoos.scalar.Or;
import org.cactoos.scalar.ScalarWithFallback;
import org.cactoos.scalar.Sticky;
import org.cactoos.scalar.SumOfInt;
import org.cactoos.scalar.True;
import org.cactoos.scalar.Unchecked;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/cactoos/list/Shuffled.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.cactoos.list;

import java.util.Collections;
import java.util.List;

/**
* Shuffled list.
Expand Down
27 changes: 14 additions & 13 deletions src/test/java/org/cactoos/func/FuncWithFallbackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@
import java.util.IllegalFormatWidthException;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.FallbackFrom;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.FuncApplies;

/**
* Test case for {@link FuncWithFallback}.
*
* @since 0.2
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
@SuppressWarnings("unchecked")
public final class FuncWithFallbackTest {

@Test
public void usesMainFunc() throws Exception {
public void usesMainFunc() {
final String expected = "It's success";
MatcherAssert.assertThat(
new Assertion<>(
"Can't use the main function if no exception",
new FuncWithFallback<>(
input -> expected,
Expand All @@ -54,13 +55,13 @@ public void usesMainFunc() throws Exception {
)
),
new FuncApplies<>(1, expected)
);
).affirm();
}

@Test
public void usesFallback() throws Exception {
public void usesFallback() {
final String expected = "Never mind";
MatcherAssert.assertThat(
new Assertion<>(
"Can't use the callback in case of exception",
new FuncWithFallback<>(
input -> {
Expand All @@ -69,13 +70,13 @@ public void usesFallback() throws Exception {
new FallbackFrom<>(IOException.class, ex -> expected)
),
new FuncApplies<>(1, expected)
);
).affirm();
}

@Test
public void usesFallbackOfInterruptedException() throws Exception {
public void usesFallbackOfInterruptedException() {
final String expected = "Fallback from InterruptedException";
MatcherAssert.assertThat(
new Assertion<>(
"Can't use a fallback from Interrupted in case of exception",
new FuncWithFallback<>(
input -> {
Expand All @@ -86,13 +87,13 @@ public void usesFallbackOfInterruptedException() throws Exception {
new FallbackFrom<>(InterruptedException.class, exp -> expected)
),
new FuncApplies<>(1, expected)
);
).affirm();
}

@Test
public void usesTheClosestFallback() throws Exception {
public void usesTheClosestFallback() {
final String expected = "Fallback from IllegalFormatException";
MatcherAssert.assertThat(
new Assertion<>(
"Can't find the closest fallback",
new FuncWithFallback<>(
input -> {
Expand All @@ -110,7 +111,7 @@ public void usesTheClosestFallback() throws Exception {
)
),
new FuncApplies<>(1, expected)
);
).affirm();
}

@Test(expected = Exception.class)
Expand Down
21 changes: 11 additions & 10 deletions src/test/java/org/cactoos/func/IoCheckedBiFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
package org.cactoos.func;

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 IoCheckedBiFunc}.
Expand All @@ -38,17 +38,18 @@ public final class IoCheckedBiFuncTest {
@Test
public void rethrowsIoException() {
final IOException exception = new IOException("intended");
try {
new IoCheckedBiFunc<>(
new Assertion<>(
"Must rethrow IOException",
() -> new IoCheckedBiFunc<>(
(fst, scd) -> {
throw exception;
}
).apply(1, 2);
} catch (final IOException ex) {
MatcherAssert.assertThat(
ex, Matchers.is(exception)
);
}
).apply(1, 2),
new Throws<>(
exception.getMessage(),
exception.getClass()
)
).affirm();
}

@Test(expected = IOException.class)
Expand Down
64 changes: 38 additions & 26 deletions src/test/java/org/cactoos/func/IoCheckedFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
package org.cactoos.func;

import java.io.IOException;
import org.cactoos.Func;
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 IoCheckedFunc}.
Expand All @@ -40,35 +39,48 @@ public final class IoCheckedFuncTest {
@Test
public void rethrowsIoException() {
final IOException exception = new IOException("intended");
try {
new IoCheckedFunc<>(
(Func<Integer, String>) i -> {
new Assertion<>(
"Must rethrow original IOException",
() -> new IoCheckedFunc<>(
i -> {
throw exception;
}
).apply(1);
} catch (final IOException ex) {
MatcherAssert.assertThat(
ex, Matchers.is(exception)
);
}
).apply(1),
new Throws<>(
exception.getMessage(),
exception.getClass()
)
).affirm();
}

@Test(expected = IOException.class)
public void rethrowsCheckedToIoException() throws Exception {
new IoCheckedFunc<>(
i -> {
throw new IOException("intended to fail");
}
).apply(1);
@Test
public void rethrowsCheckedToIoException() {
new Assertion<>(
"Must rethrow as IOException",
() -> new IoCheckedFunc<>(
i -> {
throw new InterruptedException("intended to fail");
}
).apply(1),
new Throws<>(
IOException.class
)
).affirm();
}

@Test(expected = IllegalStateException.class)
public void runtimeExceptionGoesOut() throws IOException {
new IoCheckedFunc<>(
i -> {
throw new IllegalStateException("intended to fail here");
}
).apply(1);
@Test
public void runtimeExceptionGoesOut() {
new Assertion<>(
"Must throw runtime exception as is",
() -> new IoCheckedFunc<>(
i -> {
throw new IllegalStateException("intended to fail here");
}
).apply(1),
new Throws<>(
IllegalStateException.class
)
).affirm();
}

}
69 changes: 42 additions & 27 deletions src/test/java/org/cactoos/func/IoCheckedProcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

import java.io.IOException;
import org.cactoos.Proc;
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 IoCheckedProc}.
Expand All @@ -39,35 +39,50 @@ public final class IoCheckedProcTest {
@Test
public void rethrowsIoException() {
final IOException exception = new IOException("intended");
try {
new IoCheckedProc<>(
(Proc<Integer>) i -> {
throw exception;
}
).exec(1);
} catch (final IOException ex) {
MatcherAssert.assertThat(
ex, Matchers.is(exception)
);
}
new Assertion<>(
"Must rethrow original IOException",
() -> {
new IoCheckedProc<>(
(Proc<Integer>) i -> {
throw exception;
}
).exec(1);
return null;
},
new Throws<>(exception.getMessage(), exception.getClass())
).affirm();
}

@Test(expected = IOException.class)
public void rethrowsCheckedToIoException() throws Exception {
new IoCheckedProc<>(
i -> {
throw new InterruptedException("intended to fail");
}
).exec(1);
@Test
public void rethrowsCheckedToIoException() {
new Assertion<>(
"Must wrap and throw IOException",
() -> {
new IoCheckedProc<>(
(Proc<Integer>) i -> {
throw new InterruptedException("intended to fail");
}
).exec(1);
return null;
},
new Throws<>(IOException.class)
).affirm();
}

@Test(expected = IllegalStateException.class)
public void runtimeExceptionGoesOut() throws IOException {
new IoCheckedProc<>(
i -> {
throw new IllegalStateException("intended to fail here");
}
).exec(1);
@Test
public void runtimeExceptionGoesOut() {
new Assertion<>(
"Must throw runtime exceptions as is",
() -> {
new IoCheckedProc<>(
i -> {
throw new IllegalStateException("intended to fail here");
}
).exec(1);
return null;
},
new Throws<>(IllegalStateException.class)
).affirm();
}

}
14 changes: 7 additions & 7 deletions src/test/java/org/cactoos/func/ProcOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import java.util.List;
import java.util.concurrent.Callable;
import org.cactoos.text.FormattedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link ProcOf}.
Expand All @@ -51,14 +51,14 @@ public void run() {
}
}
).exec("You can use any input in a Runnable.");
MatcherAssert.assertThat(
new Assertion<>(
new FormattedText(
"Wrong result when created with a Runnable. Expected %s",
str
).asString(),
list,
Matchers.contains(str)
);
).affirm();
}

@Test
Expand All @@ -74,14 +74,14 @@ public String call() throws Exception {
}
}
).exec("You can use any input in a Callable");
MatcherAssert.assertThat(
new Assertion<>(
new FormattedText(
"Wrong result when created with a Callable. Expected %s",
str
).asString(),
list,
Matchers.contains(str)
);
).affirm();
}

@Test
Expand All @@ -94,13 +94,13 @@ public void worksWithFunc() throws Exception {
return list.size();
}
).exec(str);
MatcherAssert.assertThat(
new Assertion<>(
new FormattedText(
"Wrong result when created with a Func. Expected %s",
str
).asString(),
list,
Matchers.contains(str)
);
).affirm();
}
}
Loading

2 comments on commit de9e21d

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on de9e21d Jul 17, 2020

Choose a reason for hiding this comment

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

Puzzle 1391-715b3f6c disappeared from src/test/java/org/cactoos/scalar/package-info.java, that's why I closed #1396. 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 de9e21d Jul 17, 2020

Choose a reason for hiding this comment

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

Puzzle 1396-59819ae3 discovered in src/test/java/org/cactoos/package-info.java and submitted as #1420. 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.