Search in sources :

Example 1 with MatcherOf

use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.

the class BytesOfTest method closesInputStream.

@Test
public void closesInputStream() throws IOException {
    final AtomicBoolean closed = new AtomicBoolean();
    final InputStream input = new ByteArrayInputStream("how are you?".getBytes());
    MatcherAssert.assertThat("Can't close InputStream correctly", new TextOf(new InputOf(new InputStream() {

        @Override
        public int read() throws IOException {
            return input.read();
        }

        @Override
        public void close() throws IOException {
            input.close();
            closed.set(true);
        }
    }), StandardCharsets.UTF_8).asString(), new MatcherOf<>(text -> {
        return closed.get();
    }));
}
Also used : Text(org.cactoos.Text) JoinedText(org.cactoos.text.JoinedText) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) Limited(org.cactoos.iterable.Limited) StandardCharsets(java.nio.charset.StandardCharsets) MatcherOf(org.cactoos.matchers.MatcherOf) TextHasString(org.cactoos.matchers.TextHasString) Endless(org.cactoos.iterable.Endless) MatcherAssert(org.hamcrest.MatcherAssert) ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) TextOf(org.cactoos.text.TextOf) InputStream(java.io.InputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 2 with MatcherOf

use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.

the class WriterAsOutputStreamTest method writesLargeContentToFile.

@Test
public void writesLargeContentToFile() throws IOException {
    final Path temp = Files.createTempFile("cactoos-1", "txt-1");
    MatcherAssert.assertThat("Can't copy Input to Output and return Input", new TextOf(new TeeInput(new ResourceOf("org/cactoos/large-text.txt"), new OutputTo(new WriterAsOutputStream(new OutputStreamWriter(new FileOutputStream(temp.toFile()), StandardCharsets.UTF_8), StandardCharsets.UTF_8, // @checkstyle MagicNumber (1 line)
    345)))), new TextHasString(new MatcherOf<>(str -> {
        return new TextOf(temp).asString().equals(str);
    })));
}
Also used : Path(java.nio.file.Path) FileOutputStream(java.io.FileOutputStream) TextHasString(org.cactoos.matchers.TextHasString) TextOf(org.cactoos.text.TextOf) OutputStreamWriter(java.io.OutputStreamWriter) MatcherOf(org.cactoos.matchers.MatcherOf) Test(org.junit.Test)

Example 3 with MatcherOf

use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.

the class WriterAsOutputTest method writesLargeContentToFile.

@Test
public void writesLargeContentToFile() throws IOException {
    final Path temp = Files.createTempFile("cactoos-1", "txt-1");
    MatcherAssert.assertThat("Can't copy Input to Output and return Input", new TextOf(new TeeInput(new ResourceOf("org/cactoos/large-text.txt"), new WriterAsOutput(new OutputStreamWriter(new FileOutputStream(temp.toFile()), StandardCharsets.UTF_8)))), new TextHasString(new MatcherOf<>(str -> {
        return new TextOf(temp).asString().equals(str);
    })));
}
Also used : Path(java.nio.file.Path) FileOutputStream(java.io.FileOutputStream) TextHasString(org.cactoos.matchers.TextHasString) TextOf(org.cactoos.text.TextOf) OutputStreamWriter(java.io.OutputStreamWriter) MatcherOf(org.cactoos.matchers.MatcherOf) Test(org.junit.Test)

Example 4 with MatcherOf

use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.

the class SolidMapTest method mapsEmptyIterableWithKeyFuncAndValueFunc.

@Test
public void mapsEmptyIterableWithKeyFuncAndValueFunc() {
    final SolidMap<String, String> map = new SolidMap<>(key -> new SubText(new TextOf(key), 0, 1).asString(), value -> new UpperText(new TextOf(value)).asString(), new IterableOf<String>());
    MatcherAssert.assertThat("Empty Iterable cannot be accepted for key and value mapping", map, new MatcherOf<>(m -> m.size() == 0));
}
Also used : UpperText(org.cactoos.text.UpperText) MatcherAssert(org.hamcrest.MatcherAssert) Map(java.util.Map) IterableOf(org.cactoos.iterable.IterableOf) Matchers(org.hamcrest.Matchers) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test) SubText(org.cactoos.text.SubText) Scalar(org.cactoos.Scalar) MatcherOf(org.cactoos.matchers.MatcherOf) RunsInThreads(org.cactoos.matchers.RunsInThreads) UpperText(org.cactoos.text.UpperText) SubText(org.cactoos.text.SubText) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 5 with MatcherOf

use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.

the class SolidMapTest method mapsIterableWithKeyFuncAndValueFunc.

@Test
public void mapsIterableWithKeyFuncAndValueFunc() {
    final SolidMap<String, String> map = new SolidMap<>(key -> new SubText(new TextOf(key), 0, 1).asString(), value -> new UpperText(new TextOf(value)).asString(), new IterableOf<>("aa", "bb"));
    MatcherAssert.assertThat("Functions are not applied to key and value", map, Matchers.allOf(Matchers.hasEntry(Matchers.equalTo("a"), Matchers.equalTo("AA")), Matchers.hasEntry(Matchers.equalTo("b"), Matchers.equalTo("BB")), new MatcherOf<>(m -> m.size() == 2)));
}
Also used : UpperText(org.cactoos.text.UpperText) SubText(org.cactoos.text.SubText) TextOf(org.cactoos.text.TextOf) MatcherOf(org.cactoos.matchers.MatcherOf) Test(org.junit.Test)

Aggregations

MatcherOf (org.cactoos.matchers.MatcherOf)11 Test (org.junit.Test)11 MatcherAssert (org.hamcrest.MatcherAssert)8 TextOf (org.cactoos.text.TextOf)5 Matchers (org.hamcrest.Matchers)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Executors (java.util.concurrent.Executors)3 Future (java.util.concurrent.Future)3 ThreadFactory (java.util.concurrent.ThreadFactory)3 TimeUnit (java.util.concurrent.TimeUnit)3 Proc (org.cactoos.Proc)3 FuncApplies (org.cactoos.matchers.FuncApplies)3 TextHasString (org.cactoos.matchers.TextHasString)3 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Path (java.nio.file.Path)2 SubText (org.cactoos.text.SubText)2 UpperText (org.cactoos.text.UpperText)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1