1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SERVICE_EXCEPTION;
import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SUCCESS;
import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_VALIDATION_ERROR;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException;
import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.VehicleService;
import at.ac.tuwien.sepm.assignment.groupphase.util.Helper;
import at.ac.tuwien.sepm.assignment.groupphase.util.HighDpiAwareApplicationTest;
import javafx.scene.control.DialogPane;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.testfx.api.FxToolkit;
import org.testfx.robot.Motion;
public class CreateNewVehicleControllerTest extends HighDpiAwareApplicationTest {
private VehicleService vehicleService;
@Before
public void setup() throws Exception {
FxToolkit.registerPrimaryStage();
FxToolkit.setupApplication(GuiTestApplication.class, "createCar.fxml");
vehicleService = GuiTestApplication.context.getBean(VehicleService.class);
}
@After
public void cleanup() throws Exception {
FxToolkit.cleanupStages();
}
@Test
public void testClickAddValidVehicle() throws ServiceException, InvalidVehicleException {
when(vehicleService.add(any())).thenReturn(1L);
clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
Stage alertDialog = Helper.getTopModalStage(robotContext());
Assert.assertNotNull(alertDialog);
DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
Assert.assertEquals(ALERT_TITLE_SUCCESS, dialogPane.getHeaderText());
}
@Test
public void testClickInvalidVehicleEx() throws ServiceException, InvalidVehicleException {
when(vehicleService.add(any())).thenThrow(InvalidVehicleException.class);
clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
Stage alertDialog = Helper.getTopModalStage(robotContext());
Assert.assertNotNull(alertDialog);
DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
Assert.assertEquals(ALERT_TITLE_VALIDATION_ERROR, dialogPane.getHeaderText());
}
@Test
public void testClickInvalidServiceEx() throws ServiceException, InvalidVehicleException {
when(vehicleService.add(any())).thenThrow(ServiceException.class);
clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
Stage alertDialog = Helper.getTopModalStage(robotContext());
Assert.assertNotNull(alertDialog);
DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
Assert.assertEquals(ALERT_TITLE_SERVICE_EXCEPTION, dialogPane.getHeaderText());
}
}
|