// 10. Check the matching new catalog piece of furniture was created
List<CatalogPieceOfFurniture> selectedCatalogFurniture =
controller.getFurnitureCatalogController().getSelectedFurniture();
assertEquals("Wrong selected furniture count in catalog", 0, selectedCatalogFurniture.size());
assertEquals("Incorrect count of created catalog piece", 1, addedCatalogFurniture.size());
CatalogPieceOfFurniture catalogPiece = addedCatalogFurniture.get(0);
assertEquals("Wrong catalog piece name", pieceTestName, catalogPiece.getName());
assertEquals("Wrong catalog piece category name", categoryTestName, catalogPiece.getCategory().getName());
assertTrue("Catalog doesn't contain new piece",
preferences.getFurnitureCatalog().getCategories().contains(catalogPiece.getCategory()));
TestUtilities.assertEqualsWithinEpsilon("Incorrect width", newWidth, catalogPiece.getWidth(), 1E-3f);
TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", newDepth, catalogPiece.getDepth(), 1E-3f);
TestUtilities.assertEqualsWithinEpsilon("Incorrect height", newHeight, catalogPiece.getHeight(), 1E-3f);
TestUtilities.assertEqualsWithinEpsilon("Incorrect elevation", 10, catalogPiece.getElevation(), 1E-3f);
assertFalse("Catalog piece is movable", catalogPiece.isMovable());
assertTrue("Catalog piece isn't a door or window", catalogPiece.isDoorOrWindow());
assertEquals("Wrong catalog piece color", null, catalogPiece.getColor());
assertTrue("Catalog piece isn't modifiable", catalogPiece.isModifiable());
// Check a new home piece of furniture was created and it's the selected piece in home
List<Selectable> homeSelectedItems = home.getSelectedItems();
assertEquals("Wrong selected furniture count in home", 1, homeSelectedItems.size());
HomePieceOfFurniture homePiece = (HomePieceOfFurniture)homeSelectedItems.get(0);
assertEquals("Wrong home piece name", pieceTestName, homePiece.getName());
// 11. Transfer focus to tree
JComponent catalogView = (JComponent)controller.getFurnitureCatalogController().getView();
tester.focus(catalogView);
// Check plan view has focus
assertTrue("Catalog tree doesn't have the focus", catalogView.isFocusOwner());
// Select the piece added to catalog
controller.getFurnitureCatalogController().setSelectedFurniture(addedCatalogFurniture);
// Delete new catalog piece of furniture
final Action deleteAction = homeView.getActionMap().get(HomePane.ActionType.DELETE);
assertTrue("Delete action isn't enable", deleteAction.isEnabled());
tester.invokeLater(new Runnable() {
public void run() {
deleteAction.actionPerformed(null);
}
});
// Wait for confirm dialog to be shown
tester.waitForFrameShowing(new AWTHierarchy(), preferences.getLocalizedString(
HomePane.class, "confirmDeleteCatalogSelection.title"));
// Find displayed dialog box
JDialog confirmDeleteCatalogSelectionDialog = (JDialog)new BasicFinder().find(frame,
new ClassMatcher (JDialog.class, true));
// Click on Ok in dialog box
final JOptionPane optionPane = (JOptionPane)TestUtilities.findComponent(
confirmDeleteCatalogSelectionDialog, JOptionPane.class);
tester.invokeAndWait(new Runnable() {
public void run() {
// Select delete option to hide dialog box in Event Dispatch Thread
optionPane.setValue(preferences.getLocalizedString(
HomePane.class, "confirmDeleteCatalogSelection.delete"));
}
});
// Check selection is empty
selectedCatalogFurniture = controller.getFurnitureCatalogController().getSelectedFurniture();
assertTrue("Catalog selected furniture isn't empty", selectedCatalogFurniture.isEmpty());
// Check catalog doesn't contain the new piece
assertFalse("Piece is still in catalog",
preferences.getFurnitureCatalog().getCategories().contains(catalogPiece.getCategory()));
// Check home piece of furniture is still in home and selected
assertTrue("Home piece isn't in home", home.getFurniture().contains(homePiece));
assertTrue("Home piece isn't selected", home.getSelectedItems().contains(homePiece));
// 12. Undo furniture creation in home