### Question:
SearchUtils { public static Map<String, Object> collapseURLParams(MultivaluedMap<String, String> params) { Map output = new HashMap<>(); for (String key: params.keySet()) { List values = params.get(key); if (values != null) { output.put(key, values.size() == 1 ? values.get(0) : values.toArray()); } } return output; }  static Properties loadProperties(String path); static String trimToNull(String value); static List<String> safeList(List<String> values); static boolean isBlank(String value); static boolean isBlank(Object value); static String convertJsonMapToString(Map<String, Object> jsonMapValue); static DateFormat getISODateFormat(); static Date dateFromISOString(String string, boolean silent); static boolean isDateAfter(Object date, int thresholdInMinutes); static Map<String, Object> convertToJsonMap(String jsonData); static Integer getIntegerFromJsonMap(Map<String, Object> map, String key); @SuppressWarnings("unchecked") static List<String> getListOfStringsFromJsonMap(Map<String, Object> map, String key); static void mergeJsonMaps(Map<String, Object> source, Map<String, Object> target); static Map<String, Object> collapseURLParams(MultivaluedMap<String, String> params); static boolean isMysqlDialect(String databaseProductName);  }### Answer:
@Test public void collapseURLParams() { { MultivaluedMap<String, String> map = new MultivaluedMapImpl<>(); Map<String, Object> collapsedMap = SearchUtils.collapseURLParams(map); Assert.assertTrue(collapsedMap.isEmpty()); } { MultivaluedMap<String, String> map = new MultivaluedMapImpl<>(); map.put(null, null); Map<String, Object> collapsedMap = SearchUtils.collapseURLParams(map); Assert.assertTrue(collapsedMap.isEmpty()); } { MultivaluedMap<String, String> map = new MultivaluedMapImpl<>(); map.put("key1", null); Map<String, Object> collapsedMap = SearchUtils.collapseURLParams(map); Assert.assertTrue(collapsedMap.isEmpty()); } { List<String> values = new ArrayList<>(); values.add("value1"); values.add("value2"); values.add("value3"); MultivaluedMap<String, String> map = new MultivaluedMapImpl<>(); map.put("key1", values); Map<String, Object> collapsedMap = SearchUtils.collapseURLParams(map); Assert.assertFalse(collapsedMap.isEmpty()); Assert.assertEquals(1, collapsedMap.keySet().size()); Assert.assertTrue(collapsedMap.containsKey("key1")); Assert.assertTrue(collapsedMap.get("key1") instanceof Object[]); Assert.assertArrayEquals(values.toArray(), (Object[]) collapsedMap.get("key1")); } { List<String> values = new ArrayList<>(); values.add(null); values.add(null); values.add(null); MultivaluedMap<String, String> map = new MultivaluedMapImpl<>(); map.put("key1", values); Map<String, Object> collapsedMap = SearchUtils.collapseURLParams(map); Assert.assertFalse(collapsedMap.isEmpty()); Assert.assertEquals(1, collapsedMap.keySet().size()); Assert.assertTrue(collapsedMap.containsKey("key1")); Assert.assertTrue(collapsedMap.get("key1") instanceof Object[]); Assert.assertArrayEquals(values.toArray(), (Object[]) collapsedMap.get("key1")); } { List<String> values = new ArrayList<>(); values.add("value1"); MultivaluedMap<String, String> map = new MultivaluedMapImpl<>(); map.put("key1", values); Map<String, Object> collapsedMap = SearchUtils.collapseURLParams(map); Assert.assertFalse(collapsedMap.isEmpty()); Assert.assertEquals(1, collapsedMap.keySet().size()); Assert.assertTrue(collapsedMap.containsKey("key1")); Assert.assertTrue(collapsedMap.get("key1") instanceof String); Assert.assertEquals(values.get(0), collapsedMap.get("key1")); } }