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 thePathFollowTask
. - Next, an Entity containing the
AITaskComponent
and aPhysicsMovementComponent
is created and configured. The creature can communicate with the game's physics system thanks to thePhysicsMovementComponent
. - 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 thewanderStart
event. - Starting the Task: The PathFollowTask calls the
start()
function. This should cause the task to begin behaving in a way that should cause thewanderStart
event to occur based on how it is implemented. - Event Verification: To confirm that the mimicked
EventListener0
received ahandle()
call, use Mockito'sverify()
method. This attests to the fact that thewanderStart
event was set off by the task when it started.