Search in sources :

Example 26 with TextOf

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

the class InputStreamOfTest method readsFromUrl.

@Test
public void readsFromUrl() throws Exception {
    final String content = "Content for reading through URL";
    final File file = this.folder.newFile("readFromUrl.txt-4");
    new LengthOf(new TeeInput(content, file)).value();
    new Assertion<>("Must read from URL", new TextOf(new InputStreamOf(file.toURI().toURL())), new IsText(content)).affirm();
}
Also used : LengthOf(org.cactoos.scalar.LengthOf) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) File(java.io.File) Test(org.junit.Test)

Example 27 with TextOf

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

the class InputStreamOfTest method readsBytesArray.

@Test
public void readsBytesArray() throws Exception {
    final String content = "Bytes array content";
    final byte[] bytes = new BytesOf(content).asBytes();
    new Assertion<>("Must read from byte array", new TextOf(new InputStreamOf(bytes)), new IsText(content)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 28 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextWithCharsetByNameToFile.

@Test
public void copiesFromTextWithCharsetByNameToFile() throws Exception {
    final String input = "Hello, товарищ file #3 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new TextOf(input), output, StandardCharsets.UTF_8.name())).value();
    new Assertion<>("text must be copied to the file 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)

Example 29 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextToFile.

@Test
public void copiesFromTextToFile() throws Exception {
    final String input = "Hello, товарищ file #1 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new TextOf(input), output)).value();
    new Assertion<>("text must be copied to the file", 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 30 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextWithCharsetByNameToPath.

@Test
public void copiesFromTextWithCharsetByNameToPath() throws Exception {
    final String input = "Hello, товарищ path #3 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new TextOf(input), output.toPath(), StandardCharsets.UTF_8.name())).value();
    new Assertion<>("text must be copied to the path 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