Class UnitTestUtils

java.lang.Object
org.sonar.java.checks.helpers.UnitTestUtils

public final class UnitTestUtils extends Object
  • Field Details

    • ASSERTION_METHODS_PATTERN

      public static final Pattern ASSERTION_METHODS_PATTERN
    • ASSERTION_INVOCATION_MATCHERS

      public static final MethodMatchers ASSERTION_INVOCATION_MATCHERS
    • REACTIVE_X_TEST_METHODS

      public static final MethodMatchers REACTIVE_X_TEST_METHODS
    • FAIL_METHOD_MATCHER

      public static final MethodMatchers FAIL_METHOD_MATCHER
    • ASSERTIONS_METHOD_MATCHER

      public static final MethodMatchers ASSERTIONS_METHOD_MATCHER
    • COMMON_ASSERTION_MATCHER

      public static final MethodMatchers 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

      public static final Set<String> JUNIT5_TEST_ANNOTATIONS
  • Method Details

    • hasNestedAnnotation

      public static boolean hasNestedAnnotation(ClassTree tree)
    • hasTestAnnotation

      public static boolean hasTestAnnotation(MethodTree tree)
    • hasJUnitJupiterAnnotation

      public static boolean hasJUnitJupiterAnnotation(MethodTree tree)
    • hasJUnit5InstanceLifecycleAnnotation

      public static boolean hasJUnit5InstanceLifecycleAnnotation(MethodTree tree)
    • hasJUnit5ClassLifecycleAnnotation

      public static boolean hasJUnit5ClassLifecycleAnnotation(MethodTree tree)
    • isInUnitTestRelatedToObjectMethods

      public static boolean isInUnitTestRelatedToObjectMethods(ExpressionTree expr)
    • isUnitTestRelatedToObjectMethods

      public static boolean isUnitTestRelatedToObjectMethods(@Nullable MethodTree method)
    • isUnitTest

      public static boolean isUnitTest(MethodTree methodTree)
    • isTestClass

      public static boolean isTestClass(ClassTree classTree)
    • methodNameMatchesAssertionMethodPattern

      public static boolean methodNameMatchesAssertionMethodPattern(String methodName, Symbol methodSymbol)
    • findFail

      public static Optional<MethodInvocationTree> findFail(BlockTree block)
      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