Recipe Name:
Use isEmpty for checking for collection with no elements
Description:
Use isEmpty for checking for collection with no elements
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • framework specific
  • quality
Recipe
id: scw:assertj:idiomatic:collection-hasSizeLessThanOne
version: 10
metadata:
  name: Use isEmpty for checking for collection with no elements
  shortDescription: Use isEmpty for checking for collection with no elements
  level: warning
  language: java
  enabled: true
  tags: AssertJ;framework specific;quality
search:
  methodcall:
    args:
      1:
        type:
          reference:
            matches: Collection<.*>
          checkInheritance: true
    argCount: 1
    name: assertThat
    anyOf:
    - followedBy:
        methodcall:
          args:
            1:
              value:
                integer: 1
          argCount: 1
          name: hasSizeLessThan
          label: hasSizeLessThanMethodCall
          type:
            reference:
              matches: org.assertj.core.api.AbstractIterableAssert<.*>
            checkInheritance: true
    - followedBy:
        methodcall:
          followedBy:
            methodcall:
              args:
                1:
                  value:
                    integer: 1
              argCount: 1
              name: hasSizeLessThan
              label: hasSizeLessThanMethodCall
              type:
                reference:
                  matches: org.assertj.core.api.AbstractIterableAssert<.*>
                checkInheritance: true
          name:
            matches: (as|describedAs)
availableFixes:
- name: Use idiomatic assertion
  actions:
  - changeName:
      name: isEmpty
      target: label:hasSizeLessThanMethodCall
  - modifyArguments:
      remove:
      - 1
      target: label:hasSizeLessThanMethodCall