package com.google.common.base; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Test; import com.google.common.base.Joiner.MapJoiner; public class TestJoiner { @Test public void appendToTest() { Joiner j = Joiner.on(','); List l = new ArrayList(); l.add("hello"); l.add("world"); String result = j.join(l); assertEquals("hello,world", result); } @Test public void skipNullsTest() { Joiner j = Joiner.on(',').skipNulls(); List l = new ArrayList(); l.add("hello"); l.add(null); l.add("world"); String result = j.join(l); assertEquals("hello,world", result); } @Test public void useForNullTest() { Joiner j = Joiner.on(',').useForNull("oops"); List l = new ArrayList(); l.add("hello"); l.add(null); l.add("world"); String result = j.join(l); assertEquals("hello,oops,world", result); } @Test public void withKeyValueSeparatorTest() { MapJoiner j = Joiner.on(',').withKeyValueSeparator("->"); Map m = new HashMap(); m.put("hello", "world"); m.put("bad", "boy"); String result = j.join(m); assertEquals("hello->world,bad->boy", result); } }