-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mehyil
committed
Jun 2, 2017
1 parent
65d6d67
commit 4d2b9d0
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.cactoos.text; | ||
|
||
import org.cactoos.Text; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Replace the Text. | ||
* | ||
* @author Mehmet Yildirim (memoyil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.1 | ||
*/ | ||
public class ReplacedText implements Text { | ||
|
||
/** | ||
* The text. | ||
*/ | ||
private final Text origin; | ||
|
||
/** | ||
* The old char. | ||
*/ | ||
private String oldChar; | ||
|
||
/** | ||
* The new char. | ||
*/ | ||
private String newChar; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param text The text | ||
* @param oldChar The old char | ||
* @param newChar The new char | ||
*/ | ||
public ReplacedText(final Text text, String oldChar, String newChar) { | ||
this.origin = text; | ||
this.oldChar = oldChar; | ||
this.newChar = newChar; | ||
} | ||
|
||
@Override | ||
public String asString() throws IOException { | ||
return origin.asString().replace(oldChar, newChar); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.cactoos.text; | ||
|
||
import org.cactoos.TextHasString; | ||
import org.hamcrest.MatcherAssert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test case for {@link ReplacedText}. | ||
* @author Mehmet Yildirim (memoyil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.1 | ||
* @checkstyle JavadocMethodCheck (500 lines) | ||
*/ | ||
public final class ReplacedTextTest { | ||
|
||
@Test | ||
public void replaceText() { | ||
MatcherAssert.assertThat( | ||
"Can't replace a text", | ||
new ReplacedText(new StringAsText("Hello!"),"ello","i"), | ||
new TextHasString("Hi!") | ||
); | ||
} | ||
} |