I have followings Unit Test with JUnit 4.12 and AssertJ 3.11.0 and having interesting results. helloTest
is green
but worldTest
is red
.
@Test
public void helloTest() {
Object[] array = new Object[2];
String[] firstElement = new String[]{"Hello"};
String[] secondElement = new String[]{"World"};
array[0] = firstElement;
array[1] = secondElement;
assertThat(array).containsExactlyInAnyOrder(firstElement, secondElement);
}
@Test
public void worldTest() {
Object[] array = new Object[1];
String[] element = new String[]{"Hello"};
array[0] = element;
assertThat(array).containsExactlyInAnyOrder(element);
}
And the result from AssertJ is
java.lang.AssertionError:
Expecting:
<[["Hello"]]>
to contain exactly in any order:
<["Hello"]>
elements not found:
<["Hello"]>
and elements not expected:
<[["Hello"]]>
But why?