Search in sources :

Example 21 with IsText

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

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

the class TeeOutputTest method copiesWithFile.

@Test
public void copiesWithFile() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final File file = this.folder.newFile();
    new Assertion<>("Must copy Output with file", new TextOf(new TeeInput(new InputOf("Hello, товарищ! with file"), new TeeOutput(new OutputTo(baos), file))), new IsText(new TextOf(file.toPath()))).affirm();
}
Also used : IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.Test)

Example 23 with IsText

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

the class HeadInputStreamTest method testSkippingMoreThanTotal.

@Test
void testSkippingMoreThanTotal() throws Exception {
    final HeadInputStream stream = new HeadInputStream(new InputOf("testSkippingMoreThanTotal").stream(), 5);
    final long skipped = stream.skip(7L);
    new Assertion<>("Incorrect number of bytes skipped", skipped, new IsEqual<>(5L)).affirm();
    final String input = new TextOf(stream).asString();
    new Assertion<>("The result text wasn't empty", new TextOf(input), new IsText("")).affirm();
}
Also used : IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 24 with IsText

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

the class InputStreamOfTest method readsFromTextWithCharset.

@Test
public void readsFromTextWithCharset() throws Exception {
    final File file = this.folder.newFile("readTextWithCharset.txt-5");
    final String content = "Content for reading text with charset";
    new LengthOf(new TeeInput(content, file)).value();
    new Assertion<>("Must read from text with charset", new TextOf(new InputStreamOf(new TextOf(file), StandardCharsets.UTF_8.name())), 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 25 with IsText

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

the class InputStreamOfTest method readsFromUri.

@Test
public void readsFromUri() throws Exception {
    final String content = "Content for reading through URI";
    final File file = this.folder.newFile("readFromUri.txt-3");
    new LengthOf(new TeeInput(content, file)).value();
    new Assertion<>("Must read from URI", new TextOf(new InputStreamOf(file.toURI())), 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