j.appendTo(sb, ImmutableMap.of(1, 2, 3, 4, 5, 6));
assertEquals("1:2;3:4;5:6", sb.toString());
}
public void testEntries() {
MapJoiner j = Joiner.on(";").withKeyValueSeparator(":");
assertEquals("", j.join(ImmutableMultimap.of().entries()));
assertEquals("", j.join(ImmutableMultimap.of().entries().iterator()));
assertEquals(":", j.join(ImmutableMultimap.of("", "").entries()));
assertEquals(":", j.join(ImmutableMultimap.of("", "").entries().iterator()));
assertEquals("1:a;1:b", j.join(ImmutableMultimap.of("1", "a", "1", "b").entries()));
assertEquals("1:a;1:b", j.join(ImmutableMultimap.of("1", "a", "1", "b").entries().iterator()));
Map<String, String> mapWithNulls = Maps.newLinkedHashMap();
mapWithNulls.put("a", null);
mapWithNulls.put(null, "b");
Set<Map.Entry<String, String>> entriesWithNulls = mapWithNulls.entrySet();
try {
j.join(entriesWithNulls);
fail();
} catch (NullPointerException expected) {
}
try {
j.join(entriesWithNulls.iterator());
fail();
} catch (NullPointerException expected) {
}
assertEquals("a:00;00:b", j.useForNull("00").join(entriesWithNulls));
assertEquals("a:00;00:b", j.useForNull("00").join(entriesWithNulls.iterator()));
StringBuilder sb1 = new StringBuilder();
j.appendTo(sb1, ImmutableMultimap.of(1, 2, 3, 4, 5, 6, 1, 3, 5, 10).entries());
assertEquals("1:2;1:3;3:4;5:6;5:10", sb1.toString());
StringBuilder sb2 = new StringBuilder();
j.appendTo(sb2, ImmutableMultimap.of(1, 2, 3, 4, 5, 6, 1, 3, 5, 10).entries().iterator());
assertEquals("1:2;1:3;3:4;5:6;5:10", sb2.toString());
}