### Question:
StringLiteral implements Matcher<ExpressionTree> { @Override public boolean matches(ExpressionTree expressionTree, VisitorState state) { if (expressionTree instanceof LiteralTree) { LiteralTree literalTree = (LiteralTree) expressionTree; Object actualValue = literalTree.getValue(); return actualValue instanceof String && pattern.matcher((String) actualValue).matches(); } else { return false; } } StringLiteral(String value);  StringLiteral(Pattern pattern); @Override boolean matches(ExpressionTree expressionTree, VisitorState state);  }### Answer:
@Test public void matches() { LiteralTree tree = new LiteralTree() { @Override public Kind getKind() { throw new UnsupportedOperationException(); } @Override public <R, D> R accept(TreeVisitor<R, D> visitor, D data) { throw new UnsupportedOperationException(); } @Override public Object getValue() { return "a string literal"; } }; assertThat(new StringLiteral("a string literal").matches(tree, null)).isTrue(); }
@Test public void notMatches() { LiteralTree tree = new LiteralTree() { @Override public Kind getKind() { throw new UnsupportedOperationException(); } @Override public <R, D> R accept(TreeVisitor<R, D> visitor, D data) { throw new UnsupportedOperationException(); } @Override public Object getValue() { return "a string literal"; } }; assertThat(new StringLiteral("different string").matches(tree, null)).isFalse(); IdentifierTree idTree = new IdentifierTree() { @Override public Name getName() { return null; } @Override public Kind getKind() { throw new UnsupportedOperationException(); } @Override public <R, D> R accept(TreeVisitor<R, D> visitor, D data) { throw new UnsupportedOperationException(); } }; assertThat(new StringLiteral("test").matches(idTree, null)).isFalse(); LiteralTree intTree = new LiteralTree() { @Override public Object getValue() { return 5; } @Override public Kind getKind() { throw new UnsupportedOperationException(); } @Override public <R, D> R accept(TreeVisitor<R, D> visitor, D data) { throw new UnsupportedOperationException(); } }; assertThat(new StringLiteral("test").matches(intTree, null)).isFalse(); }