Recipe Name:
Use AssertJ's isNotNull() (with message)
Description:
Can be replaced with AssertJ style assertions
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • TestNG
Recipe
id: scw:assertj:junit-assert-not-null-message
version: 10
metadata:
  name: Use AssertJ's isNotNull() (with message)
  shortDescription: Can be replaced with AssertJ style assertions
  level: warning
  language: java
  enabled: true
  tags: AssertJ; TestNG
search:
  methodcall:
    argCount: 2
    name: assertNotNull
    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).isNotNull()
  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 }}}).isNotNull()
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              type: org.junit.jupiter.api.Assertions
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.0 }}}).as({{{ arguments.1 }}}).isNotNull()