You mention that your test case uses assertSame
. This looks for reference equality, and requires that a == b
.
Your code creates a copy. A copy will never have reference equality to the original. In some classes that override the Object
method Equals
it may be true that assertEquals
will pass. In the case of an array, try using assertArrayEquals
.
For example this test should pass:
@Test
public void assertArrayEqualsTest() throws Exception {
assertArrayEquals(new int[]{1, 2, 3}, new int[]{1, 2, 3});
}
But this test will fail:
@Test
public void assertSameTest() throws Exception {
assertSame(new int[]{1, 2, 3}, new int[]{1, 2, 3});
}
You should be clear on why this is.