I am getting the following error even if the expected and actual output is exactly similar.
org.opentest4j.AssertionFailedError: expected: java.util.ArrayList@2bbf180e<[[1, 2, 3], [4, 5, 6]]> but was: java.util.ArrayList@163e4e87<[[1, 2, 3], [4, 5, 6]]>
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
at org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1141)
at parseCsvTest$ExampleTests.shouldHandleSimpleInputs(parseCsvTest.java:17)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
Test cases were written by someone else as I am doing an online assessment on a website so I am not sure how the tests are written.
Here is my code.
public class Challenge {
public static ArrayList<ArrayList<String>> parseCsv(
String csv,
String separator,
String quote
) {
String[] splitted = csv.split("\n");
ArrayList<ArrayList<String>> result = new ArrayList<>();
for (int i = 0; i< splitted.length; i++) {
String[] st = splitted[i].split(separator);
String string = new String();
for (int j = 0; j < st.length; j++) {
string += st[j];
if (j != st.length - 1) {
string += ", ";
}
}
ArrayList<String> temp = new ArrayList<>();
temp.add(string);
result.add(temp);
}
return result;
}
}