2

I have the following class which returns a list of strings.

public static String[] parseLinks(String text) {
    String[] result = new String[] {"",""};
            return result;
    }

But when I do an assertEquals on the result,

    assertEquals(new String[]{"",""}, parseLinks(""));

I get the following error:

Exception in thread "main" junit.framework.AssertionFailedError: expected: <[Ljava.lang.String;@2352544e> but was:<[Ljava.lang.String;@721cdeff>
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.Assert.failNotEquals(Assert.java:329)
at junit.framework.Assert.assertEquals(Assert.java:78)
at junit.framework.Assert.assertEquals(Assert.java:86)
at junit.framework.TestCase.assertEquals(TestCase.java:253)

How do I go about fixing this? Please let me know if there is any other additional information that I have to provide.

4

1 回答 1

8

You're comparing two different Array objects. You can use assertArrayEquals to compare arrays instead.

于 2013-09-27T01:28:22.087 回答