Search in sources :

Example 6 with Throws

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

the class ReplacedTest method invalidRegex.

@Test
void invalidRegex() {
    final String regex = "invalid_regex{0,";
    new Assertion<>("Doesn't throw proper exception", new Replaced(new TextOf("text"), regex, "error")::asString, new Throws<>(new PatternSyntaxException("Unclosed counted closure", regex, // @checkstyle MagicNumberCheck (1 line)
    16).getMessage(), PatternSyntaxException.class)).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) Throws(org.llorllale.cactoos.matchers.Throws) PatternSyntaxException(java.util.regex.PatternSyntaxException) Test(org.junit.jupiter.api.Test)

Example 7 with Throws

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

the class LoggingInputStreamTest method reThrowsException.

@Test
void reThrowsException() {
    final String message = "Some read exception.";
    final LoggingInputStream stream = new LoggingInputStream(new InputStream() {

        @Override
        public int read() throws IOException {
            throw new IOException(message);
        }
    }, this.getClass().getSimpleName());
    new Assertion<>("Read doesn't throw an the exception.", () -> stream.read(), new Throws<>(message, IOException.class)).affirm();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Throws(org.llorllale.cactoos.matchers.Throws) Test(org.junit.jupiter.api.Test)

Example 8 with Throws

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

the class IoCheckedBiFuncTest method rethrowsIoException.

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

Example 9 with Throws

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

the class UncheckedTextTest method rethrowsCheckedToUncheckedException.

@Test
void rethrowsCheckedToUncheckedException() {
    final String msg = "intended";
    new Assertion<>("Must throw an exception when something goes wrong", new UncheckedText(() -> {
        throw new IOException(msg);
    })::asString, new Throws<>(new StringContains(msg), RuntimeException.class)).affirm();
}
Also used : HasToString(org.hamcrest.object.HasToString) IOException(java.io.IOException) Throws(org.llorllale.cactoos.matchers.Throws) StringContains(org.hamcrest.core.StringContains) Test(org.junit.jupiter.api.Test)

Example 10 with Throws

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

the class IoCheckedTest method rethrowsIoException.

@Test
void rethrowsIoException() {
    final IOException exception = new IOException("intended");
    new Assertion<>("Must rethrow IOException", () -> new IoChecked<>(() -> {
        throw exception;
    }).value(), new Throws<>(exception.getMessage(), exception.getClass())).affirm();
}
Also used : IOException(java.io.IOException) Throws(org.llorllale.cactoos.matchers.Throws) Test(org.junit.jupiter.api.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