Search in sources :

Example 1 with TextOf

use of org.cactoos.text.TextOf 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 TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class BytesOfTest method asBytes.

@Test
public void asBytes() throws IOException {
    final Text text = new TextOf("Hello!");
    MatcherAssert.assertThat("Can't convert text into bytes", new BytesOf(new InputOf(text)).asBytes(), Matchers.equalTo(new BytesOf(text.asString()).asBytes()));
}
Also used : Text(org.cactoos.Text) JoinedText(org.cactoos.text.JoinedText) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 3 with TextOf

use of org.cactoos.text.TextOf 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 4 with TextOf

use of org.cactoos.text.TextOf 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 5 with TextOf

use of org.cactoos.text.TextOf 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)

Aggregations

TextOf (org.cactoos.text.TextOf)74 Test (org.junit.Test)41 Test (org.junit.jupiter.api.Test)32 IsText (org.llorllale.cactoos.matchers.IsText)25 File (java.io.File)20 LengthOf (org.cactoos.scalar.LengthOf)20 HasString (org.llorllale.cactoos.matchers.HasString)17 HasContent (org.llorllale.cactoos.matchers.HasContent)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 Logger (java.util.logging.Logger)10 Text (org.cactoos.Text)9 AllOf (org.hamcrest.core.AllOf)7 IsEqual (org.hamcrest.core.IsEqual)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 StringReader (java.io.StringReader)5 Path (java.nio.file.Path)5 MatcherOf (org.cactoos.matchers.MatcherOf)5 InputStream (java.io.InputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 BytesOf (org.cactoos.bytes.BytesOf)4