Search in sources :

Example 56 with TextOf

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

the class BytesOfTest method readsFromReader.

@Test
void readsFromReader() throws Exception {
    final String source = "hello, друг!";
    new Assertion<>("must read string through a reader", new TextOf(new Sticky(new InputOf(new BytesOf(new StringReader(source), StandardCharsets.UTF_8, // @checkstyle MagicNumberCheck (1 line)
    16 << 10)))), new IsText(source)).affirm();
}
Also used : StringReader(java.io.StringReader) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) InputOf(org.cactoos.io.InputOf) Sticky(org.cactoos.io.Sticky) Test(org.junit.jupiter.api.Test)

Example 57 with TextOf

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

the class BytesOfTest method asBytes.

@Test
void asBytes() throws Exception {
    final Text text = new TextOf("Hello!");
    new Assertion<>("Can't convert text into bytes", new BytesOf(new InputOf(text)).asBytes(), new IsEqual<>(new BytesOf(text.asString()).asBytes())).affirm();
}
Also used : Text(org.cactoos.Text) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) InputOf(org.cactoos.io.InputOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 58 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextWithCharsetToOutput.

@Test
public void copiesFromTextWithCharsetToOutput() throws Exception {
    final String input = "Hello, товарищ output #2 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new TextOf(input), new OutputTo(output), StandardCharsets.UTF_8)).value();
    new Assertion<>("text must be copied to the output with UTF_8 charset", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) File(java.io.File) Test(org.junit.Test)

Example 59 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextToOutput.

@Test
public void copiesFromTextToOutput() throws Exception {
    final String input = "Hello, товарищ output #1 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new TextOf(input), new OutputTo(output))).value();
    new Assertion<>("text must be copied to the output", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) File(java.io.File) Test(org.junit.Test)

Example 60 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextWithCharsetByNameToOutput.

@Test
public void copiesFromTextWithCharsetByNameToOutput() throws Exception {
    final String input = "Hello, товарищ output #3 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new TextOf(input), new OutputTo(output), StandardCharsets.UTF_8.name())).value();
    new Assertion<>("text must be copied to the output with UTF_8 charset's name", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) File(java.io.File) 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