Class UnitTestUtils
java.lang.Object
org.sonar.java.checks.helpers.UnitTestUtils
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MethodMatchersstatic final Patternstatic final MethodMatchersstatic final MethodMatchersMatch when we are sure that the intention is to assert something, that will result in an AssertionError if the assertion fails.static final MethodMatchersstatic final MethodMatchers -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<MethodInvocationTree> Checks if the given block tree's last statement is a call to a fail method, and if so, returns the corresponding method invocation tree.groupJUnit5Methods(ClassTree classTree) Categorizes the methods of a JUnit 5 test class into three groups: class lifecycle methods (@BeforeAll/@AfterAll), instance methods (@Test/@BeforeEach/etc.), and other (non-JUnit 5) methods.static booleanstatic booleanstatic booleanstatic booleanhasNestedAnnotation(ClassTree tree) static booleanhasTestAnnotation(MethodTree tree) static booleanstatic booleanisTestClass(ClassTree classTree) static booleanisUnitTest(MethodTree methodTree) static booleanstatic booleanmethodNameMatchesAssertionMethodPattern(String methodName, Symbol methodSymbol)
-
Field Details
-
ASSERTION_METHODS_PATTERN
-
ASSERTION_INVOCATION_MATCHERS
-
REACTIVE_X_TEST_METHODS
-
FAIL_METHOD_MATCHER
-
ASSERTIONS_METHOD_MATCHER
-
COMMON_ASSERTION_MATCHER
Match when we are sure that the intention is to assert something, that will result in an AssertionError if the assertion fails. The purpose is not to detect any assertion method (similar to S2699). -
JUNIT5_TEST_ANNOTATIONS
-
-
Method Details
-
groupJUnit5Methods
Categorizes the methods of a JUnit 5 test class into three groups: class lifecycle methods (@BeforeAll/@AfterAll), instance methods (@Test/@BeforeEach/etc.), and other (non-JUnit 5) methods. Overriding methods are excluded from the JUnit 5 groups. -
hasNestedAnnotation
-
hasTestAnnotation
-
hasJUnitJupiterAnnotation
-
hasJUnit5InstanceLifecycleAnnotation
-
hasJUnit5ClassLifecycleAnnotation
-
isInUnitTestRelatedToObjectMethods
-
isUnitTestRelatedToObjectMethods
-
isUnitTest
-
isTestClass
-
methodNameMatchesAssertionMethodPattern
-
findFail
Checks if the given block tree's last statement is a call to a fail method, and if so, returns the corresponding method invocation tree.- Parameters:
block- the block tree to check- Returns:
- an optional containing the method invocation tree if the last statement is a call to a fail method, or an empty optional otherwise
-