Recipe Name:
Use hasSameSizeAs for comparing Collection sizes
Description:
Use hasSameSizeAs for comparing Collection sizes
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • framework specific
  • quality
Recipe
id: scw:assertj:idiomatic:collection-hasSameSizeAs
version: 10
metadata:
  name: Use hasSameSizeAs for comparing Collection sizes
  shortDescription: Use hasSameSizeAs for comparing Collection sizes
  level: warning
  language: java
  enabled: true
  tags: AssertJ;framework specific;quality
search:
  methodcall:
    args:
      1:
        value:
          is:
            methodcall:
              name: size
              label: sizeMethodCall1
              type:
                reference:
                  matches: Collection<.*>
                checkInheritance: true
    name: assertThat
    anyOf:
    - followedBy:
        methodcall:
          args:
            1:
              value:
                is:
                  methodcall:
                    name: size
                    label: sizeMethodCall2
                    type:
                      reference:
                        matches: Collection<.*>
                      checkInheritance: true
          name: isEqualTo
          label: isEqualToMethodCall
          type:
            reference:
              matches: org.assertj.core.api.AbstractIntegerAssert<.*>
            checkInheritance: true
    - followedBy:
        methodcall:
          followedBy:
            methodcall:
              args:
                1:
                  value:
                    is:
                      methodcall:
                        name: size
                        label: sizeMethodCall2
                        type:
                          reference:
                            matches: Collection<.*>
                          checkInheritance: true
              name: isEqualTo
              label: isEqualToMethodCall
          name:
            matches: (as|describedAs)
          type:
            reference:
              matches: org.assertj.core.api.AbstractIntegerAssert<.*>
            checkInheritance: true
availableFixes:
- doStaticImports: true
  name: Use idiomatic assertion
  actions:
  - rewrite:
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.0.qualifier }}})
  - changeName:
      name: hasSameSizeAs
      target: label:isEqualToMethodCall
  - rewrite:
      to: '{{{ qualifier }}}'
      target: label:sizeMethodCall2