Skip to content

AssertJ: Refactor assertThat(x instanceof Type).isTrue() to assertThat(x).isInstanceOf(Type.class) #1030

Description

@juherr

What problem are you trying to solve?

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

AssertJ available.

Describe the situation before applying the recipe

class A {
    void foo(Object error) {
        assertThat(error instanceof RuntimeException).isTrue();
        assertThat(error instanceof RuntimeException).isFalse();
    }
}

Describe the situation after applying the recipe

class A {
    void foo(Object error) {
        assertThat(error).isInstanceOf(RuntimeException.class);
        assertThat(error).isNotInstanceOf(RuntimeException.class);
    }
}

(Should also handle the parenthesized form assertThat((error instanceof RuntimeException)) and the negated assertThat(!(x instanceof T)).isTrue().)

Any additional context

Are you interested in contributing this recipe?

Can help with samples/testing; happy to review a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions