### Question:
StringFormatUtil { public static String removeQueryParameter(String query, String key) { int index = query.indexOf("&" + key + "="); boolean isFirstParameter = false; if (index == -1) { index = query.indexOf(key + "="); if (index == -1) { return query; } isFirstParameter = index > 0 && query.charAt(index - 1) == '?'; if (!isFirstParameter) { return query; } } int end = query.indexOf('&', index + 1); if (end == -1) { return query.substring(0, index - (isFirstParameter ? 1 : 0)); } return query.substring(0, index) + query.substring(end + (isFirstParameter ? 1 : 0)); } private  StringFormatUtil(); static String formatFilesize(String filesize, int decimalPlaces); static String formatFilesize(long filesize, int decimalPlaces); static String truncateText(String text, int length); static String urlEncode(String value); static String removeQueryParameter(String query, String key); static String makeToken(String input, String replacement);  }### Answer:
@Test public void testRemoveOnlyQueryParameter() { String query = BASE_URL + "?param=val"; assertEquals(BASE_URL, StringFormatUtil.removeQueryParameter(query, "param")); }
@Test public void testRemoveSecondQueryParameter() { String query = BASE_URL + "?first=val&second=2"; assertEquals(BASE_URL + "?first=val", StringFormatUtil.removeQueryParameter(query, "second")); }
@Test public void testRemoveFirstQueryParameter() { String query = BASE_URL + "?first=val&second=2"; assertEquals(BASE_URL + "?second=2", StringFormatUtil.removeQueryParameter(query, "first")); }
@Test public void testRemoveQueryParameterNotPresent() { String query = BASE_URL + "?first=val&second=2"; assertEquals(query, StringFormatUtil.removeQueryParameter(query, "other")); }