use of org.llorllale.cactoos.matchers.HasValue in project cactoos by yegor256.
the class BinaryTest method conditionTrue.
@Test
public void conditionTrue() {
final int expected = 1;
final AtomicInteger counter = new AtomicInteger(0);
final Binary binary = new Binary(new True(), counter::incrementAndGet);
new Assertion<>("Binary has to return true", binary, new HasValue<>(true)).affirm();
new Assertion<>("Binary has to invoke increment method", counter.get(), new IsEqual<>(expected)).affirm();
}
use of org.llorllale.cactoos.matchers.HasValue in project cactoos by yegor256.
the class FirstOfTest method returnsMatchingValueWithExceptionalFallback.
@Test
void returnsMatchingValueWithExceptionalFallback() {
final int value = 2;
new Assertion<>("Exception was not thrown", new FirstOf<>(i -> i >= value, new IterableOfInts(0, value), () -> {
throw new IllegalArgumentException("This exception should not be thrown");
}), new HasValue<>(value)).affirm();
}
use of org.llorllale.cactoos.matchers.HasValue in project cactoos by yegor256.
the class SlowInputTest method calculatesLength.
@Test
void calculatesLength() throws Exception {
final String text = "What's up, друг?";
new Assertion<>("Can't calculate the length of Input", new LengthOf(new SlowInput(new InputOf(new TextOf(text)))), new HasValue<>((long) text.getBytes(StandardCharsets.UTF_8).length)).affirm();
}
use of org.llorllale.cactoos.matchers.HasValue in project cactoos by yegor256.
the class RetryTest method runsScalarTwiceWithDefaults.
@Test
void runsScalarTwiceWithDefaults() throws Exception {
// @checkstyle MagicNumberCheck (1 line)
final AtomicInteger tries = new AtomicInteger(0);
new Assertion<>("Should run twice with defaults", new Retry<>(() -> {
// @checkstyle MagicNumberCheck (1 line)
if (tries.getAndIncrement() <= 1) {
throw new IllegalArgumentException("Not enough tries");
}
return 0;
}), new HasValue<>(0)).affirm();
}
use of org.llorllale.cactoos.matchers.HasValue in project cactoos by yegor256.
the class RetryTest method runsScalarMultipleTimesIgnoringNegativeDuration.
@Test
void runsScalarMultipleTimesIgnoringNegativeDuration() throws Exception {
// @checkstyle MagicNumberCheck (2 line)
final int times = 2;
final AtomicInteger tries = new AtomicInteger(0);
new Assertion<>("Should ignore negative duration", new Retry<>(() -> {
if (tries.getAndIncrement() < times) {
throw new IllegalArgumentException("Not yet");
}
return 0;
}, Integer.MAX_VALUE, // @checkstyle MagicNumberCheck (1 line)
Duration.of(-5, ChronoUnit.DAYS)), new HasValue<>(0)).affirm();
}
Aggregations