public void testCharacterSimpleSplitWithNoDelimiter() { String simple = "a,b,c"; Iterable<String> letters = Splitter.on('.').split(simple); assertThat(letters).containsExactly("a,b,c").inOrder(); }
public void testStringSplitWithTrailingDelimiter() { String trailing = "a,b,c,"; Iterable<String> letters = Splitter.on(",").split(trailing); assertThat(letters).containsExactly("a", "b", "c", "").inOrder(); }
public void testStringSplitWithMultipleLetters() { Iterable<String> testStringingMotto = Splitter.on("-").split("Testing-rocks-Debugging-sucks"); assertThat(testStringingMotto) .containsExactly("Testing", "rocks", "Debugging", "sucks") .inOrder(); }
public void testBuilderPutAllEntryListJdkBacked() { List<Entry<String, String>> entryList = Arrays.asList( new AbstractMap.SimpleEntry<>("a", "1"), new AbstractMap.SimpleEntry<>("b", "2")); ImmutableMap<String, String> map = ImmutableMap.<String, String>builder().putAll(entryList).buildJdkBacked(); assertThat(map).containsExactly("a", "1", "b", "2").inOrder(); entryList.get(0).setValue("3"); assertThat(map).containsExactly("a", "1", "b", "2").inOrder(); } }
@GwtIncompatible // java.util.regex.Pattern public void testPatternSplitWordBoundary_singleCharInput() { String string = "f"; Iterable<String> words = Splitter.on(Pattern.compile("\\b")).split(string); assertThat(words).containsExactly("f").inOrder(); }
public void testLimitExtraSeparatorsTrim3() { String text = ",,a,, , b ,, c,d "; Iterable<String> items = COMMA_SPLITTER.limit(3).omitEmptyStrings().trimResults().split(text); assertThat(items).containsExactly("a", "b", "c,d").inOrder(); }
public void testInsertionOrderAfterRemoveFirst() { BiMap<String, Integer> map = HashBiMap.create(); map.put("foo", 1); map.put("bar", 2); map.put("quux", 3); map.remove("foo"); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("bar", 2), Maps.immutableEntry("quux", 3)) .inOrder(); }
public void testCopyOfExplicit_iterator_ordering_dupes() { SortedSet<String> set = ImmutableSortedSet.copyOf( STRING_LENGTH, asIterator("in", "the", "quick", "brown", "fox", "jumped", "over", "a", "lazy", "dog")); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
@SuppressWarnings("unchecked") // varargs public void testHeadMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).headMap("three", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("one", 1), Maps.immutableEntry("three", 3)) .inOrder(); }
@SuppressWarnings("unchecked") // varargs public void testTailMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).tailMap("three", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("three", 3), Maps.immutableEntry("two", 2)) .inOrder(); }
@SuppressWarnings("unchecked") // varargs public void testSubMapExclusiveInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).subMap("one", false, "two", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("three", 3), Maps.immutableEntry("two", 2)) .inOrder(); }
@GwtIncompatible // java.util.regex.Pattern public void testPatternSplitWithDoubleDelimiterOmitEmptyStrings() { String doubled = "a..b.c"; Iterable<String> letters = Splitter.on(literalDotPattern()).omitEmptyStrings().split(doubled); assertThat(letters).containsExactly("a", "b", "c").inOrder(); }
@GwtIncompatible // java.util.regex.Pattern @AndroidIncompatible // Bug in older versions of Android we test against, since fixed. public void testPatternSplitWordBoundary() { String string = "foo<bar>bletch"; Iterable<String> words = Splitter.on(Pattern.compile("\\b")).split(string); assertThat(words).containsExactly("foo", "<", "bar", ">", "bletch").inOrder(); }
public void testMapSplitter_trimmedKeyValue() { Map<String, String> m = COMMA_SPLITTER .withKeyValueSeparator(Splitter.on(':').trimResults()) .split("boy : tom , girl: tina , cat : kitty , dog: tommy "); ImmutableMap<String, String> expected = ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy"); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
public void testMapSplitter_multiCharacterSeparator() { // try different delimiters. Map<String, String> m = Splitter.on(",") .withKeyValueSeparator(":^&") .split("boy:^&tom,girl:^&tina,cat:^&kitty,dog:^&tommy"); ImmutableMap<String, String> expected = ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy"); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
@GwtIncompatible // java.util.regex.Pattern public void testPatternSplitOnOnlyDelimiter() { Iterable<String> blankblank = Splitter.on(literalDotPattern()).split("."); assertThat(blankblank).containsExactly("", "").inOrder(); }
public void testToMap() { assertThat(fluent(1, 2, 3).toMap(Functions.toStringFunction()).entrySet()) .containsExactly( Maps.immutableEntry(1, "1"), Maps.immutableEntry(2, "2"), Maps.immutableEntry(3, "3")) .inOrder(); }
public void testMultisetsSpliterator() { Multiset<String> multiset = TreeMultiset.create(); multiset.add("a", 3); multiset.add("b", 1); multiset.add("c", 2); List<String> actualValues = Lists.newArrayList(); multiset.spliterator().forEachRemaining(actualValues::add); assertThat(multiset).containsExactly("a", "a", "a", "b", "c", "c").inOrder(); } }
public void testRetainOccurrences() { Multiset<String> multiset = TreeMultiset.create(Arrays.asList("a", "b", "a", "c")); Multiset<String> toRetain = HashMultiset.create(Arrays.asList("a", "b", "b")); assertTrue(Multisets.retainOccurrences(multiset, toRetain)); assertThat(multiset).containsExactly("a", "b").inOrder(); }