### Question:
FilterParser { public static ListMultimap<String, String> parseFilter(String filterString) throws ServletException { ListMultimap<String, String> filterFieldMap = LinkedListMultimap.create(); if (filterString != null) { StringTokenizer st = new StringTokenizer(filterString, PARAMETER_DELIMITER); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.contains(PARAMETER_EQUALS)) { String[] nameValuePair = token.split(PARAMETER_EQUALS); if (nameValuePair.length != 2) { filterFormatError(filterString); } String key = nameValuePair[0]; String value = nameValuePair[1]; if (Strings.isNullOrEmpty(key)) { filterFormatError(filterString); } filterFieldMap.put(key, value); } else { filterFormatError(filterString); } } } return filterFieldMap; }  static ListMultimap<String, String> parseFilter(String filterString);  }### Answer:
@Test public void testNullFilter() throws ServletException { Multimap<String, String> filterMap = FilterParser.parseFilter(null); assertEquals("Filter map size should be zero for null filter", 0, filterMap.size()); }
@Test public void testEmptyString() throws ServletException { Multimap<String, String> filterMap = FilterParser.parseFilter(""); assertEquals("Filter map size should be zero for empty filter", 0, filterMap.size()); }
@Test public void testMissingEquals() throws ServletException { expectedException.expect(ServletException.class); FilterParser.parseFilter("keyvalue"); }
@Test public void testMissingKey() throws ServletException { expectedException.expect(ServletException.class); FilterParser.parseFilter("=value"); }
@Test public void testTooManyEquals() throws ServletException { expectedException.expect(ServletException.class); FilterParser.parseFilter("key=value1=value2"); }
@Test public void testMissingValue() throws ServletException { expectedException.expect(ServletException.class); FilterParser.parseFilter("key1="); }
@Test public void testSingleParameter() throws ServletException { ListMultimap<String, String> filterMap = FilterParser.parseFilter("key1=value1"); ListMultimap<String, String> expectedMap = LinkedListMultimap.create(); expectedMap.put("key1", "value1"); assertEquals("Different filter map", expectedMap, filterMap); }
@Test public void testTwoParameters() throws ServletException { Multimap<String, String> filterMap = FilterParser.parseFilter("key1=value1;key2=value2"); ListMultimap<String, String> expectedMap = LinkedListMultimap.create(); expectedMap.put("key1", "value1"); expectedMap.put("key2", "value2"); assertEquals("Different filter map", expectedMap, filterMap); }
@Test public void testRepeatedKeys() throws ServletException { Multimap<String, String> filterMap = FilterParser.parseFilter("key1=value1;key1=value2"); ListMultimap<String, String> expectedMap = LinkedListMultimap.create(); expectedMap.put("key1", "value1"); expectedMap.put("key1", "value2"); assertEquals("Different filter map", expectedMap, filterMap); }