### Question:
URISupport { public static int indexOfParenthesisMatch(String str, int first) throws URISyntaxException { int index = -1; if (first < 0 || first > str.length()) { throw new IllegalArgumentException("Invalid position for first parenthesis: " + first); } if (str.charAt(first) != '(') { throw new IllegalArgumentException("character at indicated position is not a parenthesis"); } int depth = 1; char[] array = str.toCharArray(); for (index = first + 1; index < array.length; ++index) { char current = array[index]; if (current == '(') { depth++; } else if (current == ')') { if (--depth == 0) { break; } } } if (depth != 0) { throw new URISyntaxException(str, "URI did not contain a matching parenthesis."); } return index; }  static CompositeData parseComposite(URI uri); static boolean isCompositeURI(URI uri); static boolean checkParenthesis(String str); static int indexOfParenthesisMatch(String str, int first); static String[] splitComponents(String str); static URI removeQuery(URI uri); static Map<String, String> parseParameters(URI uri); static URI applyParameters(URI uri, Map<String, String> queryParameters); static URI applyParameters(URI uri, Map<String, String> queryParameters, String optionPrefix);  }### Answer:
@Test public void testIndexOfParenthesisMatch() throws URISyntaxException { String source1 = "a(b)c"; assertEquals(3, URISupport.indexOfParenthesisMatch(source1, 1)); String source2 = "(b)"; assertEquals(2, URISupport.indexOfParenthesisMatch(source2, 0)); String source3 = "()"; assertEquals(1, URISupport.indexOfParenthesisMatch(source3, 0)); }
@Test public void testIndexOfParenthesisMatchWhenNoMatchPresent() throws URISyntaxException { try { String source = "a(bc"; URISupport.indexOfParenthesisMatch(source, 1); fail("Should have thrown URISyntaxException"); } catch (URISyntaxException use) {} try { String source = "("; URISupport.indexOfParenthesisMatch(source, 0); fail("Should have thrown URISyntaxException"); } catch (URISyntaxException use) {} try { String source = "a("; URISupport.indexOfParenthesisMatch(source, 1); fail("Should have thrown URISyntaxException"); } catch (URISyntaxException use) {} }
@Test public void testIndexOfParenthesisMatchExceptions() throws URISyntaxException { try { URISupport.indexOfParenthesisMatch(null, -1); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iobe) {} try { URISupport.indexOfParenthesisMatch("tcp", 4); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iobe) {} try { URISupport.indexOfParenthesisMatch("tcp", 2); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iobe) {} try { URISupport.indexOfParenthesisMatch("(tcp", 0); fail("Should have thrown URISyntaxException"); } catch (URISyntaxException iobe) {} }