VariableUtils { public static String extractVariableName(String expression) { if (isEmpty(expression)) { return null; } Matcher matcher = regexPattern.matcher(expression); if (matcher.matches()) { return matcher.group(1); } return null; } private  VariableUtils(); static String extractVariableName(String expression);  }
@Test void extractValidVariableName() { assertEquals("var", extractVariableName("${var}")); assertEquals("var.subvar", extractVariableName("${var.subvar}")); }
@Test void invalidExpression() { assertNull(extractVariableName("${abc")); assertNull(extractVariableName("$abc")); assertNull(extractVariableName("abc")); assertNull(extractVariableName("${abc}${abc}")); }
@Test void nullExpression() { assertNull(extractVariableName(null)); assertNull(extractVariableName("")); }