Skip to content

Simplify AssertJ assertions related to Iterable #811

@kthoms

Description

@kthoms

What problem are you trying to solve?

Resolve Sonar issues of type java:S5838
Image

What precondition(s) should be checked before applying this recipe?

AssertJ library is present

Describe the situation before applying the recipe

class A {
    void foo(Iterable bar) {
        assertThat(bar).hasSize(0);
    }
}

Describe the situation after applying the recipe

class A {
    void foo(Iterable bar) {
        assertThat(bar).isEmpty();
    }
}

Have you considered any alternatives or workarounds?

Any additional context

There might be other situations for AbstractIterableAssert or ListAssert that could be changed, too.

The issue can be reproduced by adding to org.openrewrite.java.testing.assertj.AssertJBestPracticesTest.SonarDedicatedAssertions#replacements:

arguments("java.lang.Iterable", "assertThat(x).hasSize(0)", "assertThat(x).isEmpty()"),

Are you interested in contributing this recipe to OpenRewrite?

In general, yes, but too busy ATM.

Metadata

Metadata

Assignees

Labels

assertjbugSomething isn't workingrecipeRecipe request

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions