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();
}
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();
}
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();
}
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);
}
Aggregations