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

Improve rule S5838 to handle maps and longs

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.10
    • Component/s: Rules

      Description

      Current implementation doesn't handle some cases, when using maps or longs. Here is the suggestion of possible improvements.

         Map<Object, Object> x = new HashMap<>();
          assertThat(x).containsOnlyKeys("foo"); // TN
          assertThat(x.keySet()).containsOnly("foo"); // FN: dev should use containsOnlyKeys here
          assertThat(x).containsValues("foo"); // TN
          assertThat(x.values()).contains("foo"); // FN: dev should use containsValues here
          // There is a contains and a containsOnly for both values and keys provided by AssertJ
      
          long i = 5;
          assertThat(i).isEqualTo(0); // TP: isZero() is suggested instead
          assertThat(i).isEqualTo(0L); // FN: dev should use isZero() here
          assertThat(i).isGreaterThan(0L); // FN: dev should use isPositive() here
          // The same is most certainly true for isLessThan(OrEqualTo)(...), isGreaterThanOrEqualTo(...)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                margarita.nedzelska Margarita Nedzelska
              • Votes:
                1 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: