Recipe Name:
Use contains instead of contains isTrue
Description:
Use contains instead of contains isTrue
Level:
warning
Language:
  • java
Tags:
  • AssertJ
  • framework specific
  • quality
Recipe
id: scw:assertj:idiomatic:string-contains
version: 10
metadata:
  name: Use contains instead of contains isTrue
  shortDescription: Use contains instead of contains isTrue
  level: warning
  language: java
  enabled: true
  tags: AssertJ;framework specific;quality
search:
  methodcall:
    args:
      1:
        value:
          is:
            methodcall:
              name: contains
              type: String
    name: assertThat
    anyOf:
    - followedBy:
        methodcall:
          name: isTrue
          label: isTrueCallDirect
    - followedBy:
        methodcall:
          followedBy:
            methodcall:
              name: isTrue
              label: isTrueCallIndirect
          name:
            matches: as|describedAs
availableFixes:
- doStaticImports: true
  name: Use idiomatic assertion
  actions:
  - rewrite:
      to: org.assertj.core.api.Assertions.assertThat({{{ arguments.0.qualifier }}})
  - changeName:
      name: contains
      target: label:isTrueCallDirect
  - changeName:
      name: contains
      target: label:isTrueCallIndirect
  - modifyArguments:
      insert:
        1: '{{{ qualifier.arguments.0.arguments.0 }}}'
      target: label:isTrueCallDirect
  - modifyArguments:
      insert:
        1: '{{{ qualifier.qualifier.arguments.0.arguments.0 }}}'
      target: label:isTrueCallIndirect