// Double click inside walls
tester.actionClick(planComponent, 100, 100, InputEvent.BUTTON1_MASK, 2);
// Check a room was created
assertEquals("Wrong room count in home", 1, frame.home.getRooms().size());
// Check room point count and area
Room room = frame.home.getRooms().get(0);
assertEquals("Wrong point count", 5, room.getPoints().length);
assertEquals("Wrong room area", 69273.02f, room.getArea());
// 4. Edit created room
JDialog attributesDialog = showRoomPanel(frame.preferences, frame.homeController, frame, tester);
// Retrieve RoomPanel components
RoomPanel wallPanel = (RoomPanel)TestUtilities.findComponent(
attributesDialog, RoomPanel.class);
JTextField nameTextField =
(JTextField)TestUtilities.getField(wallPanel, "nameTextField");
NullableCheckBox areaVisibleCheckBox =
(NullableCheckBox)TestUtilities.getField(wallPanel, "areaVisibleCheckBox");
NullableCheckBox floorVisibleCheckBox =
(NullableCheckBox)TestUtilities.getField(wallPanel, "floorVisibleCheckBox");
NullableCheckBox ceilingVisibleCheckBox =
(NullableCheckBox)TestUtilities.getField(wallPanel, "ceilingVisibleCheckBox");
// Check name is empty and check boxes are selected
assertTrue("Name not empty", nameTextField.getText().length() == 0);
assertTrue("Area check box isn't checked", areaVisibleCheckBox.getValue());
assertTrue("Floor check box isn't checked", floorVisibleCheckBox.getValue());
assertTrue("Ceiling check box isn't checked", ceilingVisibleCheckBox.getValue());
// Enter a name and unchecked boxes
nameTextField.setText("Test");
tester.click(areaVisibleCheckBox);
tester.click(floorVisibleCheckBox);
tester.click(ceilingVisibleCheckBox);
final JOptionPane attributesOptionPane = (JOptionPane)TestUtilities.findComponent(
attributesDialog, JOptionPane.class);
tester.invokeAndWait(new Runnable() {
public void run() {
// Select Ok option to hide dialog box in Event Dispatch Thread
attributesOptionPane.setValue(JOptionPane.OK_OPTION);
}
});
assertFalse("Dialog still showing", attributesDialog.isShowing());
// Assert room was modified accordingly
assertEquals("Name is incorrect", "Test", room.getName());
assertFalse("Area is visible", room.isAreaVisible());
assertFalse("Floor is visible", room.isFloorVisible());
assertFalse("Ceiling is visible", room.isCeilingVisible());
// 5. Increase font size of room name text
assertNull("Text style exists", room.getNameStyle());
runAction(frame.homeController, HomeView.ActionType.INCREASE_TEXT_SIZE, tester);
// Check text style
assertEquals("Wrong text size", 26.f, room.getNameStyle().getFontSize());
// Decrease font size of room name text
runAction(frame.homeController, HomeView.ActionType.DECREASE_TEXT_SIZE, tester);
runAction(frame.homeController, HomeView.ActionType.DECREASE_TEXT_SIZE, tester);
assertEquals("Wrong text size", 22.f, room.getNameStyle().getFontSize());
// Change style to italic
runAction(frame.homeController, HomeView.ActionType.TOGGLE_ITALIC_STYLE, tester);
assertTrue("Text isn't italic", room.getNameStyle().isItalic());
assertFalse("Text is bold", room.getNameStyle().isBold());
// Change style to bold
runAction(frame.homeController, HomeView.ActionType.TOGGLE_BOLD_STYLE, tester);
assertTrue("Text isn't italic", room.getNameStyle().isItalic());
assertTrue("Text isn't bold", room.getNameStyle().isBold());
// 6. Undo style change
runAction(frame.homeController, HomeView.ActionType.UNDO, tester);
runAction(frame.homeController, HomeView.ActionType.UNDO, tester);
// Check style
assertFalse("Text is italic", room.getNameStyle().isItalic());
assertFalse("Text is bold", room.getNameStyle().isBold());
// Undo text size change
runAction(frame.homeController, HomeView.ActionType.UNDO, tester);
runAction(frame.homeController, HomeView.ActionType.UNDO, tester);
runAction(frame.homeController, HomeView.ActionType.UNDO, tester);
assertEquals("Wrong text size", 24.f, room.getNameStyle().getFontSize());
// Undo room modification
runAction(frame.homeController, HomeView.ActionType.UNDO, tester);
assertNull("Name isn't empty", room.getName());
assertTrue("Area isn't visible", room.isAreaVisible());
assertTrue("Floor isn't visible", room.isFloorVisible());
assertTrue("Ceiling isn't visible", room.isCeilingVisible());
// Undo room creation
runAction(frame.homeController, HomeView.ActionType.UNDO, tester);
assertEquals("Wrong room count in home", 0, frame.home.getRooms().size());
// 7. Redo everything
for (int i = 0; i < 7; i++) {
runAction(frame.homeController, HomeView.ActionType.REDO, tester);
}
// Check room is back
assertEquals("Wrong room count in home", 1, frame.home.getRooms().size());
room = frame.home.getRooms().get(0);
assertEquals("Name is incorrect", "Test", room.getName());
assertFalse("Area is visible", room.isAreaVisible());
assertFalse("Floor is visible", room.isFloorVisible());
assertFalse("Ceiling is visible", room.isCeilingVisible());
assertEquals("Wrong text size", 22.f, room.getNameStyle().getFontSize());
assertTrue("Text isn't italic", room.getNameStyle().isItalic());
assertTrue("Text isn't bold", room.getNameStyle().isBold());
}