Home home = new Home(homeFurniture);
// Check home furniture isn't empty
assertTrue("Home furniture is empty", homeFurniture.size() > 0);
// 2. Create a table that displays home furniture with its controller
FurnitureController furnitureController =
new FurnitureController(home, preferences, new SwingViewFactory());
FurnitureTable table = (FurnitureTable)furnitureController.getView();
assertEquals("Home furniture count and row count different", homeFurniture.size(), table.getRowCount());
// Apply a filter on furniture that refuses pieces that are windows
table.setFurnitureFilter(new FurnitureFilter() {
public boolean include(Home home, HomePieceOfFurniture piece) {
return !piece.isDoorOrWindow();
}
});
// Count how many doors and windows are in home
int doorsAndWindowsCount = 0;
HomePieceOfFurniture doorOrWindowPiece = null;
HomePieceOfFurniture otherPiece = null;
for (HomePieceOfFurniture piece : home.getFurniture()) {
if (piece.isDoorOrWindow()) {
doorsAndWindowsCount++;
doorOrWindowPiece = piece;
} else {
otherPiece = piece;
}
}
// Check there's no door or window in table
int homeFurnitureCount = homeFurniture.size();
int tableFilterRowCount = table.getRowCount();
assertEquals("Home furniture count and row count same",
homeFurnitureCount - doorsAndWindowsCount, tableFilterRowCount);
// 3. Add a door or window to home
home.addPieceOfFurniture(new HomePieceOfFurniture(doorOrWindowPiece));
// Check no row were added in table
assertEquals("Wrong furniture count in home", homeFurnitureCount + 1, home.getFurniture().size());
assertEquals("Wrong row count in table", tableFilterRowCount, table.getRowCount());
// 4. Add an other kind of piece to home
home.addPieceOfFurniture(new HomePieceOfFurniture(otherPiece));
// Check one row was added in table
assertEquals("Wrong furniture count in home", homeFurnitureCount + 2, home.getFurniture().size());
assertEquals("Wrong row count in table", tableFilterRowCount + 1, table.getRowCount());
// 5. Test sort and filter internal buffer of the table
furnitureController.sortFurniture(HomePieceOfFurniture.SortableProperty.NAME);
// Check the alphabetical order of table data
assertFurnitureIsSortedByName(table, true);
// Add a door or window and an other kind of piece to home
home.addPieceOfFurniture(new HomePieceOfFurniture(doorOrWindowPiece));
home.addPieceOfFurniture(new HomePieceOfFurniture(otherPiece));