Search in sources :

Example 36 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextWithCharsetToPath.

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

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

the class BytesOfTest method readsFromReader.

@Test
public void readsFromReader() throws IOException {
    final String source = "hello, друг!";
    MatcherAssert.assertThat("Can't read string through a reader", new TextOf(new BytesOf(new StringReader(source), StandardCharsets.UTF_8, // @checkstyle MagicNumberCheck (1 line)
    16 << 10)).asString(), Matchers.equalTo(source));
}
Also used : StringReader(java.io.StringReader) TextOf(org.cactoos.text.TextOf) TextHasString(org.cactoos.matchers.TextHasString) Test(org.junit.Test)

Example 38 with TextOf

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

the class TeeInputHasResultTest method failsIfInputDoesNotMatchExpectedValue.

@Test
public void failsIfInputDoesNotMatchExpectedValue() {
    final TeeInput matchable = new TeeInput(new TextOf("input"), new OutputTo(new ByteArrayOutputStream()));
    final String expected = "expected-1";
    final TeeInputHasResult matcher = new TeeInputHasResult(expected, new TextOf(expected));
    MatcherAssert.assertThat("Matcher does not compare input and expected values", matcher.matchesSafely(matchable), new IsEqual<>(false));
}
Also used : OutputTo(org.cactoos.io.OutputTo) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeeInput(org.cactoos.io.TeeInput) Test(org.junit.Test)

Example 39 with TextOf

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

the class TeeInputHasResultTest method failsIfCopiedValueDoesNotMatchExpectedValue.

@Test
public void failsIfCopiedValueDoesNotMatchExpectedValue() {
    final String expected = "expected-2";
    final TeeInput matchable = new TeeInput(new TextOf(expected), new OutputTo(new ByteArrayOutputStream()));
    final TeeInputHasResult matcher = new TeeInputHasResult(expected, new TextOf("incorrect"));
    MatcherAssert.assertThat("Matcher does not compare copied and expected values", matcher.matchesSafely(matchable), new IsEqual<>(false));
}
Also used : OutputTo(org.cactoos.io.OutputTo) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeeInput(org.cactoos.io.TeeInput) Test(org.junit.Test)

Example 40 with TextOf

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

the class TeeInputHasResultTest method describesMismatchOfInputAndExpected.

@Test
public void describesMismatchOfInputAndExpected() {
    final TeeInput matchable = new TeeInput(new TextOf("i"), new OutputTo(new ByteArrayOutputStream()));
    final TeeInputHasResult matcher = new TeeInputHasResult("e", new TextOf("e"));
    final StringDescription description = new StringDescription();
    matcher.matchesSafely(matchable);
    matcher.describeMismatchSafely(matchable, description);
    MatcherAssert.assertThat("Description of mismatch of input and expected incorrect", description.toString(), new IsEqual<>("TeeInput with result \"e\" and copied value \"e\""));
}
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)

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