Skip to content

Commit

Permalink
Refactored RetryTest (yegor256#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Feb 2, 2019
1 parent 626da1f commit de50fbf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/test/java/org/cactoos/func/RetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
package org.cactoos.func;

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

/**
* Test case for {@link Retry}.
Expand All @@ -39,34 +39,36 @@
public final class RetryTest {

@Test
public void runsFuncMultipleTimes() throws Exception {
MatcherAssert.assertThat(
new Retry<>(
public void runsFuncMultipleTimes() {
new Assertion<>(
"Didn't run multiple times",
() -> new Retry<>(
input -> {
if (new SecureRandom().nextDouble() > 0.3d) {
throw new IllegalArgumentException("May happen");
}
return 0;
},
Integer.MAX_VALUE
).apply(true),
Matchers.equalTo(0)
);
),
new FuncApplies<>(true, 0)
).affirm();
}

@Test
public void runsFuncConditionMultipleTimes() throws Exception {
MatcherAssert.assertThat(
new Retry<>(
public void runsFuncConditionMultipleTimes() {
new Assertion<>(
"Didn't check condition multiple times",
() -> new Retry<>(
input -> {
if (new SecureRandom().nextDouble() > 0.3d) {
throw new IllegalArgumentException("May happen");
}
return true;
},
count -> count == Integer.MAX_VALUE
).apply(true),
Matchers.equalTo(true)
);
),
new FuncApplies<>(true, true)
).affirm();
}
}

0 comments on commit de50fbf

Please sign in to comment.