Search in sources :

Example 71 with TextOf

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

the class ImmutableTest method decoratesToString.

@Test
public void decoratesToString() throws Exception {
    final String string = new Randomized().asString();
    final Iterator<Object> iterator = new Iterator<Object>() {

        public Object next() {
            return new Object();
        }

        public boolean hasNext() {
            return false;
        }

        public String toString() {
            return string;
        }
    };
    final Iterator<Object> immutable = new Immutable<>(iterator);
    new Assertion<>("must delegate toString to decorated iterator", new TextOf(immutable.toString()), new IsText(iterator.toString())).affirm();
}
Also used : Randomized(org.cactoos.text.Randomized) Iterator(java.util.Iterator) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 72 with TextOf

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

the class FlattenedTest method flattens.

@Test
void flattens() {
    final Text txt = new TextOf("txt");
    final Scalar<Text> sclr = new Constant<>(txt);
    new Assertion<>("must flatten", new Flattened<>(new ScalarOf<>(() -> sclr)), new HasValue<>(new IsText(txt))).affirm();
}
Also used : IsText(org.llorllale.cactoos.matchers.IsText) Text(org.cactoos.Text) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) HasValue(org.llorllale.cactoos.matchers.HasValue) Test(org.junit.jupiter.api.Test)

Example 73 with TextOf

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

the class SortedTest method mustSortTextIterableAsSetUsingCustomCOmparator.

@Test
@SuppressWarnings("unchecked")
void mustSortTextIterableAsSetUsingCustomCOmparator() {
    new Assertion<>("Must keep unique integer numbers sorted in descending order", new Sorted<Text>((first, second) -> {
        final String left = new UncheckedText(first).asString();
        final String right = new UncheckedText(second).asString();
        return left.compareTo(right);
    }, new TextOf("cd"), new TextOf("ab"), new TextOf("gh"), new TextOf("ef")), new IsIterableContainingInOrder<Text>(new ListOf<>(new IsText("ab"), new IsText("cd"), new IsText("ef"), new IsText("gh")))).affirm();
}
Also used : IsIterableContainingInOrder(org.hamcrest.collection.IsIterableContainingInOrder) UncheckedText(org.cactoos.text.UncheckedText) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) Test(org.junit.jupiter.api.Test)

Example 74 with TextOf

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

the class Cycle method exec.

@Override
public void exec(final Pipe pipe) throws Exception {
    final XePrint print = new XePrint(pipe.asXembly());
    final Events events = this.base.user(print.text("{/pipe/urn/text()}")).events();
    final String json = print.text("{/pipe/json/text()}");
    new UncheckedFunc<>(new FuncWithFallback<String, JsonObject>(str -> Json.createReader(new ReaderOf(str)).readObject(), new FuncOf<>(error -> events.post(Cycle.class.getCanonicalName(), String.format("Failed to parse JSON:\n%s\n\n%s", json, new TextOf(new BytesOf(error)).asString()))), obj -> {
        if (obj != null) {
            new Exec(new JsonAgent(this.base, obj), new IgnoreEvents(new BoostEvents(events, obj), obj), pipe).run();
        }
        return obj;
    })).apply(json);
}
Also used : JsonObject(javax.json.JsonObject) Events(io.wring.model.Events) FuncOf(org.cactoos.func.FuncOf) UncheckedFunc(org.cactoos.func.UncheckedFunc) Proc(org.cactoos.Proc) Base(io.wring.model.Base) BytesOf(org.cactoos.io.BytesOf) XePrint(io.wring.model.XePrint) Json(javax.json.Json) Pipe(io.wring.model.Pipe) ReaderOf(org.cactoos.io.ReaderOf) TextOf(org.cactoos.text.TextOf) FuncWithFallback(org.cactoos.func.FuncWithFallback) BytesOf(org.cactoos.io.BytesOf) FuncWithFallback(org.cactoos.func.FuncWithFallback) Events(io.wring.model.Events) ReaderOf(org.cactoos.io.ReaderOf) XePrint(io.wring.model.XePrint) TextOf(org.cactoos.text.TextOf)

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