CustomerMovementService Test - UQcsse3200/2024-studio-3 GitHub Wiki
Dependencies
CustomerMovementService: The service class under test, which manages customer movement by tracking their movement targets.
Vector2: Used to represent target positions as 2D vectors.
GameTime: A service that mimics and controls the time of the game.
EventListener0: To ensure that the right events are triggered, a mocked event listener is used.
ServiceLocator: Registers services used in the game to isolate the class being tested.
GameExtension, MockitoExtension: These are JUnit extensions that allow for game-specific configuration and Mockito functionality.
Implementation
setUp(): Before each test, mocks are initialised using MockitoAnnotations.openMocks(), and a new instance of CustomerMovementService is created.
testRegisterMovement(): This test confirms that the right target position (e.g., (10, 20)) is stored and retrievable using getMovementTarget() when a customer ID (e.g., 1) and a target position are registered.
testUpdateMovement(): This test makes sure that when a customer moves and the target position is updated with a new position, the revised target is recorded correctly.
testUpdateMovementCustomerNotFound(): This test verifies that the movement target stays null if an attempt is made to update the movement of a customer who hasn't registered.
testRemoveMovement(): This test verifies that a customer's goal position becomes null once their movement is registered and subsequently removed.
testRemoveMovementCustomerNotFound(): This test makes sure that the target position stays null in the event that an attempt is made to remove a non-registered customer's movement.
testGetMovementTarget(): Checks that, upon registration of a customer ID and target position, the right movement target is returned.