Recipe Name:
Use AssertJ's isEmpty() instead of empty/emptyCollection/emptyIterable/emptyString
Description:
Can be replaced with AssertJ style assertions
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • Hamcrest
Recipe
id: scw:assertj:hamcrest-empty
version: 10
metadata:
  name: Use AssertJ's isEmpty() instead of empty/emptyCollection/emptyIterable/emptyString
  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:
                anyOf:
                - name: empty
                  type: org.hamcrest.Matchers
                - name: emptyCollectionOf
                  type: org.hamcrest.Matchers
                - name: empty
                  type: org.hamcrest.collection.IsEmptyCollection
                - name: emptyCollectionOf
                  type: org.hamcrest.collection.IsEmptyCollection
                - name: emptyIterable
                  type: org.hamcrest.Matchers
                - name: emptyIterableOf
                  type: org.hamcrest.Matchers
                - name: emptyIterable
                  type: org.hamcrest.collection.IsEmptyIterable
                - name: emptyIterableOf
                  type: org.hamcrest.collection.IsEmptyIterable
                - name: emptyArray
                  type: org.hamcrest.Matchers
                - name: anEmptyMap
                  type: org.hamcrest.Matchers
                - name: anEmptyMap
                  type: org.hamcrest.collection.IsMapWithSize
                - name: emptyString
                  type: org.hamcrest.Matchers
                - name: emptyString
                  type: org.hamcrest.text.IsEmptyString
      argCount: 2
    - args:
        1:
          type: String
        3:
          value:
            is:
              methodcall:
                anyOf:
                - name: empty
                  type: org.hamcrest.Matchers
                - name: emptyCollectionOf
                  type: org.hamcrest.Matchers
                - name: empty
                  type: org.hamcrest.collection.IsEmptyCollection
                - name: emptyCollectionOf
                  type: org.hamcrest.collection.IsEmptyCollection
                - name: emptyIterable
                  type: org.hamcrest.Matchers
                - name: emptyIterableOf
                  type: org.hamcrest.Matchers
                - name: emptyIterable
                  type: org.hamcrest.collection.IsEmptyIterable
                - name: emptyIterableOf
                  type: org.hamcrest.collection.IsEmptyIterable
                - name: emptyArray
                  type: org.hamcrest.Matchers
                - name: anEmptyMap
                  type: org.hamcrest.Matchers
                - name: anEmptyMap
                  type: org.hamcrest.collection.IsMapWithSize
                - name: emptyString
                  type: org.hamcrest.Matchers
                - name: emptyString
                  type: org.hamcrest.text.IsEmptyString
      argCount: 3
    type: org.hamcrest.MatcherAssert
availableFixes:
- doStaticImports: true
  name: Change to assertThat(actual).isEmpty()
  availableIf:
    markedElement:
      is:
        methodcall:
          argCount: 2
  actions:
  - rewrite:
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.0 }}}).isEmpty()
- doStaticImports: true
  name: Change to assertThat(actual).as(reason).isEmpty()
  availableIf:
    markedElement:
      is:
        methodcall:
          argCount: 3
  actions:
  - rewrite:
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.1 }}}).as({{{ arguments.0 }}}).isEmpty()