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