I am trying to create a test that asserts that two ArrayLists are equal. When running the test, I am getting an error that there is one difference between the expected and actual: there is a whitespace at the end of the arraylist.
The problem isn't caused by anything inside the arraylist, the problem is after the close of the arraylist. As far as I know, there is no trim function for this in java or a junit test which ignores whitespace.
ArrayList<Quote> expected = new ArrayList<>();
Quote q1 = new Quote("Test Test", "This is a quote.");
Quote q2 = new Quote("Author Two", "Quote 2.");
Quote q3 = new Quote("Unknown", "This quote does not have an author.");
Quote q4 = new Quote("Author Three-three", "Quote 3.");
expected.add(q1); expected.add(q2); expected.add(q3); expected.add(q4);
What this gives me is: java.util.ArrayList<[This is a quote. - Test Test, Quote 2. - Author Two, This quote does not have an author. - Unknown, Quote 3. - Author Three-three]>_
(I put a underscore where the whitespace is)
What I expect is: java.util.ArrayList<[This is a quote. - Test Test, Quote 2. - Author Two, This quote does not have an author. - Unknown, Quote 3. - Author Three-three]>
This does not include a whitespace.
I don't know why I am getting the whitespace nor do I know how to get rid of it. Any help would be appreciated.
For more context, the entire tester file
public class ImportQuotesTest {
BufferedReader reader;
@Before
public void setUp() throws Exception {
File file = new File("C:\\Users\\homba\\Documents\\QuotesProject\\src\\ImportQuotesTest.txt");
reader = new BufferedReader(new FileReader(file));
}
@Test
public void fillList() throws IOException {
ArrayList<Quote> actual = ImportQuotes.fillList(reader);
ArrayList<Quote> expected = new ArrayList<>();
Quote q1 = new Quote("Test Test", "This is a quote.");
Quote q2 = new Quote("Author Two", "Quote 2.");
Quote q3 = new Quote("Unknown", "This quote does not have an author.");
Quote q4 = new Quote("Author Three-three", "Quote 3.");
expected.add(q1); expected.add(q2); expected.add(q3); expected.add(q4);
Assert.assertEquals(expected,actual);
}
}```