* Tests zoom and alignment tools.
*/
public void testZoomAndAligment() {
// Add the first two pieces of catalog first category to home
FurnitureCategory firstCategory = this.preferences.getFurnitureCatalog().getCategories().get(0);
HomePieceOfFurniture firstPiece = new HomePieceOfFurniture(firstCategory.getFurniture().get(0));
this.home.addPieceOfFurniture(firstPiece);
HomePieceOfFurniture secondPiece = new HomePieceOfFurniture(firstCategory.getFurniture().get(1));
secondPiece.setAngle(15);
this.home.addPieceOfFurniture(secondPiece);
// Add a wall to home
this.home.addWall(new Wall(0, 0, 100, 0, 7));
PlanController planController = this.homeController.getPlanController();
float scale = planController.getScale();
// 1. Zoom in
runAction(HomePane.ActionType.ZOOM_IN);
// Check scale changed
assertEquals("Scale is incorrect", scale * 1.5f, planController.getScale());
// 2. Zoom out
runAction(HomePane.ActionType.ZOOM_OUT);
// Check scale is back to its previous value
assertEquals("Scale is incorrect", scale, planController.getScale());
// 3. Select all while table has focus
this.homeController.focusedViewChanged(this.furnitureTable);
runAction(HomePane.ActionType.SELECT_ALL);
// Check selection contains the two pieces
assertEquals("Selection doesn't contain home furniture",
this.home.getFurniture(), this.home.getSelectedItems());
// 4. Select all while plan has focus
this.homeController.focusedViewChanged(planController.getView());
runAction(HomePane.ActionType.SELECT_ALL);
// Check selection contains the two pieces, the wall and the compass
assertEquals("Selection doesn't contain home objects",
4, this.home.getSelectedItems().size());
// 5. Select the first two pieces
this.home.setSelectedItems(Arrays.asList(new Selectable [] {firstPiece, secondPiece}));
float secondPieceX = secondPiece.getX();
float secondPieceY = secondPiece.getY();
// Align on bottom
runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_BOTTOM);
// Check bottom of second piece equals bottom of first piece
TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on bottom of first piece",
getMaxY(firstPiece), getMaxY(secondPiece), 10E-4f);
// 6. Align on top
runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_TOP);
// Check bottom of second piece equals bottom of first piece
TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on top of first piece",
getMinY(firstPiece), getMinY(secondPiece), 10E-4f);
// 7. Align on left
runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_LEFT);
// Check bottom of second piece equals bottom of first piece
TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on left of first piece",
getMinX(firstPiece), getMinX(secondPiece), 10E-4f);
// 8. Align on right
runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_RIGHT);
// Check bottom of second piece equals bottom of first piece
TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on right of first piece",
getMaxX(firstPiece), getMaxX(secondPiece), 10E-4f);
float alignedPieceX = secondPiece.getX();
float alignedPieceY = secondPiece.getY();
// 9. Undo alignments
runAction(HomePane.ActionType.UNDO);
runAction(HomePane.ActionType.UNDO);
runAction(HomePane.ActionType.UNDO);
runAction(HomePane.ActionType.UNDO);
// Check second piece is back to its place
TestUtilities.assertEqualsWithinEpsilon("Second piece abcissa is incorrect",
secondPieceX, secondPiece.getX(), 10E-4f);
TestUtilities.assertEqualsWithinEpsilon("Second piece ordinate is incorrect",
secondPieceY, secondPiece.getY(), 10E-4f);
// 10. Redo alignments
runAction(HomePane.ActionType.REDO);
runAction(HomePane.ActionType.REDO);
runAction(HomePane.ActionType.REDO);
runAction(HomePane.ActionType.REDO);
// Check second piece is back to its place
TestUtilities.assertEqualsWithinEpsilon("Second piece abcissa is incorrect",
alignedPieceX, secondPiece.getX(), 10E-4f);
TestUtilities.assertEqualsWithinEpsilon("Second piece ordinate is incorrect",
alignedPieceY, secondPiece.getY(), 10E-4f);
}