Skip to content

Better error message instead of "actual is not empty while group of values to look for is" #3230

@hohwille

Description

@hohwille

Feature summary

I want to receive detailed error messages so I can better understand what went wrong in my test.
That is why I chose AssertJ (thank you so much for creating this great lib) but in some edge-cases it does not satisfy this requirement.

Example

This assertion:

    assertThat(new String[] {"foo", "bar"}).as("detailed extra hint I want to see if this fails").containsExactly(new String[0]);

is giving me:

java.lang.AssertionError: actual is not empty while group of values to look for is.
	at org.assertj.core.internal.Arrays.failIfEmptySinceActualIsNotEmpty(Arrays.java:774)
	at org.assertj.core.internal.Arrays.commonChecks(Arrays.java:498)
	at org.assertj.core.internal.Arrays.assertContainsExactly(Arrays.java:277)
	at org.assertj.core.internal.ObjectArrays.assertContainsExactly(ObjectArrays.java:298)
	at org.assertj.core.api.AbstractObjectArrayAssert.containsExactlyForProxy(AbstractObjectArrayAssert.java:619)
	at org.assertj.core.api.AbstractObjectArrayAssert.containsExactly(AbstractObjectArrayAssert.java:612)

My expected result would be:

org.opentest4j.AssertionFailedError: [detailed extra hint I want to see if this fails] 
Expecting actual:
  ["foor", "bar"]
to contain exactly (and in same order):
  []
but others were not expected:
  ["foo", "bar"]
...

(This is just an example aligned to what I get if the expected array/collection is not empty. Feel free to define the error message as prefer as long as you include the message given via as and the actual values.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions