Recipe Name:
Use assertThat(Specific)Exception
Description:
Use assertThat(Specific)Exception
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • framework specific
  • quality
Recipe
id: scw:assertj:idiomatic:assertThatSpecificException
version: 10
metadata:
  name: Use assertThat(Specific)Exception
  shortDescription: Use assertThat(Specific)Exception
  level: warning
  language: java
  enabled: true
  tags: AssertJ;framework specific;quality
search:
  methodcall:
    args:
      1:
        value:
          stringified:
            anyOf:
            - is: IllegalArgumentException.class
            - is: IllegalStateException.class
            - is: IOException.class
            - is: NullPointerException.class
    argCount: 1
    name: assertThatExceptionOfType
    type: org.assertj.core.api.Assertions
availableFixes:
- doStaticImports: true
  name: Use idiomatic assertion
  actions:
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              args:
                1:
                  value:
                    stringified: IllegalArgumentException.class
      to: org.assertj.core.api.Assertions.assertThatIllegalArgumentException()
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              args:
                1:
                  value:
                    stringified: IllegalStateException.class
      to: org.assertj.core.api.Assertions.assertThatIllegalStateException()
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              args:
                1:
                  value:
                    stringified: IOException.class
      to: org.assertj.core.api.Assertions.assertThatIOException()
  - rewrite:
      applyIf:
        markedElement:
          is:
            methodcall:
              args:
                1:
                  value:
                    stringified: NullPointerException.class
      to: org.assertj.core.api.Assertions.assertThatNullPointerException()