Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-5853

Consecutive AssertJ "assertThat" statements should be chained

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Join these multiple assertions subject to one assertion chain
    • Highlighting:
      • Primary location: first assertThat
      • Secondaries: all subsequent assertThat
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Test Sources

      Description

      AssertJ assertions methods targeting the same object can be chained instead of using multiple assertThat. It avoids duplication and increases the clarity of the code.

      This rule raises an issue when multiples assertThat target the same tested value.

      Noncompliant Code Example

      assertThat(someList).hasSize(3);
      assertThat(someList).contains("something");
      

      Compliant Solution

      assertThat(someList)
        .hasSize(3)
        .contains("something");
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              quentin.jaquier Quentin Jaquier
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: