Search in sources :

Example 41 with TextOf

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

the class TeeInputHasResultTest method describesMismatchOfCopiedAndExpected.

@Test
public void describesMismatchOfCopiedAndExpected() {
    final TeeInput matchable = new TeeInput(new TextOf("i"), new OutputTo(new ByteArrayOutputStream()));
    final TeeInputHasResult matcher = new TeeInputHasResult("i", new TextOf("wrong"));
    final StringDescription description = new StringDescription();
    matcher.matchesSafely(matchable);
    matcher.describeMismatchSafely(matchable, description);
    MatcherAssert.assertThat("Description of mismatch of copied and expected incorrect", description.toString(), new IsEqual<>("TeeInput with result \"i\" and copied value \"i\""));
}
Also used : OutputTo(org.cactoos.io.OutputTo) StringDescription(org.hamcrest.StringDescription) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeeInput(org.cactoos.io.TeeInput) Test(org.junit.Test)

Example 42 with TextOf

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

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

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

Example 45 with TextOf

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

the class HeadOfTest method readsHeadOfShorterInput.

@Test
void readsHeadOfShorterInput() throws Exception {
    final String input = "readsHeadOfShorterInput";
    new Assertion<>("must limit to at most the number of available bytes", new TextOf(new HeadOf(new InputOf(input), 35)), new HasString(input)).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) Test(org.junit.jupiter.api.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