Skip to content

Add AbstractStringAssert#asInstanceOf(Class<? extends Number>, ...) #2509

Description

@onacit

Summary

Please forgive me If this issue is already fulfilled or not appropriate.

I just faced a situation that I need to assert an actual of String against an expected of int.

String actual = calculate();
int expected = 1;
assertThat(actual).isNotNull().satisfies(v -> {
    assertThat(Integer.parseInt(v)).isEqualsTo(expected);
});
assertThat(actual).isNotNull()
        .asInstanceOf(new InstanceOfAssertFactory<>(String.class, v -> assertThat(Integer.parseInt(v))))
        .isEqualTo(expected);

Example

Do I have an already existing handy idiom or do I have any chance to get following one?

String actual = calculate();
int expected = 1;
assertThat(actual).parsesAsInt().isEqualsTo(expected);
 // <N extends Number, A extends NumberAssert<?, N>> A asInstanceOf(Class<N>, Class<A>)
assertThat(actual)
        .asInstanceOf(Integer.class, AbstractIntegerAssert.class)
        .isEqualTo(expected);
 // AbstractIntegerAssert<?> asInstanceOfIntegerAssert()
assertThat(actual)
        .asInstanceOfIntegerAssert()
        .isEqualTo(expected);

Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions