Witam, jak na razie się uczę i utknąłem na jednym problemie
Posiadam klasę Ship, która po wywołaniu getPoints zwraca mi listę obiektów Point
Chciałbym ją przetestować, czy prawidłowe Pointy są zwaracane
W klasie testowej mam
List<Point> points = Arrays.asList(new PointImpl(3, 6), new PointImpl(4, 6), new PointImpl(5, 6));
Próbując ją porównać przez ten sposób
assertThat(ship.getPoints(), containsInAnyOrder(points));
wyrzuca mi
java.lang.AssertionError:
Expected: iterable over [<[battleship.PointImpl@128d1e9, battleship.PointImpl@98a3ee, battleship.PointImpl@8c58a6]>] in any order
but: Not matched: <battleship.PointImpl@e261f0>
Pozostaje mi tylko testowanie przez pętle, w której wszystkie testy przechodzą. Czy jest to dobre rozwiązanie?
for(Point p : ship.getPoints()) {
assertEquals(p.getRow(), points.get(i).getRow());
assertEquals(p.getColumn(), points.get(i).getColumn());
i++;
}