Skip to content

Commit

Permalink
testing TagsSplitter
Browse files Browse the repository at this point in the history
  • Loading branch information
leocwolter committed Oct 7, 2014
1 parent 9fd5e6b commit 696a99f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/org/mamute/util/TagsSplitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> splitTags(String tagNames) {
List<String> tags = tagNames == null ? new ArrayList<String>() : asList(tagNames.split(regex));
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/org/mamute/util/TagsSplitterTest.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<String> splitTags = tagsSplitter.splitTags("java ruby,c");
assertThat(splitTags, hasItems("java", "ruby", "c"));
}

}

0 comments on commit 696a99f

Please sign in to comment.