EndlessGrid implements Grid<T>, Overseer { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; EndlessGrid that = (EndlessGrid) o; if (sizeX != that.sizeX) return false; if (sizeY != that.sizeY) return false; for (int j = 0; j < getSizeY(); j++) { for (int i = 0; i < getSizeX(); i++) { Cell cell = getCell(i, j); Cell otherCell = that.getCell(i, j); if (!otherCell.equals(cell)) { debugOnCellsNotEqual(cell, otherCell); return false; } } } return true; } EndlessGrid(int sizeX, int sizeY, CellFactory<T> cellFactory);  EndlessGrid(Grid<T> other, CellFactory<T> cellFactory); protected  EndlessGrid(Parcel in); @Override void putCell(T cell); @Override void onCellStateChanged(CellStateChange cellStateChange); @Override int getSizeX(); @Override int getSizeY(); @Override T getCell(int x, int y); @Override boolean equals(Object o); @Override int hashCode(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Creator<EndlessGrid> CREATOR; }
@Test public void testEquals() { EndlessGrid other = null; assertThat(grid).isEqualTo(grid); assertThat(grid.equals(other)).isFalse(); assertThat(grid.equals(this)).isFalse(); other = new EndlessGrid<>(1, 6, cellFactory); assertThat(grid).isNotEqualTo(other); other = new EndlessGrid<>(3, 1, cellFactory); assertThat(grid).isNotEqualTo(other); other = new EndlessGrid<>(3, 6, cellFactory); other.getCell(1, 1).setState(Cell.STATE_ALIVE); assertThat(grid).isNotEqualTo(other); grid.getCell(1, 1).setState(Cell.STATE_ALIVE); assertThat(grid).isEqualTo(other); }