1

This is the error trace I get:

java.lang.AssertionError: expected: java.lang.String<[{Song: title=Always artist=Blink 182}]> but was: java.util.ArrayList<[{Song: title=Always artist=Blink 182}]>

when I try and run this piece of code in the test case

assertEquals("[{Song: title=Always artist=Blink 182}]", p.getSongList());

p.getSongList is a method that returns and ArrayList<Song>. I've only added the one song so far but I am confused about how to change the expected output to java.util.ArrayList instead of java.lang.String. Any help would be greatly appreciated.

1 Answer 1

4

You are comparing an ArrayList instance with the string representation of the desired output (i.e., the String you'd get if you run toString() on the output). Instead, you should just construct the actual output you're expecting.

Your question doesn't supply the code for your Song class, so I'm guessing it's just a POJO:

Song expectedSong = new Song();
expectedSong.setTitle("Always");
expectedSong.setArtist("Blink 182");
ArrayList<Song> expectedList = new ArrayList<>(1);
expectedList.add(song);
assertEquals(expectedList, p.getSongList());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.