MCPcopy
hub / github.com/google/guava / SplitterTest

Class SplitterTest

guava-tests/test/com/google/common/base/SplitterTest.java:39–782  ·  view source on GitHub ↗

@author Julien Silland

Source from the content-addressed store, hash-verified

37 * @author Julien Silland
38 */
39@NullMarked
40@GwtCompatible
41public class SplitterTest extends TestCase {
42
43 private static final Splitter COMMA_SPLITTER = Splitter.on(',');
44
45 @SuppressWarnings("nullness") // test of a bogus call
46 public void testSplitNullString() {
47 assertThrows(NullPointerException.class, () -> COMMA_SPLITTER.split(null));
48 }
49
50 public void testCharacterSimpleSplit() {
51 String simple = "a,b,c";
52 Iterable<String> letters = COMMA_SPLITTER.split(simple);
53 assertThat(letters).containsExactly("a", "b", "c").inOrder();
54 }
55
56 /**
57 * All of the infrastructure of split and splitToString is identical, so we do one test of
58 * splitToString. All other cases should be covered by testing of split.
59 *
60 * <p>TODO(user): It would be good to make all the relevant tests run on both split and
61 * splitToString automatically.
62 */
63 public void testCharacterSimpleSplitToList() {
64 String simple = "a,b,c";
65 List<String> letters = COMMA_SPLITTER.splitToList(simple);
66 assertThat(letters).containsExactly("a", "b", "c").inOrder();
67 }
68
69 public void testCharacterSimpleSplitToStream() {
70 String simple = "a,b,c";
71 List<String> letters = COMMA_SPLITTER.splitToStream(simple).collect(toImmutableList());
72 assertThat(letters).containsExactly("a", "b", "c").inOrder();
73 }
74
75 public void testToString() {
76 assertThat(COMMA_SPLITTER.split("").toString()).isEqualTo("[]");
77 assertThat(COMMA_SPLITTER.split("a,b,c").toString()).isEqualTo("[a, b, c]");
78 assertThat(Splitter.on(", ").split("yam, bam, jam, ham").toString())
79 .isEqualTo("[yam, bam, jam, ham]");
80 }
81
82 public void testCharacterSimpleSplitWithNoDelimiter() {
83 String simple = "a,b,c";
84 Iterable<String> letters = Splitter.on('.').split(simple);
85 assertThat(letters).containsExactly("a,b,c").inOrder();
86 }
87
88 public void testCharacterSplitWithDoubleDelimiter() {
89 String doubled = "a,,b,c";
90 Iterable<String> letters = COMMA_SPLITTER.split(doubled);
91 assertThat(letters).containsExactly("a", "", "b", "c").inOrder();
92 }
93
94 public void testCharacterSplitWithDoubleDelimiterAndSpace() {
95 String doubled = "a,, b,c";
96 Iterable<String> letters = COMMA_SPLITTER.split(doubled);

Callers

nothing calls this directly

Calls 1

onMethod · 0.95

Tested by

no test coverage detected