Recipe Name:
Use AssertJ's isEqualToNormalizingWhitespace() instead of is(equalToCompressingWhiteSpace())
Description:
Can be replaced with AssertJ style assertions
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • Hamcrest
Recipe
id: scw:assertj:hamcrest-is-equal-to-compressing-white-space
version: 10
metadata:
  name: Use AssertJ's isEqualToNormalizingWhitespace() instead of is(equalToCompressingWhiteSpace())
  shortDescription: Can be replaced with AssertJ style assertions
  level: warning
  language: java
  enabled: true
  tags: AssertJ; Hamcrest
search:
  methodcall:
    name: assertThat
    anyOf:
    - args:
        2:
          value:
            is:
              methodcall:
                args:
                  1:
                    value:
                      is:
                        methodcall:
                          anyOf:
                          - name: equalToCompressingWhiteSpace
                            type: org.hamcrest.Matchers
                          - name: equalToCompressingWhiteSpace
                            type: org.hamcrest.text.IsEqualCompressingWhiteSpace
                          - name: equalToIgnoringWhiteSpace
                            type: org.hamcrest.text.IsEqualCompressingWhiteSpace
                name: is
                type:
                  reference:
                    matches: org\.hamcrest\.(CoreMatchers|Matchers|core\.Is)
                  checkInheritance: true
      argCount: 2
    - args:
        1:
          type: String
        3:
          value:
            is:
              methodcall:
                args:
                  1:
                    value:
                      is:
                        methodcall:
                          anyOf:
                          - name: equalToCompressingWhiteSpace
                            type: org.hamcrest.Matchers
                          - name: equalToCompressingWhiteSpace
                            type: org.hamcrest.text.IsEqualCompressingWhiteSpace
                          - name: equalToIgnoringWhiteSpace
                            type: org.hamcrest.text.IsEqualCompressingWhiteSpace
                name: is
                type:
                  reference:
                    matches: org\.hamcrest\.(CoreMatchers|Matchers|core\.Is)
                  checkInheritance: true
      argCount: 3
    type: org.hamcrest.MatcherAssert
availableFixes:
- doStaticImports: true
  name: Change to assertThat(actual).isEqualToNormalizingWhitespace(expected)
  availableIf:
    markedElement:
      is:
        methodcall:
          argCount: 2
  actions:
  - rewrite:
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.0 }}}).isEqualToNormalizingWhitespace({{{ arguments.1.arguments.0.arguments.0 }}})
- doStaticImports: true
  name: Change to assertThat(actual).as(reason).isEqualToNormalizingWhitespace(expected)
  availableIf:
    markedElement:
      is:
        methodcall:
          argCount: 3
  actions:
  - rewrite:
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.1 }}}).as({{{ arguments.0 }}}).isEqualToNormalizingWhitespace({{{ arguments.2.arguments.0.arguments.0 }}})