0

This is the public Test:

public void testFilmHinzufuegen() {
        Film f2 = new Film("Advent im Puppenhaus", 2019, 12, Genre.ACTION, d);
        b.filmHinzufuegen(f2);
        b.filmHinzufuegen(f2);
        LinkedList<Film> fl = new LinkedList<Film>();
        fl.add(f);
        fl.add(f2);
        b.filmHinzufuegen(null);
        assertEquals(fl, b.getFilme());

My Code:

public void filmHinzufuegen(Film film) {
        try {
            if (null != film && !this.filme.contains(film)) {
                this.getFilme().add(film);
            }
        } catch (Exception e) {

        }

The Error, which I get:

testFilmHinzufuegen(PublicTests) java.lang.AssertionError: expected:<[Film@47d384ee, Film@2d6a9952]> but was:<[Film@2d6a9952]>

My question was, how can I solve it?

  • 1
    Your code prevents duplicated films, yet your test adds the same film twice and expects to have two films at the end. Change either one or the other. – Aaron Dec 22 '20 at 18:46
  • It's probably the test that is wrong, shouldn't the first of the two consecutive `b.filmHinzufuegen(f2);` lines be `b.filmHinzufuegen(f);` instead to match the expected result? – Aaron Dec 22 '20 at 18:48
  • You add two (presumable different) films (`f` and `f2`) to `fl`, but twice the same film (`f2`) to `b` (also presumable without adding `f` to `b`). How can a list of two different films ever be equal to a list of only one film? – Thomas Kläger Dec 22 '20 at 18:56

0 Answers0