From 696a99f697c6fe1fe94c5aae712bb6484e293e8b Mon Sep 17 00:00:00 2001 From: leonardowolter Date: Tue, 7 Oct 2014 16:53:46 -0300 Subject: [PATCH] testing TagsSplitter --- .../java/org/mamute/util/TagsSplitter.java | 13 +++++++- .../org/mamute/util/TagsSplitterTest.java | 33 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/mamute/util/TagsSplitterTest.java diff --git a/src/main/java/org/mamute/util/TagsSplitter.java b/src/main/java/org/mamute/util/TagsSplitter.java index aafb24060..43cfa6f0b 100644 --- a/src/main/java/org/mamute/util/TagsSplitter.java +++ b/src/main/java/org/mamute/util/TagsSplitter.java @@ -17,8 +17,19 @@ public class TagsSplitter { + private final String regex; + + /** + * @deprecated CDI eyes only + */ + public TagsSplitter() { + this(""); + } + @Inject - private @Property("tags.splitter.regex") String regex; + public TagsSplitter(@Property("tags.splitter.regex") String regex) { + this.regex = regex; + } public List splitTags(String tagNames) { List tags = tagNames == null ? new ArrayList() : asList(tagNames.split(regex)); diff --git a/src/test/java/org/mamute/util/TagsSplitterTest.java b/src/test/java/org/mamute/util/TagsSplitterTest.java new file mode 100644 index 000000000..0c9bd77c2 --- /dev/null +++ b/src/test/java/org/mamute/util/TagsSplitterTest.java @@ -0,0 +1,33 @@ +package org.mamute.util; + +import static org.hamcrest.Matchers.hasItems; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.Test; + +public class TagsSplitterTest { + + @Test + public void should_split_tags_based_on_regex_for_comma() { + TagsSplitter tagsSplitter = new TagsSplitter("\\,"); + List splitTags = tagsSplitter.splitTags("java, ruby"); + assertThat(splitTags, hasItems("java", "ruby")); + } + + @Test + public void should_split_tags_based_on_regex_for_space_character() { + TagsSplitter tagsSplitter = new TagsSplitter("\\s+"); + List splitTags = tagsSplitter.splitTags("java ruby"); + assertThat(splitTags, hasItems("java", "ruby")); + } + + @Test + public void should_split_tags_based_on_regex_for_both_comma_and_space_character() { + TagsSplitter tagsSplitter = new TagsSplitter("[\\s+|\\,]"); + List splitTags = tagsSplitter.splitTags("java ruby,c"); + assertThat(splitTags, hasItems("java", "ruby", "c")); + } + +}