Search in sources :

Example 1 with HasValue

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HasValue(org.llorllale.cactoos.matchers.HasValue) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Example 2 with HasValue

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();
}
Also used : IterableOfInts(org.cactoos.iterable.IterableOfInts) HasValue(org.llorllale.cactoos.matchers.HasValue) Test(org.junit.jupiter.api.Test)

Example 3 with HasValue

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();
}
Also used : LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) HasValue(org.llorllale.cactoos.matchers.HasValue) Test(org.junit.jupiter.api.Test)

Example 4 with HasValue

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HasValue(org.llorllale.cactoos.matchers.HasValue) Test(org.junit.jupiter.api.Test)

Example 5 with HasValue

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HasValue(org.llorllale.cactoos.matchers.HasValue) Test(org.junit.jupiter.api.Test)

Aggregations

HasValue (org.llorllale.cactoos.matchers.HasValue)8 Test (org.junit.jupiter.api.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IterableOfInts (org.cactoos.iterable.IterableOfInts)2 TextOf (org.cactoos.text.TextOf)2 IsEqual (org.hamcrest.core.IsEqual)2 Test (org.junit.Test)2 Text (org.cactoos.Text)1 LengthOf (org.cactoos.scalar.LengthOf)1 IsText (org.llorllale.cactoos.matchers.IsText)1