Search in sources :

Example 1 with Throws

use of org.llorllale.cactoos.matchers.Throws in project cactoos by yegor256.

the class MappedWithIndexTest method failsIfIteratorExhausted.

@Test
void failsIfIteratorExhausted() {
    final Iterator<Text> iterator = new MappedWithIndex<>((item, index) -> new FormattedText("%1$s X %2$s", index, item), new IterableOf<>("1").iterator());
    iterator.next();
    new Assertion<>("must throw NSEE", iterator::next, new Throws<>(NoSuchElementException.class)).affirm();
}
Also used : IterableOf(org.cactoos.iterable.IterableOf) Text(org.cactoos.Text) FormattedText(org.cactoos.text.FormattedText) FormattedText(org.cactoos.text.FormattedText) Throws(org.llorllale.cactoos.matchers.Throws) Test(org.junit.jupiter.api.Test)

Example 2 with Throws

use of org.llorllale.cactoos.matchers.Throws in project cactoos by yegor256.

the class IoCheckedBiProcTest method executesWrappedProc.

@Test
void executesWrappedProc() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    new IoCheckedBiProc<>((first, second) -> counter.incrementAndGet()).exec(true, true);
    new Assertion<>("Must execute wrapped proc", counter.get(), new IsEqual<>(1)).affirm();
}
Also used : Test(org.junit.jupiter.api.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertion(org.llorllale.cactoos.matchers.Assertion) IsEqual(org.hamcrest.core.IsEqual) IOException(java.io.IOException) IoCheckedBiFunc(org.cactoos.func.IoCheckedBiFunc) Throws(org.llorllale.cactoos.matchers.Throws) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 3 with Throws

use of org.llorllale.cactoos.matchers.Throws in project cactoos by yegor256.

the class CheckedTest method throwsIoExceptionWithModifiedMessage.

@Test
public void throwsIoExceptionWithModifiedMessage() throws Exception {
    final String message = "error msg";
    new Assertion<>("Must throw io exception with modified message", () -> new Checked<>(() -> {
        throw new IOException("io");
    }, exp -> new IOException(message, exp)).value(), new Throws<>(message, IOException.class)).affirm();
}
Also used : Assertion(org.llorllale.cactoos.matchers.Assertion) IsEqual(org.hamcrest.core.IsEqual) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) AcceptPendingException(java.nio.channels.AcceptPendingException) Throws(org.llorllale.cactoos.matchers.Throws) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Throws(org.llorllale.cactoos.matchers.Throws) Test(org.junit.Test)

Example 4 with Throws

use of org.llorllale.cactoos.matchers.Throws in project cactoos by yegor256.

the class IoCheckedFuncTest method rethrowsIoException.

@Test
void rethrowsIoException() {
    final IOException exception = new IOException("intended");
    new Assertion<>("Must rethrow original IOException", () -> new IoCheckedFunc<>(i -> {
        throw exception;
    }).apply(1), new Throws<>(exception.getMessage(), exception.getClass())).affirm();
}
Also used : Test(org.junit.jupiter.api.Test) Assertion(org.llorllale.cactoos.matchers.Assertion) IOException(java.io.IOException) Throws(org.llorllale.cactoos.matchers.Throws) IOException(java.io.IOException) Throws(org.llorllale.cactoos.matchers.Throws) Test(org.junit.jupiter.api.Test)

Example 5 with Throws

use of org.llorllale.cactoos.matchers.Throws in project cactoos by yegor256.

the class AppendToTest method failsIfFileDoesNotExist.

/**
 * Ensures that AppendTo is failing on a negative predicate result.
 */
@Test
public void failsIfFileDoesNotExist() throws Exception {
    final File source = new File(new Randomized('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h').asString());
    new Assertion<>("Can't throw exception with proper message", () -> new AppendTo(source).stream(), new Throws<>(source.getPath(), NoSuchFileException.class)).affirm();
}
Also used : Randomized(org.cactoos.text.Randomized) Throws(org.llorllale.cactoos.matchers.Throws) File(java.io.File) Test(org.junit.Test)

Aggregations

Throws (org.llorllale.cactoos.matchers.Throws)11 IOException (java.io.IOException)8 Test (org.junit.jupiter.api.Test)8 Assertion (org.llorllale.cactoos.matchers.Assertion)5 Test (org.junit.Test)3 IsEqual (org.hamcrest.core.IsEqual)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 AcceptPendingException (java.nio.channels.AcceptPendingException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Proc (org.cactoos.Proc)1 Text (org.cactoos.Text)1 IoCheckedBiFunc (org.cactoos.func.IoCheckedBiFunc)1 IterableOf (org.cactoos.iterable.IterableOf)1 FormattedText (org.cactoos.text.FormattedText)1 Randomized (org.cactoos.text.Randomized)1 Matchers (org.hamcrest.Matchers)1