Skip to content

Commit

Permalink
(yegor256#1396) Inline three argument assertThat
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Jun 22, 2020
1 parent ece6633 commit c10ad65
Show file tree
Hide file tree
Showing 51 changed files with 694 additions and 695 deletions.
34 changes: 17 additions & 17 deletions src/test/java/org/cactoos/func/FuncWithFallbackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.io.IOException;
import java.util.IllegalFormatException;
import java.util.IllegalFormatWidthException;
import org.cactoos.MatcherAssert;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.FallbackFrom;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.FuncApplies;

/**
Expand All @@ -44,57 +44,57 @@ public final class FuncWithFallbackTest {
@Test
public void usesMainFunc() throws Exception {
final String expected = "It's success";
MatcherAssert.assertThat(
new Assertion<>(
"Can't use the main function if no exception",
new FuncWithFallback<>(
new FuncWithFallback<Integer, String>(
input -> expected,
new FallbackFrom<>(
Exception.class,
ex -> "In case of failure..."
)
),
new FuncApplies<>(1, expected)
);
new FuncApplies<Integer, String>(1, expected)
).affirm();
}

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

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

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

@Test(expected = Exception.class)
Expand Down
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 @@ -26,10 +26,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import org.cactoos.MatcherAssert;
import org.cactoos.text.FormattedText;
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();
}
}
28 changes: 14 additions & 14 deletions src/test/java/org/cactoos/func/RunnableOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.cactoos.func;

import java.util.concurrent.atomic.AtomicBoolean;
import org.cactoos.MatcherAssert;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.MatcherOf;

/**
Expand All @@ -39,29 +39,29 @@ public final class RunnableOfTest {
@Test
public void convertsFuncIntoRunnable() {
final AtomicBoolean done = new AtomicBoolean();
MatcherAssert.assertThat(
new Assertion<>(
"Can't execute Runnable with Func",
new RunnableOf<>(
new RunnableOf<Object>(
input -> {
done.set(true);
return 1;
}
),
new MatcherOf<Runnable>(
input -> {
input.run();
input1 -> {
input1.run();
return done.get();
}
)
);
).affirm();
}

@Test
public void convertsProcIntoRunnable() {
final AtomicBoolean done = new AtomicBoolean();
MatcherAssert.assertThat(
new Assertion<>(
"Can't execute Runnable with ProcOf",
new RunnableOf<>(
new RunnableOf<Object>(
new ProcOf<>(
input -> {
done.set(true);
Expand All @@ -70,20 +70,20 @@ public void convertsProcIntoRunnable() {
)
),
new MatcherOf<Runnable>(
input -> {
input.run();
input1 -> {
input1.run();
return done.get();
}
)
);
).affirm();
}

@Test
public void convertsCallableIntoRunnable() {
final AtomicBoolean done = new AtomicBoolean();
MatcherAssert.assertThat(
new Assertion<>(
"Can't execute Runnable with Callable",
new RunnableOf<>(
new RunnableOf<Object>(
() -> {
done.set(true);
return null;
Expand All @@ -95,7 +95,7 @@ public void convertsCallableIntoRunnable() {
return done.get();
}
)
);
).affirm();
}

}
17 changes: 9 additions & 8 deletions src/test/java/org/cactoos/func/SolidBiFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import java.security.SecureRandom;
import org.cactoos.BiFunc;
import org.cactoos.Func;
import org.cactoos.MatcherAssert;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.RunsInThreads;

/**
Expand All @@ -49,19 +50,19 @@ public void testThatFuncIsSynchronized() {
return true;
}
);
MatcherAssert.assertThat(
new Assertion<>(
"SolidBiFunc can't work properly in concurrent threads.",
func -> func.apply(true),
new RunsInThreads<>(
(Matcher<Func<Func<Boolean, Boolean>, Boolean>>) new RunsInThreads<Func<Boolean, Boolean>>(
(Func<Boolean, Boolean>) input -> testable.apply(1, 1),
threads
)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"Shared resource has been modified by multiple threads.",
shared[0],
Matchers.is(1)
);
).affirm();
}

@Test
Expand All @@ -71,10 +72,10 @@ public void testThatFuncResultCacheIsLimited() throws Exception {
(first, second) -> new SecureRandom().nextInt(),
1
);
MatcherAssert.assertThat(
new Assertion<>(
"Result of (0, 0) call wasn't invalidated.",
func.apply(0, 0) + func.apply(1, 1),
Matchers.not(func.apply(1, 1) + func.apply(0, 0))
);
).affirm();
}
}
7 changes: 3 additions & 4 deletions src/test/java/org/cactoos/func/SolidFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.security.SecureRandom;
import org.cactoos.Func;
import org.cactoos.MatcherAssert;
import org.cactoos.list.ListOf;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -54,7 +53,7 @@ public void cachesFuncResults() throws Exception {

@Test
public void worksInThreads() {
MatcherAssert.assertThat(
new Assertion<>(
"Can't work well in multiple threads",
func -> {
new Assertion<>(
Expand All @@ -64,10 +63,10 @@ public void worksInThreads() {
).affirm();
return true;
},
new RunsInThreads<>(
new RunsInThreads<SolidFunc<Object, ListOf<Integer>>>(
new SolidFunc<>(x -> new ListOf<>(1, 2))
)
);
).affirm();
}

}
Loading

0 comments on commit c10ad65

Please sign in to comment.