PathFollowTask Test - UQcsse3200/2024-studio-3 GitHub Wiki

Dependencies

  • PathFollowTask: The test's primary class.
  • GameTime: A service that mimics and controls the time of the game.
  • AITaskComponent, Entity, PhysicsMovementComponent: These components simulate in-game entities and their behaviors.
  • 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

The shouldTriggerEvent() method contains the main logic of the test. This function is in charge of confirming that the PathFollowTask initiates the "wanderStart" event:

  • Target Position Setup: The target position (5, 5) is represented by a Vector2 object that is generated. The PathFollowTask is initialized using this position.
  • Task and Entity Initialization: The target position is used to build a new PathFollowTask. Additionally, a container for handling AI tasks in the game called an AITaskComponent is made. This component now includes the PathFollowTask.
  • Next, an Entity containing the AITaskComponent and a PhysicsMovementComponent is created and configured. The creature can communicate with the game's physics system thanks to the PhysicsMovementComponent.
  • Entity Creation: The entity is created by calling the create() method, which initializes all of the components that are attached to the entity. In order to correctly configure the entity's state and prepare it for testing, this is required.
  • Event Listener Mocking: Mockito is used to mimic an event listener by mocking an EventListener0. The entity's event system then registers this listener to receive notifications of the wanderStart event.
  • Starting the Task: The PathFollowTask calls the start() function. This should cause the task to begin behaving in a way that should cause the wanderStart event to occur based on how it is implemented.
  • Event Verification: To confirm that the mimicked EventListener0 received a handle() call, use Mockito's verify() method. This attests to the fact that the wanderStart event was set off by the task when it started.