Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 1, 2021
2 parents 4725444 + ee85287 commit f999c06
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/main/java/org/cactoos/text/Sticky.java
Expand Up @@ -23,7 +23,6 @@
*/
package org.cactoos.text;

import org.cactoos.Scalar;
import org.cactoos.Text;

/**
Expand All @@ -37,22 +36,17 @@
* @see org.cactoos.scalar.Sticky
* @since 0.47
*/
public final class Sticky implements Text {
/**
* Sticky scalar.
*/
private final Scalar<String> 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();
}
}
29 changes: 29 additions & 0 deletions src/test/java/org/cactoos/text/StickyTest.java
Expand Up @@ -24,13 +24,18 @@
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;

/**
* Test case for {@link Sticky}.
* @since 0.47
* @checkstyle ClassDataAbstractionCouplingCheck (100 lines)
*/
final class StickyTest {
@Test
Expand All @@ -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<Text>(
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();
}
}

0 comments on commit f999c06

Please sign in to comment.