Skip to content

Commit

Permalink
(yegor256#1396) Inline two argument assertThat
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Jun 22, 2020
1 parent 9f688d1 commit 8370d24
Show file tree
Hide file tree
Showing 31 changed files with 369 additions and 249 deletions.
9 changes: 1 addition & 8 deletions src/test/java/org/cactoos/MatcherAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@ public final class MatcherAssert {
private MatcherAssert() {
}

public static <T> void assertThat(final T actual,
final Matcher<? super T> matcher) {
MatcherAssert.assertThat(
"", actual, matcher
);
}

public static <T> void assertThat(final String desc,
final T actual, final Matcher<? super T> matcher) {
final T actual, final Matcher<T> matcher) {
new Assertion<>(
desc,
actual,
Expand Down
10 changes: 6 additions & 4 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.cactoos.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link IoCheckedBiFunc}.
Expand All @@ -45,9 +45,11 @@ public void rethrowsIoException() {
}
).apply(1, 2);
} catch (final IOException ex) {
MatcherAssert.assertThat(
ex, Matchers.is(exception)
);
new Assertion<>(
"",
ex,
Matchers.is(exception)
).affirm();
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/cactoos/func/IoCheckedFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

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

/**
* Test case for {@link IoCheckedFunc}.
Expand All @@ -47,9 +47,11 @@ public void rethrowsIoException() {
}
).apply(1);
} catch (final IOException ex) {
MatcherAssert.assertThat(
ex, Matchers.is(exception)
);
new Assertion<>(
"",
ex,
Matchers.is(exception)
).affirm();
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/cactoos/func/IoCheckedProcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
package org.cactoos.func;

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

/**
* Test case for {@link IoCheckedProc}.
Expand All @@ -46,9 +46,11 @@ public void rethrowsIoException() {
}
).exec(1);
} catch (final IOException ex) {
MatcherAssert.assertThat(
ex, Matchers.is(exception)
);
new Assertion<>(
"",
ex,
Matchers.is(exception)
).affirm();
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/test/java/org/cactoos/func/RepeatedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.security.SecureRandom;
import java.util.Iterator;
import org.cactoos.Func;
import org.cactoos.MatcherAssert;
import org.cactoos.iterator.IteratorOf;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link Repeated}.
Expand All @@ -49,10 +49,11 @@ public void runsFuncMultipleTimes() throws Exception {
},
3
);
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true),
Matchers.equalTo(5)
);
).affirm();
}

@Test
Expand All @@ -63,10 +64,11 @@ public void repeatsNullsResults() throws Exception {
},
2
);
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true),
Matchers.equalTo(null)
);
).affirm();
}

@Test(expected = IllegalArgumentException.class)
Expand All @@ -77,9 +79,10 @@ public void doesntRepeatAny() throws Exception {
},
0
);
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true),
Matchers.equalTo(func.apply(true))
);
).affirm();
}
}
11 changes: 7 additions & 4 deletions src/test/java/org/cactoos/func/SolidFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.cactoos.list.ListOf;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.RunsInThreads;

/**
Expand All @@ -44,21 +45,23 @@ public void cachesFuncResults() throws Exception {
final Func<Boolean, Integer> func = new SolidFunc<>(
input -> new SecureRandom().nextInt()
);
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true) + func.apply(true),
Matchers.equalTo(func.apply(true) + func.apply(true))
);
).affirm();
}

@Test
public void worksInThreads() {
MatcherAssert.assertThat(
"Can't work well in multiple threads",
func -> {
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true),
Matchers.equalTo(func.apply(true))
);
).affirm();
return true;
},
new RunsInThreads<>(
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/cactoos/func/StickyBiFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

import java.security.SecureRandom;
import org.cactoos.BiFunc;
import org.cactoos.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link StickyBiFunc}.
Expand All @@ -41,10 +41,11 @@ public void cachesFuncResults() throws Exception {
final BiFunc<Boolean, Boolean, Integer> func = new StickyBiFunc<>(
(first, second) -> new SecureRandom().nextInt()
);
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true, true) + func.apply(true, true),
Matchers.equalTo(func.apply(true, true) + func.apply(true, true))
);
).affirm();
}

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

import java.security.SecureRandom;
import org.cactoos.Func;
import org.cactoos.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link StickyFunc}.
Expand All @@ -42,10 +42,11 @@ public void cachesFuncResults() throws Exception {
final Func<Boolean, Integer> func = new StickyFunc<>(
input -> new SecureRandom().nextInt()
);
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true) + func.apply(true),
Matchers.equalTo(func.apply(true) + func.apply(true))
);
).affirm();
}

@Test
Expand All @@ -55,26 +56,29 @@ public void cachesWithLimitedBuffer() throws Exception {
);
final int first = func.apply(0);
final int second = func.apply(1);
MatcherAssert.assertThat(
new Assertion<>(
"",
first + second,
Matchers.equalTo(func.apply(0) + func.apply(1))
);
).affirm();
final int third = func.apply(-1);
MatcherAssert.assertThat(
new Assertion<>(
"",
second + third,
Matchers.equalTo(func.apply(1) + func.apply(-1))
);
).affirm();
}

@Test
public void cachesWithZeroBuffer() throws Exception {
final Func<Boolean, Integer> func = new StickyFunc<>(
input -> new SecureRandom().nextInt(), 0
);
MatcherAssert.assertThat(
new Assertion<>(
"",
func.apply(true) + func.apply(true),
Matchers.not(Matchers.equalTo(func.apply(true) + func.apply(true)))
);
).affirm();
}

}
25 changes: 21 additions & 4 deletions src/test/java/org/cactoos/func/SyncFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cactoos.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.RunsInThreads;

/**
Expand All @@ -54,7 +55,11 @@ public void funcWorksInThreads() {
threads
)
);
MatcherAssert.assertThat(list.size(), Matchers.equalTo(threads));
new Assertion<>(
"",
list.size(),
Matchers.equalTo(threads)
).affirm();
}

@Test
Expand All @@ -74,7 +79,11 @@ public void procWorksInThreads() {
threads
)
);
MatcherAssert.assertThat(counter[0], Matchers.equalTo(threads));
new Assertion<>(
"",
counter[0],
Matchers.equalTo(threads)
).affirm();
}

@Test
Expand All @@ -94,7 +103,11 @@ public void callableWorksInThreads() {
threads
)
);
MatcherAssert.assertThat(counter[0], Matchers.equalTo(threads));
new Assertion<>(
"",
counter[0],
Matchers.equalTo(threads)
).affirm();
}

@Test
Expand All @@ -112,6 +125,10 @@ public void runnableWorksInThreads() {
threads
)
);
MatcherAssert.assertThat(counter[0], Matchers.equalTo(threads));
new Assertion<>(
"",
counter[0],
Matchers.equalTo(threads)
).affirm();
}
}
12 changes: 7 additions & 5 deletions src/test/java/org/cactoos/func/TimedFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import org.cactoos.MatcherAssert;
import org.cactoos.iterable.Endless;
import org.cactoos.scalar.And;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link Timed}.
Expand Down Expand Up @@ -71,23 +71,25 @@ public void futureTaskIsCancelled() {
).apply(true);
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception exp) {
MatcherAssert.assertThat(
new Assertion<>(
"",
future.isCancelled(),
Matchers.equalTo(true)
);
).affirm();
}
}

@Test
public void functionIsExecuted() throws Exception {
final long period = 3000L;
MatcherAssert.assertThat(
new Assertion<>(
"",
new Timed<Boolean, Boolean>(
input -> true,
period
).apply(true),
Matchers.equalTo(true)
);
).affirm();
}
}

7 changes: 4 additions & 3 deletions src/test/java/org/cactoos/func/UncheckedBiFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

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

/**
* Test case for {@link UncheckedBiFunc}.
Expand All @@ -47,12 +47,13 @@ public void rethrowsCheckedToUncheckedException() {

@Test
public void testUncheckedBiFunc() {
MatcherAssert.assertThat(
new Assertion<>(
"",
new UncheckedBiFunc<>(
(fst, scd) -> true
).apply(1, 2),
Matchers.equalTo(true)
);
).affirm();
}

@Test(expected = IllegalStateException.class)
Expand Down
Loading

0 comments on commit 8370d24

Please sign in to comment.