Recipe Name:
Use AssertJ's isNull() (with message)
Description:
Can be replaced with AssertJ style assertions
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • TestNG
Recipe
id: scw:assertj:junit-assert-null-message
version: 10
metadata:
  name: Use AssertJ's isNull() (with message)
  shortDescription: Can be replaced with AssertJ style assertions
  level: warning
  language: java
  enabled: true
  tags: AssertJ; TestNG
search:
  methodcall:
    argCount: 2
    name: assertNull
    anyOf:
    - args:
        1:
          type: String
      anyOf:
      - type: org.junit.Assert
      - type: junit.framework.TestCase
      - type: junit.framework.Assert
      - type: org.testng.AssertJUnit
    - args:
        2:
          type: String
      type: org.junit.jupiter.api.Assertions
availableFixes:
- doStaticImports: true
  name: Change to assertThat(actual).as(message).isNull()
  actions:
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              not:
                type: org.junit.jupiter.api.Assertions
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.1 }}}).as({{{ arguments.0 }}}).isNull()
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              type: org.junit.jupiter.api.Assertions
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.0 }}}).as({{{ arguments.1 }}}).isNull()