Issue
I'm new here, so sorry in advance for stupid question.
I have some problems with my JUnit test: For some reasons it shows me mistake in index.
I attached the link to my repository with test and screens.
Thank you! ERROR:
org.opentest4j.AssertionFailedError: array contents differ at index [0],
expected: <Poster(id=3, pictureId=33, filmName=Space, filmGenre=Lamusic)>
but was: <Poster(id=2, pictureId=22, filmName=Moon, filmGenre=Lamedy)>
Click here to see Test in GitHub
Solution
In your second test getLastPosters2()
(which is not working) you assert a different ordering, than your first test getLastPosters()
.
Poster[] expected = new Poster[]{thirdFilm,secondFilm};
This is the reverse order, which you are adding to your PosterManager
.
Change the order to the following and the test is working:
Poster[] expected = new Poster[]{secondFilm,thirdFilm};
At your first test getLastPosters()
you assert in the same ordering, as you are adding them to the PosterManager
.
However, either your second test is asserting the wrong order and fails, or your implementation is wrong, and your first test is "false-positive".
Answered By - csalmhof