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 which OrderActions is attached.
    • EventListener0: Mocked event listeners for verifying event triggers.

Test Cases

1. Initialisation Test

  • Purpose: Verify that OrderActions is properly initialised.
  • Setup:
    • Initialise OrderActions with a reference to GdxGame.
    • Register necessary services (DocketService, InputService) in the ServiceLocator.
    • Attach OrderActions to an Entity.
    • Simulate the create() method call to register listeners and setup the component.
  • Expected Outcome:
    • The OrderActions component should register listeners for key game events such as "addOrder", "removeOrder", "reorderDockets", "moveOrder", and "changeColour".
    • The OrderActions should be properly attached to the Entity.

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 EventListener0 for the "shiftDocketsLeft" event.
    • Simulate pressing the left bracket key (Input.Keys.LEFT_BRACKET) using the keyDown() method.
  • Expected Outcome:
    • The keyDown(int keycode) method should return true for 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.

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 EventListener0 for the "shiftDocketsRight" event.
    • Simulate pressing the right bracket key (Input.Keys.RIGHT_BRACKET) using the keyDown() method.
  • Expected Outcome:
    • The keyDown(int keycode) method should return true for 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.

4. Key Press Handling: Unhandled Key

  • Purpose: Ensure that pressing a key not handled by the OrderActions component returns false.
  • Setup:
    • Simulate pressing an unrelated key (e.g., the A key) using the keyDown() method.
  • Expected Outcome:
    • The keyDown(int keycode) method should return false for any unhandled key.
    • No events should be triggered.

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 using entity.getEvents().trigger("addOrder").
  • Expected Outcome:
    • The logger should log "Add order".
    • The event handling logic associated with adding an order should execute correctly (if applicable).

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 using entity.getEvents().trigger("removeOrder", index).
  • Expected Outcome:
    • The logger should log "Remove order".
    • The "reorderDockets" event should be triggered with the correct index, ensuring the reordering of dockets.

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 using entity.getEvents().trigger("moveOrder").
  • Expected Outcome:
    • The logger should log "Move order".
    • Any associated logic for moving orders should execute correctly (if applicable).

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 using entity.getEvents().trigger("changeColour").
  • 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).

Error Handling:

  • The test plan should include scenarios where no orders or events are present, ensuring that OrderActions does 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.