diff --git a/src/main/java/org/cactoos/text/Sticky.java b/src/main/java/org/cactoos/text/Sticky.java index 59f0f8a1c..c04388688 100644 --- a/src/main/java/org/cactoos/text/Sticky.java +++ b/src/main/java/org/cactoos/text/Sticky.java @@ -23,7 +23,6 @@ */ package org.cactoos.text; -import org.cactoos.Scalar; import org.cactoos.Text; /** @@ -37,22 +36,17 @@ * @see org.cactoos.scalar.Sticky * @since 0.47 */ -public final class Sticky implements Text { - /** - * Sticky scalar. - */ - private final Scalar scalar; - +public final class Sticky extends TextEnvelope { /** * Ctor. * @param txt Text to cache */ public Sticky(final Text txt) { - this.scalar = new org.cactoos.scalar.Sticky<>(txt::asString); + super( + new TextOfScalar( + new org.cactoos.scalar.Sticky<>(txt::asString) + ) + ); } - @Override - public String asString() throws Exception { - return this.scalar.value(); - } } diff --git a/src/test/java/org/cactoos/text/StickyTest.java b/src/test/java/org/cactoos/text/StickyTest.java index 2a569dd13..f4e51178c 100644 --- a/src/test/java/org/cactoos/text/StickyTest.java +++ b/src/test/java/org/cactoos/text/StickyTest.java @@ -24,6 +24,10 @@ package org.cactoos.text; import org.cactoos.Text; +import org.hamcrest.core.AllOf; +import org.hamcrest.core.IsEqual; +import org.hamcrest.core.IsNot; +import org.hamcrest.object.HasToString; import org.junit.jupiter.api.Test; import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.IsText; @@ -31,6 +35,7 @@ /** * Test case for {@link Sticky}. * @since 0.47 + * @checkstyle ClassDataAbstractionCouplingCheck (100 lines) */ final class StickyTest { @Test @@ -42,4 +47,28 @@ void cachesResult() { new IsText(sticky) ).affirm(); } + + @Test + void equalsItself() { + final Text random = new Randomized(); + final Text sticky = new Sticky(random); + new Assertion<>( + "must be the same as itself", + sticky, + new AllOf( + new IsEqual<>(sticky), + new IsNot<>(new IsEqual<>(random)) + ) + ).affirm(); + } + + @Test + void hasProperToString() { + final String str = "Hello"; + new Assertion<>( + "must have toString method", + new Sticky(() -> str), + new HasToString<>(new IsEqual<>(str)) + ).affirm(); + } }