### Question:
Query { public static boolean isValidExpression(final String value) { try { validateExpression(value, false); return true; } catch (final AttributeExpressionLanguageParsingException | ProcessException e) { return false; } } private  Query(final String query, final Tree tree, final Evaluator<?> evaluator); static boolean isValidExpression(final String value); static ResultType getResultType(final String value); static List<ResultType> extractResultTypes(final String value); static List<String> extractExpressions(final String value); static List<Range> extractExpressionRanges(final String value); static void validateExpression(final String value, final boolean allowSurroundingCharacters); static String unescape(final String value); static Query fromTree(final Tree tree, final String text); static PreparedQuery prepare(final String query); static Query compile(final String query); ResultType getResultType(); @Override String toString();  }### Answer:
@Test public void testIsValidExpression() { Query.validateExpression("${abc:substring(${xyz:length()})}", false); Query.isValidExpression("${now():format('yyyy-MM-dd')}"); try { Query.validateExpression("$${attr}", false); Assert.fail("invalid query validated"); } catch (final AttributeExpressionLanguageParsingException e) { } Query.validateExpression("$${attr}", true); Query.validateExpression("${filename:startsWith('T8MTXBC')\n" + ":or( ${filename:startsWith('C4QXABC')} )\n" + ":or( ${filename:startsWith('U6CXEBC')} )" + ":or( ${filename:startsWith('KYM3ABC')} )}", false); }
@Test public void testFunctionAfterReduce() { assertFalse(Query.isValidExpression("${allMatchingAttributes('a.*'):contains('2'):count():gt(2)}")); final Map<String, String> attributes = new HashMap<>(); attributes.put("a.1", "245"); attributes.put("a.2", "123"); attributes.put("a.3", "732"); attributes.put("a.4", "343"); attributes.put("a.5", "553"); final String endsWithCount = "${allMatchingAttributes('a.*'):contains('2'):count()}"; assertTrue(Query.isValidExpression(endsWithCount)); verifyEquals(endsWithCount, attributes, 3L); final String usingLiteral = "${literal(" + endsWithCount + "):gt(2)}"; assertTrue(Query.isValidExpression(usingLiteral)); verifyEquals(usingLiteral, attributes, true); attributes.clear(); attributes.put("a1", "123"); attributes.put("a2", "321"); verifyEquals("${allMatchingAttributes('a.*'):contains('2')}", attributes, true); verifyEquals("${allMatchingAttributes('a.*'):contains('2'):toUpper():equals('TRUE')}", attributes, true); verifyEquals("${allMatchingAttributes('a.*'):contains('2'):equals('true'):and( ${literal(true)} )}", attributes, true); }