ListSplitter { public static String[] split(final String valueList) { return split("'", false, valueList); }  static String[] split(final String valueList); static String[] split(final String quoteCharacter,
                                 final boolean trim,
                                 final String valueList); static String[] splitPreserveQuotes(final String quoteCharacter,
                                               final boolean trim,
                                               final String valueList);  }
@Test public void basicABC() { final String[] split = ListSplitter.split("a,b,c"); assertEquals(3, split.length); assertEquals("a", split[0]); assertEquals("b", split[1]); assertEquals("c", split[2]); }
@Test public void testQuoteCharacterUsedJustForComplexEnumMiddle() { final String[] split = ListSplitter.split("\"", true, "Prague, \"Helsinki, Finland\", Boston"); assertEquals(3, split.length); assertEquals("Prague", split[0]); assertEquals("Helsinki, Finland", split[1]); assertEquals("Boston", split[2]); }
@Test public void testDoubleQuotes() { final String[] split = ListSplitter.split("\"", true, " \"Prague\", \"\"Helsinki, Finland\"\" "); assertEquals(2, split.length); assertEquals("Prague", split[0]); assertEquals("\"Helsinki, Finland\"", split[1]); }
@Test public void testJustOneItem() { final String[] split = ListSplitter.split("\"", true, " \"Prague\" "); assertEquals(1, split.length); assertEquals("Prague", split[0]); }
@Test public void testJustOneComplexItem() { final String[] split = ListSplitter.split("\"", true, " \"Prague, Czechia\" "); assertEquals(1, split.length); assertEquals("Prague, Czechia", split[0]); }
@Test public void testQuoteCharacterUsedJustForComplexEnumStart() { final String[] split = ListSplitter.split("\"", true, "\"Helsinki, Finland\", Prague, Boston"); assertEquals(3, split.length); assertEquals("Helsinki, Finland", split[0]); assertEquals("Prague", split[1]); assertEquals("Boston", split[2]); }
@Test public void keepSpacesABC() { final String[] split = ListSplitter.split("a, b ,c"); assertEquals(3, split.length); assertEquals("a", split[0]); assertEquals(" b ", split[1]); assertEquals("c", split[2]); }
@Test public void specialABC() { final String[] split = ListSplitter.split("'a','b','c'"); assertEquals(3, split.length); assertEquals("a", split[0]); assertEquals("b", split[1]); assertEquals("c", split[2]); }
@Test public void specialABCSpaces() { final String[] split = ListSplitter.split(" 'a' , 'b' , 'c' "); assertEquals(3, split.length); assertEquals("a", split[0]); assertEquals("b", split[1]); assertEquals("c", split[2]); }
@Test public void basicCharacters() { final String[] split = ListSplitter.split("',!,%,)"); assertEquals(4, split.length); assertEquals("'", split[0]); assertEquals("!", split[1]); assertEquals("%", split[2]); assertEquals(")", split[3]); }
@Test public void splitItemsWithCommas() { final String[] split = ListSplitter.split("'One sentence.','Another one, but with comma.','Third one. I'll make things, if possible, even more complicated.'"); assertEquals(3, split.length); assertEquals("One sentence.", split[0]); assertEquals("Another one, but with comma.", split[1]); assertEquals("Third one. I'll make things, if possible, even more complicated.", split[2]); }
@Test public void changeQuoteCharacter() { final String[] split = ListSplitter.split("\"", true, "\"Helsinki, Finland\", Boston"); assertEquals(2, split.length); assertEquals("Helsinki, Finland", split[0]); assertEquals("Boston", split[1]); }
@Test public void changeQuoteCharacterSkipTrimming() { final String[] split = ListSplitter.split("\"", false, "\"Helsinki, Finland\", Boston"); assertEquals(2, split.length); assertEquals("Helsinki, Finland", split[0]); assertEquals(" Boston", split[1]); }
@Test public void testQuoteCharacterUsedJustForComplexEnumEnd() { final String[] split = ListSplitter.split("\"", true, "Prague, Boston, \"Helsinki, Finland\""); assertEquals(3, split.length); assertEquals("Prague", split[0]); assertEquals("Boston", split[1]); assertEquals("Helsinki, Finland", split[2]); }