Class JUnit4TearDownNotRun

All Implemented Interfaces:
BugChecker.MethodTreeMatcher, Suppressible, Serializable

public class JUnit4TearDownNotRun extends BugChecker
Checks for the existence of a JUnit3 style tearDown() method in a JUnit4 test class or methods annotated with a non-JUnit4 @After annotation.
Author: (Nick Glorioso)
See Also:
  • Constructor Details

    • JUnit4TearDownNotRun

      public JUnit4TearDownNotRun()
  • Method Details

    • methodMatcher

      protected Matcher<com.sun.source.tree.MethodTree> methodMatcher()
      Returns a matcher that selects which methods this matcher applies to (e.g. public void setUp() without @Before/@BeforeClass annotation)
    • correctAnnotation

      protected String correctAnnotation()
      Returns the fully qualified class name of the annotation this bugpattern should apply to matched methods.

      If another annotation is on the method that has the same name, the import will be replaced with the appropriate one (e.g.: com.example.Before becomes org.junit.Before)

    • annotationReplacements

      protected List<> annotationReplacements()
      Returns a collection of 'before-and-after' pairs of annotations that should be replaced on these methods.

      If this method matcher finds a method annotated with AbstractJUnit4InitMethodNotRun.AnnotationReplacements.badAnnotation, instead of applying correctAnnotation(), instead replace it with AbstractJUnit4InitMethodNotRun.AnnotationReplacements.goodAnnotation

    • matchMethod

      public Description matchMethod(com.sun.source.tree.MethodTree methodTree, VisitorState state)
      Matches if all of the following conditions are true: 1) The method matches methodMatcher(), (looks like setUp() or tearDown(), and none of the overrides in the hierarchy of the method have the appropriate @Before or @After annotations) 2) The method is not annotated with @Test 3) The enclosing class has an @RunWith annotation and does not extend TestCase. This marks that the test is intended to run with JUnit 4.
      Specified by:
      matchMethod in interface BugChecker.MethodTreeMatcher