Test Plan for OrderActions - UQcsse3200/2024-studio-3 GitHub Wiki
Test Environment
- Framework: JUnit 5
- Dependencies:
OrderActions: The main class under test.ServiceLocator: Manages the services used in the game.DocketService,InputService,EventHandler: Registered services to support the functionality.Entity: A game entity to whichOrderActionsis attached.EventListener0: Mocked event listeners for verifying event triggers.
Test Cases
1. Initialisation Test
- Purpose: Verify that
OrderActionsis properly initialised. - Setup:
- Initialise
OrderActionswith a reference toGdxGame. - Register necessary services (
DocketService,InputService) in theServiceLocator. - Attach
OrderActionsto anEntity. - Simulate the
create()method call to register listeners and setup the component.
- Initialise
- Expected Outcome:
- The
OrderActionscomponent should register listeners for key game events such as"addOrder","removeOrder","reorderDockets","moveOrder", and"changeColour". - The
OrderActionsshould be properly attached to theEntity.
- The
2. Key Press Handling: Left Bracket Key
- Purpose: Test that pressing the left bracket key triggers the event for shifting dockets to the left.
- Setup:
- Mock an
EventListener0for the"shiftDocketsLeft"event. - Simulate pressing the left bracket key (
Input.Keys.LEFT_BRACKET) using thekeyDown()method.
- Mock an
- Expected Outcome:
- The
keyDown(int keycode)method should returntruefor the left bracket key. - The
"shiftDocketsLeft"event should be triggered, and the associated event listener should handle the event. - No other events (e.g.,
"shiftDocketsRight") should be triggered.
- The
3. Key Press Handling: Right Bracket Key
- Purpose: Test that pressing the right bracket key triggers the event for shifting dockets to the right.
- Setup:
- Mock an
EventListener0for the"shiftDocketsRight"event. - Simulate pressing the right bracket key (
Input.Keys.RIGHT_BRACKET) using thekeyDown()method.
- Mock an
- Expected Outcome:
- The
keyDown(int keycode)method should returntruefor the right bracket key. - The
"shiftDocketsRight"event should be triggered, and the associated event listener should handle the event. - No other events (e.g.,
"shiftDocketsLeft") should be triggered.
- The
4. Key Press Handling: Unhandled Key
- Purpose: Ensure that pressing a key not handled by the
OrderActionscomponent returnsfalse. - Setup:
- Simulate pressing an unrelated key (e.g., the
Akey) using thekeyDown()method.
- Simulate pressing an unrelated key (e.g., the
- Expected Outcome:
- The
keyDown(int keycode)method should returnfalsefor any unhandled key. - No events should be triggered.
- The
5. Event Handling: Add Order
- Purpose: Verify that triggering the
"addOrder"event logs the correct message and initiates any related actions. - Setup:
- Manually trigger the
"addOrder"event usingentity.getEvents().trigger("addOrder").
- Manually trigger the
- Expected Outcome:
- The logger should log
"Add order". - The event handling logic associated with adding an order should execute correctly (if applicable).
- The logger should log
6. Event Handling: Remove Order
- Purpose: Ensure that the
"removeOrder"event triggers reordering of dockets and logs the correct message. - Setup:
- Manually trigger the
"removeOrder"event with an example index usingentity.getEvents().trigger("removeOrder", index).
- Manually trigger the
- Expected Outcome:
- The logger should log
"Remove order". - The
"reorderDockets"event should be triggered with the correct index, ensuring the reordering of dockets.
- The logger should log
7. Event Handling: Move Order
- Purpose: Verify that the
"moveOrder"event is handled correctly and logs the appropriate message. - Setup:
- Manually trigger the
"moveOrder"event usingentity.getEvents().trigger("moveOrder").
- Manually trigger the
- Expected Outcome:
- The logger should log
"Move order". - Any associated logic for moving orders should execute correctly (if applicable).
- The logger should log
8. Event Handling: Change Colour
- Purpose: Ensure that the
"changeColour"event triggers the correct actions related to updating the order's appearance based on the recipe timer. - Setup:
- Manually trigger the
"changeColour"event usingentity.getEvents().trigger("changeColour").
- Manually trigger the
- Expected Outcome:
- The logger should log
"Move order"(or a more appropriate message related to colour change). - The logic associated with changing the colour of an order should execute correctly (if applicable).
- The logger should log
Error Handling:
- The test plan should include scenarios where no orders or events are present, ensuring that
OrderActionsdoes not throw exceptions and logs appropriate warnings.
Logging Verification:
- Ensure that all events are logged correctly using the logger, and these log messages can be used as part of the test assertions where applicable.