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