Skip to content

Commit

Permalink
(yegor256#981) Renamed Before to PrefixOf, After to SuffixOf
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Feb 2, 2019
1 parent 5780c4d commit 3abfb4c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @since 1.0
*/
public final class Before extends TextEnvelope {
public final class PrefixOf extends TextEnvelope {

/**
* Ctor.
Expand All @@ -41,16 +41,16 @@ public final class Before extends TextEnvelope {
*/
@SuppressWarnings({"PMD.CallSuperInConstructor",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"})
public Before(final String text, final String boundary) {
public PrefixOf(final String text, final String boundary) {
super((Scalar<String>) () -> {
final String before;
final String prefix;
final int idx = text.indexOf(boundary);
if (idx >= 0) {
before = text.substring(0, idx);
prefix = text.substring(0, idx);
} else {
before = text;
prefix = text;
}
return before;
return prefix;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
* <p>There is no thread-safety guarantee.
*
* @since 1.0
* @todo #981:30min Update qulice version(min. 0.18.10) and remove
* constructor suppress warnings which existence of is
* not needed, but is a bug in currently used version
*/
public final class After extends TextEnvelope {
public final class SuffixOf extends TextEnvelope {

/**
* Ctor.
Expand All @@ -44,16 +41,16 @@ public final class After extends TextEnvelope {
*/
@SuppressWarnings({"PMD.CallSuperInConstructor",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"})
public After(final String text, final String boundary) {
public SuffixOf(final String text, final String boundary) {
super((Scalar<String>) () -> {
final String after;
final String suffix;
final int idx = text.indexOf(boundary);
if (idx >= 0) {
after = text.substring(idx + boundary.length());
suffix = text.substring(idx + boundary.length());
} else {
after = "";
suffix = "";
}
return after;
return suffix;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.llorllale.cactoos.matchers.TextIs;

/**
* Test case for {@link Before}.
* Test case for {@link PrefixOf}.
*
* @since 1.0
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class BeforeTest {
public final class PrefixOfTest {

/**
* Ensures that Before is returning given string if
Expand All @@ -43,7 +43,7 @@ public final class BeforeTest {
public void returnsInputIfThereIsNoBoundary() {
new Assertion<>(
"Given strings are not equal",
() -> new Before("Cactoos", "bnd"),
() -> new PrefixOf("Cactoos", "bnd"),
new TextIs("Cactoos")
).affirm();
}
Expand All @@ -56,7 +56,7 @@ public void returnsInputIfThereIsNoBoundary() {
public void returnsEmptyIfStringIsBoundary() {
new Assertion<>(
"Given string is not empty",
() -> new Before("Boundary", "Boundary"),
() -> new PrefixOf("Boundary", "Boundary"),
new TextIs("")
).affirm();
}
Expand All @@ -69,7 +69,7 @@ public void returnsEmptyIfStringIsBoundary() {
public void returnsBeforeBoundaryString() {
new Assertion<>(
"Given strings are not equal",
() -> new Before("Anti-pattern", "-pattern"),
() -> new PrefixOf("Anti-pattern", "-pattern"),
new TextIs("Anti")
).affirm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.llorllale.cactoos.matchers.TextIs;

/**
* Test case for {@link After}.
* Test case for {@link SuffixOf}.
*
* @since 1.0
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class AfterTest {
public final class SuffixOfTest {

/**
* Ensures that After is returning empty string if
Expand All @@ -43,7 +43,7 @@ public final class AfterTest {
public void returnsEmptyIfThereIsNoBoundary() {
new Assertion<>(
"Given string is not empty",
() -> new After("Cactoos with description", "after"),
() -> new SuffixOf("Cactoos with description", "after"),
new TextIs("")
).affirm();
}
Expand All @@ -56,7 +56,7 @@ public void returnsEmptyIfThereIsNoBoundary() {
public void returnsEmptyIfStringIsBoundary() {
new Assertion<>(
"Given string is not empty",
() -> new After("Boundary", "Boundary"),
() -> new SuffixOf("Boundary", "Boundary"),
new TextIs("")
).affirm();
}
Expand All @@ -69,7 +69,7 @@ public void returnsEmptyIfStringIsBoundary() {
public void returnsAfterBoundaryString() {
new Assertion<>(
"Given strings are not equal",
() -> new After("Anti-pattern", "Anti-"),
() -> new SuffixOf("Anti-pattern", "Anti-"),
new TextIs("pattern")
).affirm();
}
Expand Down

0 comments on commit 3abfb4c

Please sign in to comment.