Recipe Name:
Use AssertJ's fail()
Description:
Use AssertJ's fail()
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • TestNG
Recipe
id: scw:assertj:junit-fail
version: 10
metadata:
  name: Use AssertJ's fail()
  shortDescription: Use AssertJ's fail()
  level: warning
  language: java
  enabled: true
  tags: AssertJ; TestNG
search:
  methodcall:
    with:
      anyOf:
      - argCount: 0
      - args:
          1:
            type: String
        argCount: 1
    argCount:
      lessThanOrEquals: 2
    name: fail
    anyOf:
    - type: org.junit.Assert
    - type: junit.framework.TestCase
    - type: junit.framework.Assert
    - type: org.junit.jupiter.api.Assertions
    - type: org.testng.AssertJUnit
availableFixes:
- doStaticImports: true
  name: Use AssertJ's fail()
  actions:
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              argCount: 0
      to: org.assertj.core.api.Assertions.fail("")
      target: self
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              argCount: 1
      to: org.assertj.core.api.Assertions.fail({{{ arguments.0 }}})
      target: self