Skip to content

AssertJ: Refactor assertThat(list.size())isEqualsTo() -> hasSize() #812

@kthoms

Description

@kthoms

What problem are you trying to solve?

Resolve Sonar issues of type "Chained AssertJ assertions should be simplified to the corresponding dedicated assertion java:S5838"

Image

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

AssertJ must be present

Describe the situation before applying the recipe

class A {
    void foo(List bar) {
        assertThat(bar.size()).isEqualTo(5);
    }
    void foo2(List bar) {
        assertThat(bar.size()).isEqualTo(0);
    }
}

Describe the situation after applying the recipe

class A {
    void foo(List bar) {
        assertThat(bar).hasSize(5);
    }
    void foo2(List bar) {
        assertThat(bar).isEmpty();
    }
}

Have you considered any alternatives or workarounds?

IntelliJ IDEA is able to refactor these occurrences.

Any additional context

Are you interested in contributing this recipe to OpenRewrite?

Not ATM.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions