diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b8c202c..d355985 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,4 +1,5 @@
before_script:
+ - cp tracker.json /root/
- cd vendmachtrack/
- mvn clean install -DskipTests
@@ -28,6 +29,7 @@ checkstyle:
when: always
paths:
- $CI_PROJECT_DIR/vendmachtrack/test-results/checkstyle/*.xml
+ expire_in: 1 week
needs:
- build
@@ -42,6 +44,7 @@ spotbugs:
when: always
paths:
- $CI_PROJECT_DIR/vendmachtrack/test-results/spotbugs/**/spotbugs.xml
+ expire_in: 1 week
needs:
- build
@@ -56,6 +59,7 @@ test:
when: always
reports:
junit: $CI_PROJECT_DIR/vendmachtrack/test-results/junit/**/*xml
+ expire_in: 1 week
needs:
- build
@@ -72,7 +76,7 @@ verify:
when: always
paths:
- $CI_PROJECT_DIR/vendmachtrack/test-results/jacoco/
- expire_in: 1 hour
+ expire_in: 1 week
needs:
- build
- checkstyle
diff --git a/vendmachtrack/integrationtests/pom.xml b/vendmachtrack/integrationtests/pom.xml
new file mode 100644
index 0000000..ca5720e
--- /dev/null
+++ b/vendmachtrack/integrationtests/pom.xml
@@ -0,0 +1,201 @@
+
+
+ *
+ * Before the Tests are started the Spring Boot application is started. + * This ensures that the UI module uses RemoteAccess to communicate with the + * Spring Boot Rest API. + * And that the application works properly while the server is running. + * + *
+ *
+ * The test class simulates a user scenario by interacting with the UI and + * verifying the expected outcomes. + * this is done using TestFX, a testing framework for JavaFX applications. + *
+ *
+ * Note: Test method order is controlled using `@Order` annotations to ensure + * that the tests are run in + * a specific sequence, as some tests depend on the outcome of previous tests. + */ + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class IntegrationUITestIT extends ApplicationTest { + + /** + * Initializes and starts the JavaFX application. + */ + @Override + public void start(Stage stage) throws Exception { + + new vendmachtrack.ui.App().start(stage); + } + + /** + * Centers the current JavaFX stage (window) on the screen. + * This ensures that TestFx works properly + */ + private void centerCurrentStage() { + Stage currentStage = (Stage) lookup(".root").queryParent().getScene().getWindow(); + + double screenWidth = javafx.stage.Screen.getPrimary().getBounds().getWidth(); + double screenHeight = javafx.stage.Screen.getPrimary().getBounds().getHeight(); + double windowWidth = currentStage.getWidth(); + double windowHeight = currentStage.getHeight(); + + currentStage.setX((screenWidth - windowWidth) / 2); + currentStage.setY((screenHeight - windowHeight) / 2); + } + + /** + * This JUnit test method represents an integration test for our vendmachtrack + * APplication. It simulates + * a user's interaction with different controllers and scenes in the + * application. The test is divided into + * several steps. + * + *
+ *
+ * Step 1: ServerController: + *
+ *
+ *
+ * Step 2: VendAppController + * + *
+ *
+ * Step 3: RefillController + *
+ *
+ * Step 4: UserAppController + *
+ * + * + * Step 5: passwordHandlerController: + *
+ *
+ * @throws InterruptedException if any thread-related issues occur during test
+ * execution.
+ */
+ @Test
+ @Order(1)
+ public void integrationTestFlow() throws InterruptedException {
+
+ // Redirect the standard output stream to capture console output.
+ ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ PrintStream originalOut = System.out;
+ System.setOut(new PrintStream(outContent));
+
+ // STEP 1: ServerController: Write the server url and the tracker file name
+ clickOn("#serverUrlField").write("http://localhost:8080");
+ clickOn("#trackerFileNameField").write("tracker.json");
+
+ // GO to VendAppController scene
+ clickOn("Submit");
+
+ // Restore the original standard output stream.
+ System.setOut(originalOut);
+
+ // Assert that the captured console output indicates the use of remote access
+ // due to the healthy server connection.
+ assertTrue(outContent.toString().contains("Using remote access"),
+ "Expected remote access but got local access");
+
+ verifyThat("#addButton", NodeMatchers.isVisible());
+
+ centerCurrentStage(); // Center the stage on the screen
+
+ // STEP 2: VendAppController: Add a Vending Machine with Id: 1001 and location:
+ // Beijing
+ clickOn("#idTextFieldAdd").write("1001");
+ clickOn("#locationTextField").write("Beijing");
+ clickOn("#addButton");
+ clickOn("#menuBar");
+
+ // Assert that the vending machine was added to the choice box
+ @SuppressWarnings("unchecked") // Suppressing unchecked cast warning because we are certain that the queried
+ // object is of type ChoiceBox
+ *
+ * The test is divided into several steps.
+ *
+ *
+ *
+ * The class is annotated with Spring Boot annotations to configure the test environment:
+ *
+ * The class includes instance variables for the server port and a TestRestTemplate for making HTTP requests to the application.
+ *
+ * This test verifies that a new vending machine can be successfully added by making a POST request
+ *
+ *
+ * Test Steps:
+ *
+ *
+ * This test checks if we can successfully find out where a vending machine is by making a GET request
+ *
+ *
+ * Test Steps:
+ *
+ *
+ * This test checks if we can successfully put an item into a vending machine and verify that it has the correct quantity using a PUT request
+ *
+ *
+ * Test Steps:
+ *
+ *
+ * This test checks if we can successfully get the quantity of a specific item ("Cola")
+ *
+ *
+ * Test Steps:
+ *
+ *
+ * This test checks if we can successfully take a specific quantity of an item (e.g., "Cola") from a vending machine and verify the remaining quantity.
+ *
+ *
+ * Test Steps:
+ *
+ *
+ * This test checks if we can successfully confirm that a specific quantity of an item (e.g., "Cola") has been removed from a vending machine and that the remaining quantity matches the expected value.
+ *
+ *
+ * Test Steps:
+ *
+ *
+ * This test checks if we can successfully remove a vending machine by making a DELETE request.
+ *
+ *
+ * Test Steps:
+ *
+ *
+ * This test checks if we can successfully confirm that a vending machine has been removed by making a GET request to the specified endpoint and verifying that it's no longer found (HTTP 404 NOT FOUND).
+ *
+ *
+ * Test Steps:
+ *
+ * This test class contains a suite of test cases that verify the behavior of the {@link MachineTrackerController} by mocking HTTP requests and responses. The tests cover various methods and scenarios, including adding and removing vending machines, changing machine locations, and handling exceptions like {@link ResourceNotFoundException} and {@link IllegalInputException}.
+ *
+ * To conduct these tests, Spring's {@link WebMvcTest} annotation is used to focus on testing the controller layer in isolation. Various mock configurations are applied to test different scenarios.
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#getVendMachLocation(int)} method returns the expected location ("Oslo") for a vending machine with a given ID and ensures a 200 (OK) response status.
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#getVendMachLocation(int)} method throws a {@link ResourceNotFoundException} with the message "Should throw" and ensures that the HTTP response status is 404 (Not Found).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#getInventory(int)} method returns a JSON object containing the inventory of a vending machine ("Cola": 10) and ensures that the HTTP response status is 200 (OK).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#getInventory(int)} method throws an {@link IllegalInputException} with the message "Should throw" and ensures that the HTTP response status is 400 (Bad Request).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#addItem(int, String, int)} method returns a JSON object containing the updated inventory of the vending machine ("Coke": 10) and ensures that the HTTP response status is 200 (OK).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#addItem(int, String, int)} method throws an {@link IllegalInputException} with the message "Should throw" and ensures that the HTTP response status is 400 (Bad Request).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#removeItem(int, String, int)} method returns a JSON object containing the updated inventory of the vending machine (e.g., "Coke": 5) and ensures that the HTTP response status is 200 (OK).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#removeItem(int, String, int)} method throws an {@link IllegalInputException} with the message "Should throw" and ensures that the HTTP response status is 400 (Bad Request).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#addVendMach(int, String)} method returns a {@link HashMap} with the added vending machine's ID and location ("1": "Oslo") and ensures that the HTTP response status is 200 (OK).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#addVendMach(int, String)} method throws an {@link IllegalInputException} and ensures that the HTTP response status is 400 Bad Request.
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#removeVendMach(int)} method returns an updated list of vending machines as a {@link HashMap} and ensures that the HTTP response status is 200 (OK).
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#removeVendMach(int)} method handles the scenario where an {@link IllegalInputException} is thrown. It expects the HTTP response status to be 400 Bad Request, and the thrown exception to be of type {@link IllegalInputException} with the message "Should throw."
+ *
+ * Test Steps:
+ *
+ * This test verifies that the {@link MachineTrackerController#changeLocation(int, String)} method correctly updates the location of a vending machine and returns a HashMap with the updated location. It expects the HTTP response status to be 200 (OK).
+ *
+ * Test Steps:
+ *
+ * This test verifies how the {@link MachineTrackerController#changeLocation(int, String)} method handles an {@link IllegalInputException} when trying to update the location of a vending machine. It expects the HTTP response status to be 400 Bad Request and the exception to be of type {@link IllegalInputException}.
+ *
+ * Test Steps:
+ *
+ * This test verifies how the {@link MachineTrackerController#changeLocation(int, String)} method handles a {@link ResourceNotFoundException} when trying to update the location of a vending machine. It expects the HTTP response status to be 404 Not Found and the exception to be of type {@link ResourceNotFoundException}.
+ *
+ * Test Steps:
+ *
+ * The tests are implemented using the JUnit 5 framework and Mockito. The {@link MachineTrackerRepository} class is tested in isolation from the rest of the application.
+ */
public class MachineTrackerRepositoryTest {
private final VendmachtrackPersistence persistence = Mockito.mock(VendmachtrackPersistence.class);
@@ -44,8 +49,20 @@ public void setUp() {
}
/**
- * Test case for MachineTrackerRepository's getVendmachtrack method.
- * It Verifies that the method returns the expected MachineTracker object.
+ * Tests the {@link MachineTrackerRepository#getVendmachtrack()} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ * This test case verifies that the {@link MachineTrackerRepository#getVendmachtrack()} method returns the expected {@link MachineTracker} object.
+ *
+ * Test Steps:
+ *
+ * This test case verifies that the {@link MachineTrackerRepository#getVendMach(int)} method returns the expected {@link VendingMachine} object when given a valid machine ID.
+ *
+ * Test Steps:
+ *
+ * Given an ID, this test case verifies that the {@link MachineTrackerRepository#getVendMach(int)} method returns {@code null} if the vending machine is not found in the database.
+ *
+ * Test Steps:
+ *
+ * This test case verifies that the {@link MachineTrackerRepository#saveVendmachtrack(MachineTracker)} method correctly saves and returns a {@link MachineTracker} object.
+ *
+ * Test Steps:
+ *
+ * This test case verifies that the {@link MachineTrackerRepository#addVendMach(int, String)} method correctly adds a vending machine to the list of machines in the {@link MachineTracker} object.
+ * It also ensures that the added vending machine has the correct ID and location.
+ *
+ * Test Steps:
+ *
+ * This test case verifies that the {@link MachineTrackerRepository#addItem(int, String, int)} method correctly adds an item to an existing vending machine and updates the {@link MachineTracker} object accordingly.
+ *
+ * Test Steps:
+ *
+ * This test case verifies that the {@link MachineTrackerRepository#addItem(int, String, int)} method returns {@code null} when attempting to add an item to a non-existent vending machine.
+ *
+ * Test Steps:
+ *
+ * This test case verifies that the {@link MachineTrackerRepository#changeLocation(int, String)} method correctly updates the location of a vending machine with the given ID
+ * and ensures that the updated vending machine is saved in the {@link MachineTracker} object.
+ *
+ * Test Steps:
+ *
+ * This test case covers the scenario where the vending machine with the given ID does not exist in the system.
+ * It verifies that the method correctly returns null when attempting to change the location of a non-existent vending machine.
+ *
+ * Test Steps:
+ *
+ * This test verifies that the method removes a vending machine from the list of machines in the {@link MachineTracker} object..
+ *
+ * Test Steps:
+ *
+ * Tests the scenario where the vending machine to be removed does not exist in the {@link MachineTracker}.
+ *
+ * The test sets up the necessary mocks and data, calls the {@link MachineTrackerRepository#removeVendMach(int)} method with a non-existent vending machine ID,
+ * and verifies that the returned {@link MachineTracker} is the same as the one saved.
+ *
- * The test sets up the necessary mocks and data, calls the removeVendMach
- * method with a non-existent VendindgMachineTracker id,
- * and verifies that the returned VendingMachineTracker is the same as the one
- * saved, and that the saved VendingMachineTracker
- * has the same machines as the original one.
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test cases cover various scenarios including valid inputs, invalid inputs, exceptions, and edge cases to ensure the service behaves as expected.
+ *
+ * This test case verifies that the {@link MachineTrackerService#getVendMachList()} method returns a list of machines when the machine tracker is present.
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test cases cover various scenarios including valid input, invalid input, edge cases, and error handling to ensure the UI behaves as expected.
+ *
+ * The tests in this class extend {@link ApplicationTest}
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Mocks are used to simulate the behavior of the AccessService and MachineTrackerAccessible interfaces.
+ * The tests cover various scenarios related to the vending machine management application.
+ *
+ * @see VendAppController
+ * @see ApplicationTest
+ */
public class VendAppControllerUITest extends ApplicationTest {
private VendAppController controller;
@@ -38,6 +48,14 @@ public class VendAppControllerUITest extends ApplicationTest {
@Mock
private MachineTrackerAccessible mockAccess;
+ /**
+ * Initializes the test environment and sets up mocks for testing the {@link AppController} class.
+ * It mocks the behavior of the AccessService and MachineTrackerAccessible, loads the FXML,
+ * sets the mocked service to the controller, and initializes the scene for testing.
+ *
+ * @param stage The primary stage for the test application.
+ * @throws Exception If an exception occurs during the test setup.
+ */
@Override
public void start(Stage stage) throws Exception {
// Initialize mocks
@@ -68,11 +86,35 @@ public void start(Stage stage) throws Exception {
stage.show();
}
+ /**
+ * Test case for the {@link VenpAppController} class's initialization.
+ * Verifies that the controller instance is not null after initialization.
+ *
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ * Test Steps:
+ *
+ *
+ */
+ @Test
+ @Order(2)
+ public void testIntegrationFlow2() {
+
+ // STEP 1: ServerController: Write the server url and the tracker file name
+ clickOn("#serverUrlField").write("http://localhost:8080");
+ clickOn("#trackerFileNameField").write("tracker.json");
+ clickOn("Submit");
+
+ // Center the stage on the screen
+ centerCurrentStage();
+
+ // Remove the Added Vending Machine
+ clickOn("#idTextFieldRemove").write("1001");
+ clickOn("#removeButton");
+
+ // Assert that the vending machine was removed from the choice box
+ @SuppressWarnings("unchecked") // Suppressing unchecked cast warning because we are certain that the queried
+ // object is of type ChoiceBox
+ *
+ *
+ *
+ *
+ */
+ @Test
+ @Order(1)
+ public void testAddVendMach() {
+
+ // Arrange
+ String baseUrl = "http://localhost:" + port;
+ String newMachineId = "100";
+ String newLocation = "Test Location";
+
+ // Act
+ ResponseEntity
+ *
+ */
+ @Test
+ @Order(2)
+ public void testGetVendMachLocation() {
+
+ // Arrange
+ String baseUrl = "http://localhost:" + port;
+ int existingMachineId = 100;
+ // Act
+ ResponseEntity
+ *
+ */
+ @Test
+ @Order(3)
+ public void testAddItem() {
+
+ // Arrange
+ String baseUrl = "http://localhost:" + port;
+ int machineId = 100;
+ String item = "Cola";
+ int quantity = 5;
+
+ // Act
+ ResponseEntity
+ *
+ */
+ @Test
+ @Order(4)
+ public void testGetItem(){
+
+ String baseUrl = "http://localhost:" + port;
+ int machineId = 100;
+ String item = "Cola";
+ int quantity = 5;
+
+ ResponseEntity
+ *
+ */
+ @Test
+ @Order(5)
+ public void testRemoveItem() {
+
+ // Arrange
+ String baseUrl = "http://localhost:" + port;
+ int machineId = 100;
+ String item = "Cola";
+ int quantityToRemove = 3;
+
+ // Act
+ ResponseEntity
+ *
+ */
+ @Test
+ @Order(6)
+ public void testremovedItem(){
+
+ // Arrange
+ String baseUrl = "http://localhost:" + port;
+ int machineId = 100;
+ String item = "Cola";
+ int quantityToRemove = 3;
+
+ //Act
+ ResponseEntity
+ *
+ */
+ @Test
+ @Order(7)
+ public void testRemoveVendMach() {
+ // Arrange
+ String baseUrl = "http://localhost:" + port;
+ String machineIdToRemove = "100";
+
+ // Act
+ ResponseEntity
+ *
+ */
+ @Test
+ @Order(8)
+ public void testVendMachRemoved(){
+
+ // Arrange
+ String baseUrl = "http://localhost:" + port;
+ String machineIdToRemove = "100";
+
+ // Act
+ ResponseEntity
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_getVendMachList_returnVendmachList() throws Exception {
@@ -77,9 +97,22 @@ public void MachineTrackerController_getVendMachList_returnVendmachList() throws
.andExpect(content().json("{\"1\":\"Oslo\"}"));
}
+
/**
- * Tests the scenario where the MachineTrackerController throws a ResourceNotFoundException when trying to get the list of vending machines.
- * Expects the HTTP response status to be 404 Not Found and the exception to be of type ResourceNotFoundException with the message "Should throw".
+ * Tests the scenario where the {@link MachineTrackerController} throws a {@link ResourceNotFoundException} when trying to get the list of vending machines.
+ *
+ * This test expects the HTTP response status to be 404 (Not Found) and the exception to be of type {@link ResourceNotFoundException} with the message "Should throw".
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_getVendMachList_throwsResourceNotFoundException() throws Exception {
@@ -97,10 +130,24 @@ public void MachineTrackerController_getVendMachList_throwsResourceNotFoundExcep
.andExpect(result -> assertEquals("Should throw", result.getResolvedException().getMessage()));
}
+
/**
- * Test case for the MachineTrackerController's getVendMachLocation method.
- * It tests if the method returns the correct location of a vending machine and
- * the HTTP response status is 200 (OK).
+ * Tests the behavior of the {@link MachineTrackerController#getVendMachLocation(int)} method in the {@link MachineTrackerController} class.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_getVendMachLocation_returnLocation() throws Exception {
@@ -120,8 +167,22 @@ public void MachineTrackerController_getVendMachLocation_returnLocation() throws
}
/**
- * Test case for the MachineTrackerController's getVendMachLocation method when it throws a ResourceNotFoundException.
- * Expects the HTTP response status to be 404 Not Found and the exception to be of type ResourceNotFoundException with the message "Should throw".
+ * Tests the behavior of the {@link MachineTrackerController#getVendMachLocation(int)} method in the {@link MachineTrackerController} class when it throws a {@link ResourceNotFoundException}.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_getVendMachLocation_throwsResourceNotFoundException() throws Exception {
@@ -142,9 +203,22 @@ public void MachineTrackerController_getVendMachLocation_throwsResourceNotFoundE
}
/**
- * Test case for the MachineTrackerController's getInventory method.
- * Expects the response to be a JSON object containing the inventory of the
- * vending machine and the HTTP response status to be 200 (OK).
+ * Tests the behavior of the {@link MachineTrackerController#getInventory(int)} method in the {@link MachineTrackerController} class.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_getInventory_returnInventory() throws Exception {
@@ -165,8 +239,22 @@ public void MachineTrackerController_getInventory_returnInventory() throws Excep
}
/**
- * Tests the MachineTrackerController's getInventory method when it throws an IllegalInputException.
- * Expects the HTTP response status to be 400 Bad Request and the exception to be of type IllegalInputException.
+ * Tests the behavior of the {@link MachineTrackerController#getInventory(int)} method in the {@link MachineTrackerController} class when it throws an {@link IllegalInputException}.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_getInventory_throwsIllegalInputException() throws Exception {
@@ -186,9 +274,22 @@ public void MachineTrackerController_getInventory_throwsIllegalInputException()
}
/**
- * Test case for the MachineTrackerController's addItem method.
- * Expects the response to be a JSON object containing the updated inventory of
- * the vending machine and the HTTP response status to be 200 (OK).
+ * Tests the behavior of the {@link MachineTrackerController#addItem(int, String, int)} method in the {@link MachineTrackerController} class.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_addItem_returnUpdatedInventory() throws Exception {
@@ -209,10 +310,24 @@ public void MachineTrackerController_addItem_returnUpdatedInventory() throws Exc
response.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(content().json("{\"Coke\":10}"));
}
-
+
/**
- * Tests the addItem method of the MachineTrackerController class when an IllegalInputException is thrown.
- * Expects the HTTP response status to be 400 Bad Request and the exception to be of type IllegalInputException.
+ * Tests the behavior of the {@link MachineTrackerController#addItem(int, String, int)} method in the {@link MachineTrackerController} class when it throws an {@link IllegalInputException}.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_addItem_throwsIllegalInputException() throws Exception {
@@ -234,10 +349,22 @@ public void MachineTrackerController_addItem_throwsIllegalInputException() throw
}
/**
- * Tests the removeItem method of the MachineTrackerController class by mocking
- * the HTTP request and response.
- * It verifies that the updated inventory is returned in JSON format with a
- * status code of 200 (OK).
+ * Tests the behavior of the {@link MachineTrackerController#removeItem(int, String, int)} method in the {@link MachineTrackerController} class.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_removeItem_returnUpdatedInventory() throws Exception {
@@ -259,9 +386,24 @@ public void MachineTrackerController_removeItem_returnUpdatedInventory() throws
.andExpect(content().json("{\"Coke\":5}"));
}
+
/**
- * Tests the removeItem method of the MachineTrackerController class when an IllegalInputException is thrown.
- * Expects the HTTP response status to be 400 Bad Request and the exception to be of type IllegalInputException.
+ * Tests the behavior of the {@link MachineTrackerController#removeItem(int, String, int)} method in the {@link MachineTrackerController} class when it throws an {@link IllegalInputException}.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_removeItem_throwsIllegalInputException() throws Exception {
@@ -284,10 +426,24 @@ public void MachineTrackerController_removeItem_throwsIllegalInputException() th
}
+
/**
- * Tests the addVendMach method of the MachineTrackerController class.
- * Expects the method to return a HashMap with the added vending machine's ID
- * and location and the HTTP response status to be 200 (OK).
+ * Tests the behavior of the {@link MachineTrackerController#addVendMach(int, String)} method in the {@link MachineTrackerController} class.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_addVendMach_returnAdded() throws Exception {
@@ -311,9 +467,24 @@ public void MachineTrackerController_addVendMach_returnAdded() throws Exception
.andExpect(content().json("{\"1\":\"Oslo\"}"));
}
+
/**
- * Tests the addVendMach method in the MachineTrackerController class when an IllegalInputException is thrown.
- * Expects the HTTP response status to be 400 Bad Request and the exception to be of type IllegalInputException.
+ * Tests the behavior of the {@link MachineTrackerController#addVendMach(int, String)} method in the {@link MachineTrackerController} class when an {@link IllegalInputException} is thrown.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_addVendMach_throwsIllegalInputException() throws Exception {
@@ -334,10 +505,24 @@ public void MachineTrackerController_addVendMach_throwsIllegalInputException() t
.andExpect(result -> assertEquals("Should throw", result.getResolvedException().getMessage()));
}
+
/**
- * Tests the removeVendMach method of the MachineTrackerController class
- * Expects the method to return a HashMap with the updated list of vending
- * machines and the HTTP response status to be 200 (OK).
+ * Tests the behavior of the {@link MachineTrackerController#removeVendMach(int)} method in the {@link MachineTrackerController} class.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_removeVendMach_returnUpdatedList() throws Exception {
@@ -358,8 +543,22 @@ public void MachineTrackerController_removeVendMach_returnUpdatedList() throws E
}
/**
- * Tests the removeVendMach method of the MachineTrackerController class when an IllegalInputException is thrown.
- * Expects the HTTP response status to be 400 Bad Request and the exception to be of type IllegalInputException.
+ * Tests the behavior of the {@link MachineTrackerController#removeVendMach(int)} method in the {@link MachineTrackerController} class when an {@link IllegalInputException} is thrown.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_removeVendMach_throwsIllegalInputException() throws Exception {
@@ -379,10 +578,24 @@ public void MachineTrackerController_removeVendMach_throwsIllegalInputException(
.andExpect(result -> assertEquals("Should throw", result.getResolvedException().getMessage()));
}
+
/**
- * Tests the changeLocation method of the MachineTrackerController class
- * Expects the method to return a HashMap with the updated location of the
- * vending machine and the HTTP response status to be 200 (OK).
+ * Tests the behavior of the {@link MachineTrackerController#changeLocation(int, String)} method in the {@link MachineTrackerController} class.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_changeLocation_returnUpdatedLocation() throws Exception {
@@ -403,9 +616,24 @@ public void MachineTrackerController_changeLocation_returnUpdatedLocation() thro
.andExpect(content().json("{\"1\":\"Trondheim\"}"));
}
+
/**
- * Tests the behavior of the MachineTrackerController when the changeLocation method throws an IllegalInputException.
- * Expect the HTTP response status to be 400 Bad Request and the exception to be of type IllegalInputException.
+ * Tests the behavior of the {@link MachineTrackerController#changeLocation(int, String)} method in the {@link MachineTrackerController} class when it throws an {@link IllegalInputException}.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_changeLocation_throwsIllegalInputException() throws Exception {
@@ -426,9 +654,24 @@ public void MachineTrackerController_changeLocation_throwsIllegalInputException(
.andExpect(result -> assertEquals("Should throw", result.getResolvedException().getMessage()));
}
+
/**
- * Tests the scenario where the changeLocation method in MachineTrackerController throws a ResourceNotFoundException.
- * Expects the HTTP response status to be 404 Not Found and the exception to be of type ResourceNotFoundException.
+ * Tests the behavior of the {@link MachineTrackerController#changeLocation(int, String)} method in the {@link MachineTrackerController} class when it throws a {@link ResourceNotFoundException}.
+ *
+ *
+ *
+ *
+ * @throws Exception if an exception occurs during test execution.
*/
@Test
public void MachineTrackerController_changeLocation_throwsResourceNotFoundException() throws Exception {
diff --git a/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/repository/MachineTrackerRepositoryTest.java b/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/repository/MachineTrackerRepositoryTest.java
index d111734..4ae194f 100644
--- a/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/repository/MachineTrackerRepositoryTest.java
+++ b/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/repository/MachineTrackerRepositoryTest.java
@@ -17,6 +17,11 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
+/**
+ * This class contains unit tests for the {@link MachineTrackerRepository} class. It focuses on testing various methods of the repository that interact with vending machines and the {@link MachineTracker} object.
+ *
+ *
*/
@Test
public void MachineTrackerRepository_getVendmachtrack_ReturnMachineTracker() {
@@ -63,8 +80,20 @@ public void MachineTrackerRepository_getVendmachtrack_ReturnMachineTracker() {
}
/**
- * Tests the getVendMach method of the MachineTrackerRepository class.
- * It verifies that the method returns the expected VendingMachine object.
+ * Tests the {@link MachineTrackerRepository#getVendMach(int)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_getVendMach_ReturnVendingMachine() {
@@ -81,11 +110,21 @@ public void MachineTrackerRepository_getVendMach_ReturnVendingMachine() {
assertEquals(vendingmachine, actualVendingMachine);
}
- /**
- * Tests the getVendMach method of the MachineTrackerRepository class when the
- * machine is not found.
- * Given an id, the method should return null if the machine is not found in the
- * database.
+ /**
+ * Tests the {@link MachineTrackerRepository#getVendMach(int)} method of the {@link MachineTrackerRepository} class when the machine is not found.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_getVendMach_retrunsnull() {
@@ -102,9 +141,20 @@ public void MachineTrackerRepository_getVendMach_retrunsnull() {
}
/**
- * Tests the saveVendmachtrack method of the MachineTrackerRepository class.
- * It verifies that the method saves and returns a MachineTracker object
- * correctly.
+ * Tests the {@link MachineTrackerRepository#saveVendmachtrack(MachineTracker)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_SaveVendmachtrack_savesAndRetursMAchinetracker() {
@@ -116,18 +166,26 @@ public void MachineTrackerRepository_SaveVendmachtrack_savesAndRetursMAchinetrac
MachineTracker returnedMachineTracker = machineTrackerRepository.saveVendmachtrack(machineTracker);
// Assert
- verify(persistence, times(1)).saveVendmachtrack(machineTracker); // check that saveVendmachtrack was called once
- // with the correct parameter
- assertSame(machineTracker, returnedMachineTracker); // check that the returned object is the same as the one
- // passed in
+ verify(persistence, times(1)).saveVendmachtrack(machineTracker);
+ assertSame(machineTracker, returnedMachineTracker);
}
/**
- * Tests the addVendMach method of the MachineTrackerRepository class.
- * It verifies that the method adds a vending machine to the list of machines in
- * the MachineTracker object.
- * It also verifies that the added vending machine has the correct id and
- * location.
+ * Tests the {@link MachineTrackerRepository#addVendMach(int, String)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_addVendMach_addsVendingMachine() {
@@ -155,10 +213,22 @@ public void MachineTrackerRepository_addVendMach_addsVendingMachine() {
assertEquals(location, addedVendingMachine.getLocation());
}
+
/**
- * Tests the addItem method of the MachineTrackerRepository class.
- * It verifies that the method adds an item to an existing vending machine and
- * updates the MachineTracker object accordingly.
+ * Tests the {@link MachineTrackerRepository#addItem(int, String, int)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_addItem_addsItemToExistingVendingmachine() {
@@ -186,8 +256,20 @@ public void MachineTrackerRepository_addItem_addsItemToExistingVendingmachine()
}
/**
- * Tests the addItem method of the MachineTrackerRepository class when the
- * vending machine does not exist.
+ * Tests the {@link MachineTrackerRepository#addItem(int, String, int)} method of the {@link MachineTrackerRepository} class when the vending machine does not exist.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_addItem_returnNullVendingMachinenotexist() {
@@ -207,11 +289,21 @@ public void MachineTrackerRepository_addItem_returnNullVendingMachinenotexist()
}
/**
- * Tests the changeLocation method of MachineTrackerRepository class.
- * It verifies that the method updates the location of a vending machine with
- * the given id.
- * It also verifies that the updated vending machine is saved in the
- * MachineTracker object.
+ * Tests the {@link MachineTrackerRepository#changeLocation(int, String)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_changeLocation_changeLocationOnVendingMachine() {
@@ -235,13 +327,24 @@ public void MachineTrackerRepository_changeLocation_changeLocationOnVendingMachi
MachineTracker capturedMachineTracker = machineTrackerCaptor.getValue();
// verify that the captured MachineTracker contains the updated VendingMachine
assertEquals(vendingmachine, capturedMachineTracker.getMachines().get(0));
-
}
/**
- * Test case for the changeLocation method of MachineTrackerRepository class.
- * It tests the scenario where the vending machine with the given id does not
- * exist in the system.
+ * Test case for the {@link MachineTrackerRepository#changeLocation(int, String)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_changeLocation_returnNullVendingMachineNotExist() {
@@ -257,18 +360,23 @@ public void MachineTrackerRepository_changeLocation_returnNullVendingMachineNotE
// Assert
assertNull(result);
-
}
-
+
/**
- * Tests the removeVendMach method of the MachineTrackerRepository class.
- * It verifies that the method removes a vending machine from the list of
- * machines in the MachineTracker object,
- * saves the updated MachineTracker object to the persistence layer, and returns
- * the updated MachineTracker object.
- * It also verifies that the returned and saved MachineTracker objects are the
- * same and that the list of machines
- * in the updated MachineTracker object is empty.
+ * Tests the {@link MachineTrackerRepository#removeVendMach(int)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_removeVendMach_removesVendingmachine() {
@@ -288,21 +396,29 @@ public void MachineTrackerRepository_removeVendMach_removesVendingmachine() {
assertTrue(result.getMachines().isEmpty());
verify(persistence).saveVendmachtrack(machineTrackerCaptor.capture());
MachineTracker capturedMachineTracker = machineTrackerCaptor.getValue();
- assertEquals(machineTracker, capturedMachineTracker); // ensure the returned and saved MachineTrackers are the
- // same
+ assertEquals(machineTracker, capturedMachineTracker);
}
/**
- * Test case for the removeVendMach method of the MachineTrackerRepository
- * class.
- * Tests the scenario where the vendmach to be removed does not exist in the
- * MachineTracker.
+ * Test case for the {@link MachineTrackerRepository#removeVendMach(int)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_removeVendMach_removeVendmachNotExist() {
@@ -319,20 +435,24 @@ public void MachineTrackerRepository_removeVendMach_removeVendmachNotExist() {
// Assert
assertEquals(machineTracker, result);
- assertNotNull(result.getMachines());
verify(persistence).saveVendmachtrack(machineTrackerCaptor.capture());
MachineTracker capturedMachineTracker = machineTrackerCaptor.getValue();
- assertEquals(machineTracker, capturedMachineTracker); // ensure the returned and saved MachineTrackers are the
- // same
+ assertEquals(machineTracker, capturedMachineTracker);
}
+
/**
- * Tests the removeItem method of the MachineTrackerRepository class.
- * It verifies that the method removes the specified item from the vending
- * machine and updates the status accordingly.
- * It also verifies that the updated vending machine is saved correctly in the
- * persistence layer.
- */
+ * Test case for the {@link MachineTrackerRepository#removeItem(int, String, int)} method of the {@link MachineTrackerRepository} class.
+ *
+ *
+ *
+ */
@Test
public void MachineTrackerRepository_removeitem_removesItemFromVendigMachine() {
@@ -356,17 +476,24 @@ public void MachineTrackerRepository_removeitem_removesItemFromVendigMachine() {
// Assert
assertNotNull(result);
assertEquals(id, result.getId());
- assertEquals(1, result.getStatus().get(item)); // 1 item should remain
+ assertEquals(1, result.getStatus().get(item));
verify(persistence).saveVendmachtrack(machineTrackerCaptor.capture());
MachineTracker capturedMachineTracker = machineTrackerCaptor.getValue();
- assertEquals(machineTracker, capturedMachineTracker); // ensure the returned and saved MachineTrackers are the
- // same
-
+ assertEquals(machineTracker, capturedMachineTracker);
+
}
/**
- * Tests the removeItem method of the MachineTrackerRepository class when the
- * vending machine does not exist.
+ * Test case for the {@link MachineTrackerRepository#removeItem(int, String, int)} method of the {@link MachineTrackerRepository} class when the vending machine does not exist.
+ *
+ *
+ *
*/
@Test
public void MachineTrackerRepository_removeItem_removesItemVendingMachineNotExist() {
diff --git a/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/service/MachineTrackerServiceTest.java b/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/service/MachineTrackerServiceTest.java
index 0dc73b0..a65f18c 100644
--- a/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/service/MachineTrackerServiceTest.java
+++ b/vendmachtrack/springboot/src/test/java/vendmachtrack/springboot/service/MachineTrackerServiceTest.java
@@ -14,10 +14,21 @@
import vendmachtrack.core.model.VendingMachine;
import vendmachtrack.springboot.exception.IllegalInputException;
import vendmachtrack.springboot.exception.ResourceNotFoundException;
+import vendmachtrack.springboot.repository.MachineTrackerRepository;
import java.util.Collections;
import java.util.HashMap;
+/**
+ * Unit tests for the {@link MachineTrackerService} class.
+ * This class contains test cases to verify the behavior of the {@link MachineTrackerService} methods.
+ * Each test case focuses on specific functionality and expected outcomes of the service.
+ *
+ *
+ *
*/
@Test
public void getVendMachList_whenMachineTrackerIsPresent_returnsListOfMachines() {
+
// Arrange
when(repository.getVendmachtrack()).thenReturn(machineTracker);
@@ -63,8 +88,16 @@ public void getVendMachList_whenMachineTrackerIsPresent_returnsListOfMachines()
}
/**
- * Test case for the getVendMachList method of the MachineTrackerService class when the machine tracker is not present.
- * Expects a ResourceNotFoundException to be thrown.
+ * Test case for the {@link MachineTrackerService#getVendMachList()} method of the {@link MachineTrackerService} class when the machine tracker is not present.
+ * Expects a {@link ResourceNotFoundException} to be thrown.
+ *
+ *
+ *
*/
@Test
public void getVendMachList_whenMachineTrackerIsNotPresent_thowsException() {
@@ -78,8 +111,17 @@ public void getVendMachList_whenMachineTrackerIsNotPresent_thowsException() {
}
/**
- * Test case for the getVendMachLocation method of the MachineTrackerService class.
+ * Test case for the {@link MachineTrackerService#getVendMachLocation(int)} method of the {@link MachineTrackerService} class.
* Verifies that the method returns the correct location for a valid machine ID.
+ *
+ *
+ *
*/
@Test
public void getVendMachLocation_validId_returnsLocation() {
@@ -92,13 +134,22 @@ public void getVendMachLocation_validId_returnsLocation() {
// Assert
assertEquals("Oslo", location);
}
-
+
/**
- * Test case for the getVendMachLocation method of the MachineTrackerService class when an invalid id is provided.
- * Expects a ResourceNotFoundException to be thrown.
+ * Test case for the {@link MachineTrackerService#getVendMachLocation(int)} method of the {@link MachineTrackerService} class.
+ * Verifies that the method throws a {@link ResourceNotFoundException} when an invalid ID is provided.
+ *
+ *
+ *
*/
@Test
public void getVendMachLocation_invalidId_throwsResourceNotFoundException() {
+
// Arrange
when(repository.getVendmachtrack()).thenReturn(machineTracker);
@@ -107,9 +158,17 @@ public void getVendMachLocation_invalidId_throwsResourceNotFoundException() {
}
/**
- * Test case for the getInventory method of the MachineTrackerService class.
- * Verifies that the method returns the correct inventory for a valid machine
- * ID.
+ * Test case for the {@link MachineTrackerService#getInventory(int)} method of the {@link MachineTrackerService} class.
+ * Verifies that the method returns the correct inventory for a valid machine ID.
+ *
+ *
+ *
*/
@Test
public void getInventory_validId_returnsInventory() {
@@ -128,8 +187,16 @@ public void getInventory_validId_returnsInventory() {
}
/**
- * Test case for the getInventory method of the MachineTrackerService class when an invalid id is provided.
- * Expects a ResourceNotFoundException to be thrown.
+ * Test case for the {@link MachineTrackerService#getInventory(int)} method of the {@link MachineTrackerService} class when an invalid ID is provided.
+ * Expects a {@link ResourceNotFoundException} to be thrown.
+ *
+ *
+ *
*/
@Test
public void getInventory_invalidId_throwsResourceNotFoundException() {
@@ -141,9 +208,17 @@ public void getInventory_invalidId_throwsResourceNotFoundException() {
}
/**
- * Tests the addItem method of the MachineTrackerService class with valid input.
- * Verifies that the method adds an item to the machine successfully when a
- * valid id, item, and quantity are provided.
+ * Test case for the {@link MachineTrackerService#addItem(int, String, int)} method of the {@link MachineTrackerService} class with valid input.
+ * Verifies that the method adds an item to the machine successfully when a valid ID, item, and quantity are provided.
+ *
+ *
+ *
*/
@Test
public void addItem_validInput_addsItemSuccessfully() {
@@ -163,9 +238,17 @@ public void addItem_validInput_addsItemSuccessfully() {
assertEquals(inventory, updatedInventory);
}
+
/**
- * Tests that an IllegalInputException is thrown when an invalid item is added
- * to the machine.
+ * Test case for the {@link MachineTrackerService#addItem(int, String, int)} method of the {@link MachineTrackerService} class when an invalid item is added to the machine.
+ * Verifies that an {@link IllegalInputException} is thrown when an invalid item is provided.
+ *
+ *
+ *
*/
@Test
public void addItem_invalidItem_throwsIllegalInputException() {
@@ -174,9 +257,15 @@ public void addItem_invalidItem_throwsIllegalInputException() {
}
/**
- * Tests the addItem method of the MachineTrackerService class when an invalid
- * quantity is provided.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#addItem(int, String, int)} method of the {@link MachineTrackerService} class when an invalid quantity is provided.
+ * Verifies that an {@link IllegalInputException} is thrown when an invalid quantity is provided.
+ *
+ *
+ *
*/
@Test
public void addItem_invalidQuantity_throwsIllegalInputException() {
@@ -185,8 +274,16 @@ public void addItem_invalidQuantity_throwsIllegalInputException() {
}
/**
- * Tests the addItem method of the MachineTrackerService class when an invalid is is provided.
- * Expects a ResourceNotFoundException to be thrown.
+ * Test case for the {@link MachineTrackerService#addItem(int, String, int)} method of the {@link MachineTrackerService} class when an invalid ID is provided.
+ * Verifies that a {@link ResourceNotFoundException} is thrown when an invalid ID is provided.
+ *
+ *
+ *
*/
@Test
public void addItem_invalidId_throwsResourceNotFoundException() {
@@ -198,9 +295,18 @@ public void addItem_invalidId_throwsResourceNotFoundException() {
}
/**
- * Tests the addItem method of the MachineTrackerService class when a negative
- * quantity is provided.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#addItem(int, String, int)} method of the {@link MachineTrackerService} class
+ * when an invalid quantity is provided.
+ * Verifies that an {@link IllegalInputException} is thrown when an invalid quantity is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void addItem_negativeQuantity_throwsIllegalInputException() {
@@ -210,8 +316,19 @@ public void addItem_negativeQuantity_throwsIllegalInputException() {
}
/**
- * Tests the addVendMach method of the MachineTrackerService class when an existing id is provided.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#addVendMach(int, String)} method of the {@link MachineTrackerService} class
+ * when an existing ID is provided.
+ * Verifies that the method throws an {@link IllegalInputException} when an existing ID is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void addVendMach_existingId_throwsIllegalInputException() {
@@ -224,8 +341,19 @@ public void addVendMach_existingId_throwsIllegalInputException() {
/**
* Test case for adding a new vending machine to the machine tracker service.
- * It verifies that the method adds a new vending machine successfully when a
- * valid id and location are provided.
+ * Verifies that the method adds a new vending machine successfully when a
+ * valid ID and location are provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void addVendMach_validInput_addsMachineSuccessfully() {
@@ -247,8 +375,19 @@ public void addVendMach_validInput_addsMachineSuccessfully() {
}
/**
- * Tests the addVendMach method of the MachineTrackerService class when an invalid location is provided.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#addVendMach(int, String)} method of the {@link MachineTrackerService} class
+ * when an invalid location is provided.
+ * Verifies that the method throws an {@link IllegalInputException} when an invalid location is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void addVendMach_invalidLocation_throwsIllegalInputException() {
@@ -260,9 +399,19 @@ public void addVendMach_invalidLocation_throwsIllegalInputException() {
}
/**
- * Tests the addVendMach method of the MachineTrackerService class when an
- * invalid id is provided.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#addVendMach(int, String)} method of the {@link MachineTrackerService} class
+ * when an invalid ID is provided.
+ * Verifies that the method throws an {@link IllegalInputException} when an invalid ID is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void addVendMach_invalidId_throwsIllegalInputException() {
@@ -277,8 +426,20 @@ public void addVendMach_invalidId_throwsIllegalInputException() {
}
/**
- * Tests the removeVendMach method of the MachineTrackerService class.
- * It verifies that the method removes a vending machine successfully when a valid id is provided.
+ * Test case for the {@link MachineTrackerService#removeVendMach(int)} method of the {@link MachineTrackerService} class
+ * when a valid ID is provided.
+ * Verifies that the method removes a vending machine successfully when a valid ID is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void removeVendMach_validId_removesMachineSuccessfully() {
@@ -296,8 +457,19 @@ public void removeVendMach_validId_removesMachineSuccessfully() {
}
/**
- * Tests the removeVendMach method of the MachineTrackerService class when an invalid ID is provided.
- * Expects a ResourceNotFoundException to be thrown.
+ * Test case for the {@link MachineTrackerService#removeVendMach(int)} method of the {@link MachineTrackerService} class
+ * when an invalid ID is provided.
+ * Verifies that the method throws a {@link ResourceNotFoundException} when an invalid ID is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void removeVendMach_invalidId_throwsResourceNotFoundException() {
@@ -309,9 +481,20 @@ public void removeVendMach_invalidId_throwsResourceNotFoundException() {
}
/**
- * Tests the changeLocation method of the MachineTrackerService class.
- * It verifies that the method changes the location of a vending machine
- * successfully.
+ * Test case for the {@link MachineTrackerService#changeLocation(int, String)} method of the {@link MachineTrackerService} class
+ * when valid input is provided.
+ * Verifies that the method changes the location of a vending machine successfully.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void changeLocation_validInput_changesLocationSuccessfully() {
@@ -333,9 +516,21 @@ public void changeLocation_validInput_changesLocationSuccessfully() {
assertEquals("Trondheim", updatedMachineList.get(1));
}
+
/**
- * Tests the changeLocation method of the MachineTrackerService class when an invalid location is provided.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#changeLocation(int, String)} method of the {@link MachineTrackerService} class
+ * when an invalid location is provided.
+ * Verifies that the method throws an {@link IllegalInputException} when an invalid location is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void changeLocation_invalidLocation_throwsIllegalInputException() {
@@ -347,8 +542,19 @@ public void changeLocation_invalidLocation_throwsIllegalInputException() {
}
/**
- * Tests the changeLocation method of the MachineTrackerService class when an invalid id is passed as input.
- * Expects a ResourceNotFoundException to be thrown.
+ * Test case for the {@link MachineTrackerService#changeLocation(int, String)} method of the {@link MachineTrackerService} class
+ * when an invalid ID is passed as input.
+ * Verifies that the method throws a {@link ResourceNotFoundException} when an invalid ID is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void changeLocation_invalidId_throwsResourceNotFoundException() {
@@ -360,9 +566,18 @@ public void changeLocation_invalidId_throwsResourceNotFoundException() {
}
/**
- * Tests the removeItem method of the MachineTrackerService class when an
- * invalid item is passed as input.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#removeItem(int, String, int)} method of the {@link MachineTrackerService} class
+ * when an invalid item is passed as input.
+ * Verifies that the method throws an {@link IllegalInputException} when an invalid item is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void removeItem_invalidItem_throwsIllegalInputException() {
@@ -371,9 +586,18 @@ public void removeItem_invalidItem_throwsIllegalInputException() {
}
/**
- * Tests the removeItem method of the MachineTrackerService class when an
- * invalid quantity is provided.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#removeItem(int, String, int)} method of the {@link MachineTrackerService} class
+ * when an invalid quantity is provided.
+ * Verifies that the method throws an {@link IllegalInputException} when an invalid quantity is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void removeItem_invalidQuantity_throwsIllegalInputException() {
@@ -382,8 +606,19 @@ public void removeItem_invalidQuantity_throwsIllegalInputException() {
}
/**
- * Tests the removeItem method of the MachineTrackerService class when an invalid id is provided.
- * Expects a ResourceNotFoundException to be thrown.
+ * Test case for the {@link MachineTrackerService#removeItem(int, String, int)} method of the {@link MachineTrackerService} class
+ * when an invalid ID is provided.
+ * Verifies that the method throws a {@link ResourceNotFoundException} when an invalid ID is provided.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void removeItem_invalidId_throwsResourceNotFoundException() {
@@ -395,9 +630,20 @@ public void removeItem_invalidId_throwsResourceNotFoundException() {
}
/**
- * Tests the removeItem method of the MachineTrackerService class when the item
- * is not in the inventory.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#removeItem(int, String, int)} method of the {@link MachineTrackerService} class
+ * when the item is not in the inventory.
+ * Verifies that the method throws an {@link IllegalInputException} when the item is not present in the inventory.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void removeItem_itemNotInInventory_throwsIllegalInputException() {
@@ -413,9 +659,20 @@ public void removeItem_itemNotInInventory_throwsIllegalInputException() {
}
/**
- * Tests the removeItem method of the MachineTrackerService class when the
- * removal quantity is greater than the inventory.
- * Expects an IllegalInputException to be thrown.
+ * Test case for the {@link MachineTrackerService#removeItem(int, String, int)} method of the {@link MachineTrackerService} class
+ * when the removal quantity is greater than the inventory.
+ * Verifies that the method throws an {@link IllegalInputException} when the removal quantity exceeds the available quantity in the inventory.
+ *
+ *
+ *
+ *
+ * @throws Exception if any error occurs during the test.
*/
@Test
public void removeItem_removalQuantityGreaterThanInventory_throwsIllegalInputException() {
diff --git a/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/RefillControllerUITest.java b/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/RefillControllerUITest.java
index fe506ba..f8bae2a 100644
--- a/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/RefillControllerUITest.java
+++ b/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/RefillControllerUITest.java
@@ -24,6 +24,19 @@
import vendmachtrack.ui.access.AccessService;
import vendmachtrack.ui.access.MachineTrackerAccessible;
+/**
+ * UI tests for the {@link RefillController} class.
+ * This class contains a suite of UI tests to verify the behavior of the RefillController when interacting with the application's user interface.
+ * Each test case focuses on specific UI interactions and expected outcomes.
+ *
+ *
+ *
+ *
+ * @param stage The JavaFX stage for the application.
+ * @throws Exception if any error occurs during the setup.
+ */
@Override
public void start(Stage stage) throws Exception {
@@ -65,6 +96,21 @@ public void start(Stage stage) throws Exception {
stage.show();
}
+ /**
+ * Test case for the {@link RefillController} class's {@code testRefill} method with valid input.
+ * Verifies that the method correctly refills an item in the inventory when valid input is provided.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void RefillController_testRefill_validInput() throws ConnectException {
@@ -87,6 +133,18 @@ public void RefillController_testRefill_validInput() throws ConnectException {
assertEquals("", textField.getText());
}
+ /**
+ * Test case for the {@link RefillController} class's {@code testRefill} method when an invalid number is provided.
+ * Verifies that the method handles the scenario of an invalid number input and displays the appropriate error message.
+ *
+ *
+ *
+ */
@Test
public void RefillController_testRefill_invalidNumber() {
@@ -100,6 +158,18 @@ public void RefillController_testRefill_invalidNumber() {
assertEquals("Invalid input: Please enter a valid number and item", textField.getText());
}
+ /**
+ * Test case for the {@link RefillController} class's {@code testRefill} method when an invalid item is provided.
+ * Verifies that the method handles the scenario of an invalid item input and displays the appropriate error message.
+ *
+ *
+ *
+ */
@Test
public void RefillController_testRefill_invalidItem() {
@@ -113,6 +183,18 @@ public void RefillController_testRefill_invalidItem() {
assertEquals("Invalid input: Please enter a valid number and item", textField.getText());
}
+ /**
+ * Test case for the {@link RefillController} class's {@code testRefill} method when a negative integer is provided as the refill number.
+ * Verifies that the method handles the scenario of a negative integer input and displays the appropriate error message.
+ *
+ *
+ *
+ */
@Test
public void RefillController_testRefill_negativeInteger() {
@@ -126,6 +208,21 @@ public void RefillController_testRefill_negativeInteger() {
assertEquals("Invalid input: Please enter a valid number and item", textField.getText());
}
+ /**
+ * Test case for the {@link RefillController} class's {@code testRefill} method when refilling a new item.
+ * Verifies that the method correctly adds a new item to the inventory when valid input is provided.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void RefillController_testRefill_newItem() throws ConnectException {
diff --git a/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/VendAppControllerUITest.java b/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/VendAppControllerUITest.java
index 507d9ca..fdba590 100644
--- a/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/VendAppControllerUITest.java
+++ b/vendmachtrack/ui/src/test/java/vendmachtrack/ui/controller/VendAppControllerUITest.java
@@ -27,6 +27,16 @@
import java.net.ConnectException;
import java.util.HashMap;
+/**
+ * This class contains UI test cases for the {@link VendAppController} class using JavaFX Application Test.
+ * It focuses on testing the user interface and interaction with the application's GUI components.
+ *
+ *
+ */
@Test
public void testController_VenpAppController() {
assertNotNull(this.controller);
}
+ /**
+ * Test case for the {@link VendAppController} class's menu bar population.
+ * Verifies that the menu bar is populated with the expected number of items after updating the vending machine list.
+ *
+ *
+ *
+ */
@Test
public void VendAppController_testMenuBarPopulation() {
@@ -87,6 +129,21 @@ public void VendAppController_testMenuBarPopulation() {
assertEquals(2, menuBar.getItems().size());
}
+ /**
+ * Test case for the {@link VendAppController} class's menu bar population and selection of a vending machine.
+ * Verifies that the menu bar displays available vending machines, allows selecting one, and shows its inventory when selected.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void VendAppController_testMenuBarPopulation_selectVendingMachine() throws ConnectException {
@@ -97,7 +154,7 @@ public void VendAppController_testMenuBarPopulation_selectVendingMachine() throw
when(mockAccess.getInventory(1)).thenReturn(mockInventory);
// Act
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked") // Suppressing unchecked cast warning because we are certain that the queried object is of type ChoiceBox
+ *
+ */
@Test
public void VendAppController_testMenuBarPopulation_selectNoVendingMachine() {
@@ -119,6 +189,19 @@ public void VendAppController_testMenuBarPopulation_selectNoVendingMachine() {
FxAssert.verifyThat(textArea, TextInputControlMatchers.hasText("No vending machine selected"));
}
+ /**
+ * Test case for the {@link VendAppController} class's refill functionality when no vending machine is selected.
+ * Verifies that when the user clicks the refill button without selecting any vending machine,
+ * an appropriate message is displayed indicating that a vending machine should be selected first.
+ *
+ *
+ *
+ */
@Test
public void VendAppController_testRefill_noVendingMachineSelected() {
@@ -130,6 +213,19 @@ public void VendAppController_testRefill_noVendingMachineSelected() {
FxAssert.verifyThat(textArea, TextInputControlMatchers.hasText("Please select a vending machine."));
}
+ /**
+ * Test case for the {@link VendAppController} class's refill functionality when no vending machine is selected.
+ * Verifies that when the user clicks the refill button without selecting any vending machine,
+ * an appropriate message is displayed indicating that a vending machine should be selected first.
+ *
+ *
+ *
+ */
@Test
public void VendAppController_testUserview_noVendingMachineSelected() {
@@ -141,6 +237,22 @@ public void VendAppController_testUserview_noVendingMachineSelected() {
FxAssert.verifyThat(textArea, TextInputControlMatchers.hasText("Please select a vending machine."));
}
+ /**
+ * Test case for the {@link VendAppController} when adding a valid vending machine.
+ * Verifies that when the user adds a new vending machine with a valid ID and location,
+ * the vending machine is successfully added to the tracker, and the menu bar is updated with the new vending machine.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void VendAppController_testAddVendingMachine_validVendingMachine() throws ConnectException {
@@ -166,6 +278,22 @@ public void VendAppController_testAddVendingMachine_validVendingMachine() throws
assertTrue(menuBar.getItems().contains("id: 3 (Bergen)"));
}
+ /**
+ * Test case for the {@link VendAppController} class's addition of a vending machine with an existing ID.
+ * Verifies that when the user attempts to add a new vending machine with an existing ID,
+ * an appropriate error message is displayed indicating that the machine with that ID already exists.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void VendAppController_testAddVendingMachine_ExistingID() throws ConnectException {
@@ -183,6 +311,19 @@ public void VendAppController_testAddVendingMachine_ExistingID() throws ConnectE
assertEquals("Machine with ID: 2 already exists", outputTextLabel.getText());
}
+ /**
+ * Test case for the {@link VendAppController} class's addition of a vending machine with an invalid ID.
+ * Verifies that when the user attempts to add a new vending machine with an invalid (non-integer) ID,
+ * an appropriate error message is displayed indicating that the machine ID must be an integer.
+ *
+ *
+ *
+ */
@Test
public void VendAppController_testAddVendingMachine_InvalidID() {
@@ -196,6 +337,22 @@ public void VendAppController_testAddVendingMachine_InvalidID() {
assertEquals("Machine ID must be an integer", outputTextLabel.getText());
}
+ /**
+ * Test case for the {@link VendAppController} class's addition of a vending machine with an invalid location.
+ * Verifies that when the user attempts to add a new vending machine with an invalid location name,
+ * an appropriate error message is displayed indicating that the location name is not valid.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void VendAppController_testAddVendingMachine_InvalidLocation() throws ConnectException {
@@ -213,6 +370,19 @@ public void VendAppController_testAddVendingMachine_InvalidLocation() throws Con
assertEquals("Location Name not valid", outputTextLabel.getText());
}
+ /**
+ * Test case for the {@link VendAppController} class's addition of a vending machine when no ID is written.
+ * Verifies that when the user attempts to add a new vending machine without entering an ID,
+ * an appropriate error message is displayed indicating that the machine ID must be an integer.
+ *
+ *
+ *
+ */
@Test
public void VendAppController_testAddVendingMachine_NoIdWritten() {
@@ -225,6 +395,22 @@ public void VendAppController_testAddVendingMachine_NoIdWritten() {
assertEquals("Machine ID must be an integer", outputTextLabel.getText());
}
+ /**
+ * Test case for the {@link VendAppController} class's addition of a vending machine when no location is written.
+ * Verifies that when the user attempts to add a new vending machine without entering a location name,
+ * an appropriate error message is displayed indicating that the location name is not valid.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void VendAppController_testAddVendingMachine_NoLocationWritten() throws ConnectException {
@@ -241,6 +427,22 @@ public void VendAppController_testAddVendingMachine_NoLocationWritten() throws C
assertEquals("Location Name not valid", outputTextLabel.getText());
}
+ /**
+ * Test case for the {@link VendAppController} class's removal of a vending machine.
+ * Verifies that when the user attempts to remove an existing vending machine,
+ * it is successfully removed from the tracker, and the appropriate confirmation message is displayed.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void VendAppController_testRemoveVendingMachine_removesVendingmachine() throws ConnectException {
@@ -261,6 +463,22 @@ public void VendAppController_testRemoveVendingMachine_removesVendingmachine() t
assertFalse(menuBar.getItems().contains("id: 1 (Oslo)"));
}
+ /**
+ * Test case for the {@link VendAppController} class's removal of a vending machine with an invalid ID.
+ * Verifies that when the user attempts to remove a vending machine with an invalid ID,
+ * an appropriate error message is displayed indicating that there is no such vending machine with the given ID.
+ *
+ *
+ *
+ *
+ * @throws ConnectException if there is a connection issue during the test.
+ */
@Test
public void VendAppController_testRemoveVendingMachine_invalidID() throws ConnectException {
@@ -276,6 +494,19 @@ public void VendAppController_testRemoveVendingMachine_invalidID() throws Connec
assertEquals("No such Vending Machine with ID: 5", outputTextLabel.getText());
}
+ /**
+ * Test case for the {@link VendAppController} class's removal of a vending machine with a non-integer ID.
+ * Verifies that when the user attempts to remove a vending machine with a non-integer ID,
+ * an appropriate error message is displayed indicating that the machine ID must be an integer.
+ *
+ *
+ *
+ */
@Test
public void VendAppController_testRemoveVendingMachine_notInteger() {