Skip to content

Better error message for type mismatch in test-utils' argument assertions #876

Description

@ash211

What happened?

I recently got this error message:

java.lang.AssertionError: Expected unsafe args to be {extra=[extra], missing=[missing_secret, missing_secret2]}, but found {extra=[extra], missing=[missing_secret, missing_secret_2]}

which is confusing because it looks like expected and actual are the same. Actually, their types are different -- one is a String "[extra]" and one is a Set ImmutableSet.of("extra").

In the case where two objects are different, but their toStrings() are equal, we should additionally show in the error message the types of the two objects.

This would happen here:

Minimal repo:

        assertThatServiceExceptionThrownBy(() -> {
                    throw new ServiceException(ErrorType.INTERNAL, UnsafeArg.of("list", ImmutableList.of("a")));
                })
                .hasArgs(UnsafeArg.of("list", "[a]"));

currently gives message:

java.lang.AssertionError: Expected unsafe args to be {list=[a]}, but found {list=[a]}

What did you want to happen?

Should return a message like:

java.lang.AssertionError: Expected unsafe args to be {list=[a]} with value type String, but found {list=[a]} with value type ImmutableList<String>

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