Skip to content

Commit

Permalink
#255: SplitText fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 28, 2017
1 parent 0b97734 commit 8af1906
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/cactoos/text/SplitText.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Iterator;
import org.cactoos.Text;
import org.cactoos.list.ArrayAsIterable;
import org.cactoos.list.FilteredIterator;

/**
* Split the Text.
Expand Down Expand Up @@ -98,11 +99,14 @@ public SplitText(final UncheckedText text, final UncheckedText rgx) {

@Override
public Iterator<String> iterator() {
return new ArrayAsIterable<>(
this.origin.asString().split(
this.regex.asString()
)
).iterator();
return new FilteredIterator<>(
new ArrayAsIterable<>(
this.origin.asString().split(
this.regex.asString()
)
).iterator(),
input -> !input.isEmpty()
);
}

}
11 changes: 10 additions & 1 deletion src/test/java/org/cactoos/text/SplitTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Test case for {@link SplitText}.
* @author Alexey Semenyuk (semenyukalexey@gmail.com)
* @version $Id$
* @since 0.1
* @since 0.9
* @checkstyle JavadocMethodCheck (500 lines)
*/
public final class SplitTextTest {
Expand All @@ -50,4 +50,13 @@ public void splitText() throws Exception {
);
}

@Test
public void splitEmptyText() throws Exception {
MatcherAssert.assertThat(
"Can't split an empty text",
new SplitText("", "\n"),
Matchers.emptyIterable()
);
}

}

0 comments on commit 8af1906

Please sign in to comment.