assertEquals("Home doesn't contain 1 piece", 1, pieces.size());
assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
assertFalse("Home still contains first added piece", pieces.contains(piece1));
assertFalse("Home still contains scond added piece", pieces.contains(piece2));
assertGroupActionsEnabled(false, true);
HomeFurnitureGroup group = (HomeFurnitureGroup)pieces.get(0);
// Compare surrounding rectangles
Rectangle2D piecesRectangle = getSurroundingRectangle(piece1);
piecesRectangle.add(getSurroundingRectangle(piece2));
Rectangle2D groupRectangle = getSurroundingRectangle(group);
assertEquals("Surrounding rectangle is incorrect", piecesRectangle, groupRectangle);
// Compare elevation and height
assertEquals("Wrong elevation", Math.min(piece1.getElevation(), piece2.getElevation()), group.getElevation());
assertEquals("Wrong height",
Math.max(piece1.getElevation() + piece1.getHeight(), piece2.getElevation() + piece2.getHeight())
- Math.min(piece1.getElevation(), piece2.getElevation()), group.getHeight());
// 3. Rotate group
float angle = (float)(Math.PI / 2);
group.setAngle(angle);
// Check pieces rotation
assertEquals("Piece angle is wrong", angle, piece1.getAngle());
assertEquals("Piece angle is wrong", angle, piece2.getAngle());
assertEquals("Group angle is wrong", angle, group.getAngle());
// Check surrounding rectangles
Rectangle2D rotatedGroupRectangle = new GeneralPath(groupRectangle).createTransformedShape(
AffineTransform.getRotateInstance(angle, groupRectangle.getCenterX(), groupRectangle.getCenterY())).getBounds2D();
groupRectangle = getSurroundingRectangle(group);
assertEquals("Surrounding rectangle is incorrect", rotatedGroupRectangle, groupRectangle);
piecesRectangle = getSurroundingRectangle(piece1);
piecesRectangle.add(getSurroundingRectangle(piece2));
assertEquals("Surrounding rectangle is incorrect", piecesRectangle.getWidth(), groupRectangle.getWidth());
assertEquals("Surrounding rectangle is incorrect", piecesRectangle.getHeight(), groupRectangle.getHeight());
// 4. Undo / Redo
assertActionsEnabled(true, true, true, false);
runAction(HomePane.ActionType.UNDO);
pieces = this.home.getFurniture();
assertEquals("Home doesn't contain 2 pieces", 2, pieces.size());
assertEquals("Home doesn't contain 2 selected items", 2, this.home.getSelectedItems().size());
assertFalse("Home contains group", pieces.contains(group));
assertGroupActionsEnabled(true, false);
assertActionsEnabled(true, true, true, true);
runAction(HomePane.ActionType.REDO);
pieces = this.home.getFurniture();
assertEquals("Home doesn't contain 1 piece", 1, pieces.size());
assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
assertTrue("Home doesn't contain group", pieces.contains(group));
assertGroupActionsEnabled(false, true);
// 5. Add one more piece to home
catalogPieces = Arrays.asList(new CatalogPieceOfFurniture [] {firstCategory.getFurniture().get(0)});
this.homeController.getFurnitureCatalogController().setSelectedFurniture(catalogPieces);
runAction(HomePane.ActionType.ADD_HOME_FURNITURE);
pieces = this.home.getFurniture();
// Check home contains two pieces with one selected
assertEquals("Home doesn't contain 2 pieces", 2, pieces.size());
assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
assertGroupActionsEnabled(false, false);
// 6. Group it with the other group
HomePieceOfFurniture piece3 = pieces.get(1);
this.home.setSelectedItems(Arrays.asList(new Selectable [] {group, piece3}));
assertEquals("Home doesn't contain 2 selected items", 2, this.home.getSelectedItems().size());
assertGroupActionsEnabled(true, true);
runAction(HomePane.ActionType.GROUP_FURNITURE);
pieces = this.home.getFurniture();
assertEquals("Home doesn't contain 1 piece", 1, pieces.size());
assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
HomeFurnitureGroup group2 = (HomeFurnitureGroup)pieces.get(0);
assertFalse("Home doesn't contain a different group", group == group2);
assertGroupActionsEnabled(false, true);
// 7. Ungroup furniture
runAction(HomePane.ActionType.UNGROUP_FURNITURE);