### Question:
StringUtils { public static boolean checkStaticExistence(String expr, String sequence) throws ELEvaluationException { int curlyBracketDept = 0; int functionDepth = 0; int index = 0; boolean foundSequence = false; while (index < expr.length()) { String substring = expr.substring(index); if (substring.startsWith("${")) { ++curlyBracketDept; } else if (substring.startsWith("}")) { --curlyBracketDept; if (curlyBracketDept < 0) { throw new ELEvaluationException("Invalid curly bracket closing"); } } if (curlyBracketDept > 0) { if (substring.startsWith("(")) { ++functionDepth; } else if (substring.startsWith(")")) { --functionDepth; if (functionDepth < 0) { throw new ELEvaluationException("Invalid function closing"); } } } if (curlyBracketDept == 0 && substring.startsWith(sequence)) { foundSequence = true; } if (curlyBracketDept > 0 && functionDepth == 0 && substring.startsWith(sequence)) { foundSequence = true; } ++index; } if (curlyBracketDept != 0) { throw new ELEvaluationException("Unclosed curly brackets"); } if (functionDepth != 0) { throw new ELEvaluationException("Unfinished function calling"); } return foundSequence; }  static String trim(String str); static String intern(String str); static boolean checkStaticExistence(String expr, String sequence);  }### Answer:
@Test public void testCheckStaticExistenceWithValidExpressions() throws ELEvaluationException { assertFalse(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("ab", ",")); assertTrue(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("${a:a()}${a:a()}!", "!")); assertTrue(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("${a:a()},${a:a()}", ",")); assertFalse(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("${a:d('foo', 'bar')}", ",")); assertTrue(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("${a:a(), a:a()}", ",")); assertTrue(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("a,b", ",")); assertTrue(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("'a,b'", ",")); assertFalse(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("${func(a,b)}", ",")); assertFalse(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("${func('a','b')}", ",")); assertTrue(ASSERT_MESSAGE_CHECK_STATIC_EXISTENCE, StringUtils.checkStaticExistence("${func('abc')},${func('def')}", ",")); }
@Test public void testUnclosedCurlyBracket() throws ELEvaluationException { expectedException.expect(ELEvaluationException.class); StringUtils.checkStaticExistence("${", ","); }
@Test public void testClosingTooManyCurlyBracket() throws ELEvaluationException { expectedException.expect(ELEvaluationException.class); StringUtils.checkStaticExistence("${a:a()}}", ","); }
@Test public void testUnclosedFunctionCall() throws ELEvaluationException { expectedException.expect(ELEvaluationException.class); StringUtils.checkStaticExistence("${a:a(}", ","); }
@Test public void testTooManyParanthesisClosing() throws ELEvaluationException { expectedException.expect(ELEvaluationException.class); StringUtils.checkStaticExistence("${a:a())}", ","); }
@Test public void testSequenceBeforeInvalidPart() throws ELEvaluationException { expectedException.expect(ELEvaluationException.class); StringUtils.checkStaticExistence("${a:a(),b:b(),c:c(}", ","); }