Skip to content

Commit

Permalink
(yegor256#1462) Use TextOf' in order to provide equals' & `hashCode'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Nov 8, 2020
1 parent 397ac51 commit 92ce712
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/main/java/org/cactoos/text/Mapped.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@
*
* @since 0.47
*/
public final class Mapped implements Text {

/**
* Map function.
*/
private final Func<String, String> func;

/**
* Original text.
*/
private final Text text;
public final class Mapped extends TextEnvelope {

/**
* Ctor.
Expand All @@ -50,13 +40,7 @@ public final class Mapped implements Text {
* @param txt Original text
*/
public Mapped(final Func<String, String> fnc, final Text txt) {
this.func = fnc;
this.text = txt;
}

@Override
public String asString() throws Exception {
return this.func.apply(this.text.asString());
super(new TextOf(() -> fnc.apply(txt.asString())));
}

}
13 changes: 13 additions & 0 deletions src/test/java/org/cactoos/text/MappedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.cactoos.text;

import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.TextIs;
Expand All @@ -34,6 +35,18 @@
*/
final class MappedTest {

@Test
void resultShouldBeEqual() {
new Assertion<>(
"must be equal to the same text",
new Mapped(
String::toUpperCase,
new TextOf("hi")
),
new IsEqual<>(new TextOf("HI"))
).affirm();
}

@Test
void mapsWithFormat() {
new Assertion<>(
Expand Down

0 comments on commit 92ce712

Please sign in to comment.