Skip to content

AssertJ: Refactor assertThat with < or > in the expression to assertThat(actual).isGreaterThan(expected) or assertThat(actual).isLessThan(expected) #814

@puskarpeter

Description

@puskarpeter

What problem are you trying to solve?

Using the AssertJ best practices Sonar complains about the following:

Image

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

AssertJ available

Describe the situation before applying the recipe

class A {
    void foo(Long bar, Long foo) {
        assertThat(bar > 0).isTrue();
        assertThat(foo < 0).isTrue();
    }
}

Describe the situation after applying the recipe

class A {
    void foo(Long bar, Long foo) {
        assertThat(bar).isGreaterThan(0);
        assertThat(foo).isLessThan(0);
    }
}

Have you considered any alternatives or workarounds?

IDEA does not have quickfix for this, requires manual intervention.

Any additional context

This was a result after transforming this expression from Junit5

class A {
    void foo(Long bar, Long foo) {
        assertTrue(bar > 0);
        assertTrue(foo < 0);
    }
}

Are you interested in contributing this recipe to OpenRewrite?

Unfortunately I do not have the capacity for it right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrecipeRecipe request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions