Class JUnit4SetUpNotRun
- java.lang.Object
-
- com.google.errorprone.bugpatterns.BugChecker
-
- com.google.errorprone.bugpatterns.JUnit4SetUpNotRun
-
- All Implemented Interfaces:
BugChecker.MethodTreeMatcher
,Suppressible
,Serializable
public class JUnit4SetUpNotRun extends BugChecker
Checks for the existence of a JUnit3 style setUp() method in a JUnit4 test class or methods annotated with a non-JUnit4 @Before annotation.- Author:
- [email protected] (Nick Glorioso)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.errorprone.bugpatterns.BugChecker
BugChecker.AnnotatedTypeTreeMatcher, BugChecker.AnnotationTreeMatcher, BugChecker.ArrayAccessTreeMatcher, BugChecker.ArrayTypeTreeMatcher, BugChecker.AssertTreeMatcher, BugChecker.AssignmentTreeMatcher, BugChecker.BinaryTreeMatcher, BugChecker.BlockTreeMatcher, BugChecker.BreakTreeMatcher, BugChecker.CaseTreeMatcher, BugChecker.CatchTreeMatcher, BugChecker.ClassTreeMatcher, BugChecker.CompilationUnitTreeMatcher, BugChecker.CompoundAssignmentTreeMatcher, BugChecker.ConditionalExpressionTreeMatcher, BugChecker.ContinueTreeMatcher, BugChecker.DoWhileLoopTreeMatcher, BugChecker.EmptyStatementTreeMatcher, BugChecker.EnhancedForLoopTreeMatcher, BugChecker.ExpressionStatementTreeMatcher, BugChecker.ForLoopTreeMatcher, BugChecker.IdentifierTreeMatcher, BugChecker.IfTreeMatcher, BugChecker.ImportTreeMatcher, BugChecker.InstanceOfTreeMatcher, BugChecker.IntersectionTypeTreeMatcher, BugChecker.LabeledStatementTreeMatcher, BugChecker.LambdaExpressionTreeMatcher, BugChecker.LiteralTreeMatcher, BugChecker.MemberReferenceTreeMatcher, BugChecker.MemberSelectTreeMatcher, BugChecker.MethodInvocationTreeMatcher, BugChecker.MethodTreeMatcher, BugChecker.ModifiersTreeMatcher, BugChecker.NewArrayTreeMatcher, BugChecker.NewClassTreeMatcher, BugChecker.ParameterizedTypeTreeMatcher, BugChecker.ParenthesizedTreeMatcher, BugChecker.PrimitiveTypeTreeMatcher, BugChecker.ReturnTreeMatcher, BugChecker.SuppressibleTreePathScanner<A extends Object,B extends Object>, BugChecker.SwitchTreeMatcher, BugChecker.SynchronizedTreeMatcher, BugChecker.ThrowTreeMatcher, BugChecker.TryTreeMatcher, BugChecker.TypeCastTreeMatcher, BugChecker.TypeParameterTreeMatcher, BugChecker.UnaryTreeMatcher, BugChecker.UnionTypeTreeMatcher, BugChecker.VariableTreeMatcher, BugChecker.WhileLoopTreeMatcher, BugChecker.WildcardTreeMatcher
-
-
Constructor Summary
Constructors Constructor Description JUnit4SetUpNotRun()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<AbstractJUnit4InitMethodNotRun.AnnotationReplacements>
annotationReplacements()
Returns a collection of 'before-and-after' pairs of annotations that should be replaced on these methods.protected String
correctAnnotation()
Returns the fully qualified class name of the annotation this bugpattern should apply to matched methods.Description
matchMethod(com.sun.source.tree.MethodTree methodTree, VisitorState state)
Matches if all of the following conditions are true: 1) The method matchesmethodMatcher()
, (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.protected Matcher<com.sun.source.tree.MethodTree>
methodMatcher()
Returns a matcher that selects which methods this matcher applies to (e.g.-
Methods inherited from class com.google.errorprone.bugpatterns.BugChecker
allNames, buildDescription, buildDescription, buildDescription, canonicalName, customSuppressionAnnotations, defaultSeverity, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, disableable, equals, hashCode, isSuppressed, isSuppressed, isSuppressed, isSuppressed, linkUrl, message, supportsSuppressWarnings, suppressedByAnyOf, suppressedRegions
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.errorprone.matchers.Suppressible
allNames, canonicalName, customSuppressionAnnotations, supportsSuppressWarnings, suppressedByAnyOf
-
-
-
-
Method Detail
-
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<AbstractJUnit4InitMethodNotRun.AnnotationReplacements> 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 applyingcorrectAnnotation()
, instead replace it withAbstractJUnit4InitMethodNotRun.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 matchesmethodMatcher()
, (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 interfaceBugChecker.MethodTreeMatcher
-
-