### Question:
CategoryStringGenerator { public static List<String> getPostgresCategoryString(String searchString, Map<String, String> mapPrefix, String prefixSplit ) { List<String> finalList = new ArrayList<String>(); if (searchString == null || !(searchString.trim().length() > 0)) { finalList.add( "{}" ); return finalList; } List<String> categories = parse(searchString.trim().toLowerCase()); List<String> catHolder = new ArrayList<String>(); for( String cat : categories ) { if (cat.matches( SearchToSqlConverter.BAD_SEARCH_REGEX ) ) { throw new IllegalArgumentException( SearchToSqlConverter.BAD_CHAR_MSG ); } if (prefixSplit != null ) { int index = cat.indexOf( prefixSplit ); if ( index != -1 ) { String prefix = cat.substring( 0, index ); String value = cat.substring( index + prefixSplit.length() ); if ( mapPrefix.containsKey( prefix ) ) { addToFinalList( finalList, catHolder ); finalList.add( value ); } else { catHolder.add( cat ); } } else { catHolder.add( cat ); } } else { catHolder.add( cat ); } } addToFinalList( finalList, catHolder ); return finalList; } private  CategoryStringGenerator(); static List<String> getPostgresCategoryString(String searchString, Map<String, String> mapPrefix, String prefixSplit );  }### Answer:
@Test public void shouldGenerateTwoItems() { List<String> result = CategoryStringGenerator.getPostgresCategoryString( COL_CAT, prefixMap, SPLIT ); assertEquals( result.size(), 2 ); assertEquals(result.get( 0 ), "col" ); assertEquals(result.get( 1 ), "{cat1}" ); }
@Test public void shouldGenerateThreeItems() { List<String> result = CategoryStringGenerator.getPostgresCategoryString( COL_CAT_3, prefixMap, SPLIT ); assertEquals( result.size(), 3 ); assertEquals(result.get( 0 ), "{cat1}" ); assertEquals(result.get( 1 ), "col" ); assertEquals(result.get( 2 ), "{cat2}" ); }
@Test public void shouldGenerateStringForSingleCategory() { List<String> result = CategoryStringGenerator.getPostgresCategoryString(SINGLE_CAT, Collections.EMPTY_MAP, null ); assertEquals( result.size(), 1 ); assertEquals(result.get( 0 ), SINGLE_CAT_RESULT); }
@Test public void shouldGenerateStringForMulitpleCategories() { List<String> result = CategoryStringGenerator.getPostgresCategoryString(MULTI_CAT, Collections.EMPTY_MAP, null ); assertEquals( result.size(), 1 ); assertEquals(result.get( 0 ), MULTI_CAT_RESULT); }
@Test(expected = IllegalArgumentException.class) public void shouldFailEmpty1() { List<String> result = CategoryStringGenerator.getPostgresCategoryString(EMPTY_CAT1, Collections.EMPTY_MAP, null ); }
@Test(expected = IllegalArgumentException.class) public void shouldFailEmpty2() { List<String> result = CategoryStringGenerator.getPostgresCategoryString(EMPTY_CAT2, Collections.EMPTY_MAP, null ); }
@Test(expected = IllegalArgumentException.class) public void shouldFailEmpty3() { List<String> result = CategoryStringGenerator.getPostgresCategoryString(EMPTY_CAT3, Collections.EMPTY_MAP, null ); }