Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3395

Rule S5841: AssertJ assertions "allMatch" and "doesNotContains" should also test for emptiness

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.5
    • Component/s: Rules

      Description

      Implements S5841.

      We have to make sure to support case like:

      assertThat(list).isNotEmpty();
      assertThat(list.size()).isGreaterThan(1);
      assertThat(list).allMatch(e -> e.contains(“error”));
      
      assertThat(issues).hasSize(2);
      assertThat(issues.stream().map(Issue::getRule)).allMatch("java:S1228"::equals);
      
      assertThat(list).contains("something").doesNotContainSequence("somethingelse");
      
      assertThat("s").doesNotContain("a");
      

      and even maybe when the list is tested after the allMatch.

      In fact, any use of the list in assertion before or after is probably correct.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: