Class AbstractMockChecker<T extends Annotation>

All Implemented Interfaces:
BugChecker.MethodInvocationTreeMatcher, BugChecker.VariableTreeMatcher, Suppressible, Serializable
Direct Known Subclasses:

public abstract class AbstractMockChecker<T extends Annotation>
extends BugChecker
implements BugChecker.MethodInvocationTreeMatcher, BugChecker.VariableTreeMatcher
Helper for enforcing Annotations that disallow mocking.
Author: (Alan Malloy)
See Also:
Serialized Form
  • Field Details


      public static final AbstractMockChecker.TypeExtractor<com.sun.source.tree.MethodInvocationTree> MOCKING_METHOD
      A TypeExtractor for method invocations that create a mock using Mockito.mock, Mockito.spy, or EasyMock.create[...]Mock, extracting the type being mocked.
  • Constructor Details

  • Method Details

    • forbidder

      protected AbstractMockChecker.MockForbidder forbidder()
      Produce a MockForbidder to use when looking for disallowed mocks, in addition to the built-in checks for Annotations of type T.

      This method will be called at most once for each instance of AbstractMockChecker, but of course the returned object's forbidReason method may be called many times.

      The default implementation forbids nothing.

    • extractType

      public static <T extends com.sun.source.tree.Tree> AbstractMockChecker.TypeExtractor<T> extractType​(Matcher<T> m)
      Produces an extractor which, if the tree matches, extracts the type of that tree, as given by ASTHelpers.getType(Tree).
    • extractFirstArg

      public static AbstractMockChecker.TypeExtractor<com.sun.source.tree.MethodInvocationTree> extractFirstArg​(Matcher<com.sun.source.tree.MethodInvocationTree> m)
      Produces an extractor which, if the tree matches, extracts the type of the first argument to the method invocation.
    • extractClassArg

      public static AbstractMockChecker.TypeExtractor<com.sun.source.tree.MethodInvocationTree> extractClassArg​(Matcher<com.sun.source.tree.MethodInvocationTree> m)
      Produces an extractor which, if the tree matches, extracts the type of the first argument whose type is Class (preserving its <T> type parameter, if it has one}.
      m - the matcher to use. It is an error for this matcher to succeed on any Tree that does not include at least one argument of type Class; if such a matcher is provided, the behavior of the returned Extractor is undefined.
    • fieldAnnotatedWithOneOf

      public static AbstractMockChecker.TypeExtractor<com.sun.source.tree.VariableTree> fieldAnnotatedWithOneOf​(Stream<String> annotationClasses)
      Creates a TypeExtractor that extracts the type of a class field if that field is annotated with any one of the given annotations.
    • matchMethodInvocation

      public final Description matchMethodInvocation​(com.sun.source.tree.MethodInvocationTree tree, VisitorState state)
      Specified by:
      matchMethodInvocation in interface BugChecker.MethodInvocationTreeMatcher
    • matchVariable

      public final Description matchVariable​(com.sun.source.tree.VariableTree tree, VisitorState state)
      Specified by:
      matchVariable in interface BugChecker.VariableTreeMatcher