BracketMatcher { public static int getClosingParenthesisIndex(CharSequence chars, int startIndex) { return getClosingBracketIndex(chars, startIndex, "(", ")"); }  static int getClosingParenthesisIndex(CharSequence chars, int startIndex); static int getClosingSquareBracketIndex(CharSequence chars, int startIndex); static int getClosingCurlyBraceIndex(CharSequence chars, int startIndex); static int getClosingTagIndex(CharSequence chars, int startIndex); static int getClosingBracketIndex(CharSequence chars, int startIndex, String openBracket, String closeBracket);  }
@Test public void matchParenthesis() { assertEquals(2, BracketMatcher.getClosingParenthesisIndex("(a)", 0)); }
@Test public void matchOuterNestedParenthesis() { assertEquals(9, BracketMatcher.getClosingParenthesisIndex("a(a1(a1a))", 1)); }
@Test public void matchInnerNestedParenthesis() { assertEquals(8, BracketMatcher.getClosingParenthesisIndex("a(a1(a1a))", 4)); }
@Test(expected = IllegalArgumentException.class) public void invalidOpenParenthesisStartIndexThrowsException() { BracketMatcher.getClosingParenthesisIndex("a(a1)", 0); }
@Test(expected = IllegalArgumentException.class) public void unclosedParenthesisThrowsException() { BracketMatcher.getClosingParenthesisIndex("a(a1", 1); }