Search in sources :

Example 16 with IsText

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

the class InputOfTest method readsStringFromReader.

@Test
void readsStringFromReader() throws Exception {
    final String source = "hello, source!";
    new Assertion<>("must read string through a reader", new TextOf(new InputOf(new StringReader(source))), 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) Test(org.junit.jupiter.api.Test)

Example 17 with IsText

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

the class InputOfTest method readsEncodedStringFromReader.

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

Example 18 with IsText

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

the class GzipInputTest method readFromGzipInput.

@Test
public void readFromGzipInput() throws Exception {
    final String content = "Hello!";
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (Writer writer = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(out)))) {
        writer.write(content);
    }
    final byte[] bytes = out.toByteArray();
    new Assertion<>("Can't read from a gzip input", new TextOf(new GzipInput(new InputOf(bytes))), new IsText(content)).affirm();
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) IsText(org.llorllale.cactoos.matchers.IsText) OutputStreamWriter(java.io.OutputStreamWriter) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 19 with IsText

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

the class InputStreamOfTest method readsFileContent.

@Test
public void readsFileContent() throws Exception {
    final File file = this.folder.newFile("readFileContent.txt-2");
    final String content = "Content in a file";
    new LengthOf(new TeeInput(content, file)).value();
    new Assertion<>("Must read from file", new TextOf(new InputStreamOf(file)), 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 20 with IsText

use of org.llorllale.cactoos.matchers.IsText 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)

Aggregations

IsText (org.llorllale.cactoos.matchers.IsText)51 Test (org.junit.jupiter.api.Test)35 TextOf (org.cactoos.text.TextOf)22 Test (org.junit.Test)16 HasString (org.llorllale.cactoos.matchers.HasString)12 File (java.io.File)11 StringReader (java.io.StringReader)6 Text (org.cactoos.Text)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 LengthOf (org.cactoos.scalar.LengthOf)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 LocalDate (java.time.LocalDate)3 LocalDateTime (java.time.LocalDateTime)3 OffsetDateTime (java.time.OffsetDateTime)3 ZonedDateTime (java.time.ZonedDateTime)3 Calendar (java.util.Calendar)3 Path (java.nio.file.Path)2 BytesOf (org.cactoos.bytes.BytesOf)2 BufferedWriter (java.io.BufferedWriter)1