DancePartyUpgrade - UQcsse3200/2024-studio-3 GitHub Wiki

Test Environment

  • Framework: JUNIT 5
  • Dependencies:
  • Mockito: For mocking dependencies
  • ParameterizedTest: For testing different inputs

Test Cases

1. testDancePartyActivates

  • Purpose: Ensure the Dance Party upgrade activates correctly, and the meter UI becomes visible.
  • Setup:
    • Set player gold to a sufficient amount (100).
    • Call activate() on the dancePartyUpgrade instance.
    • rigger the event "Dancing".
  • Expected Outcome:
    • The upgrade should activate, the layout should become visible, and the meter should display a full bar (value = 1.0).
    • The event "Dancing" should be triggered.
    • activeTimeRemaining should be set to UPGRADE_DURATION.

2. testDancePartyDeactivates

  • Purpose: Ensure the Dance Party upgrade deactivates correctly and the layout UI is hidden.
  • Setup:
    • Call activate() and then deactivate() on the dancePartyUpgrade.
    • Trigger the event "UnDancing".
  • Expected:
    • The upgrade should deactivate, and the meter and text should be removed from the stage.
    • The layout should be hidden, and the event "UnDancing" should be triggered.
    • The meter value should reset to 0.

3. testLoseGoldOnPurchase

  • Purpose: Ensure the correct amount of gold is deducted when the Dance Party upgrade is purchased.
  • Setup:
    • Set player gold to 100.
    • Call activate() on dancePartyUpgrade.
  • Expected: The player's gold should decrease by 20 upon activation.

4. testInsufficientGold

  • Purpose: Ensure the Dance Party upgrade does not activate if there is insufficient gold.
  • Setup:
    • Set player gold to an insufficient amount (e.g., 10).
    • Call activate() and verify that the event notenoughmoney is triggered.
  • Expected: The upgrade should not activate, the layout should remain hidden, and the event "notenoughmoney" should be triggered.

5. testDancePartyFor30Seconds

  • Purpose: Ensure the Dance Party upgrade lasts for 30 seconds and deactivates afterward.
  • Setup: Activate the upgrade and simulate 30 seconds by calling update() repeatedly.
  • Expected:
    • The meter value should gradually deplete as time passes.
    • After 30 seconds, the upgrade should deactivate, and the boost sound should stop playing.

6. testMeterValueAtDifferentLevelsOfDepletion

  • Purpose: Ensure that the meter value updates correctly as the upgrade time depletes.
  • Setup:
    • Use parameterized values for the total depleted time (5, 10, 15, 20, 25, 30 seconds).
    • Activate the upgrade and simulate time by calling update() based on the given value.
  • Expected: The meter value should reflect the remaining upgrade time relative to the total duration.

7. testDispose

  • Purpose: Ensure that all resources related to the Dance Party upgrade are unloaded correctly when dispose() is called.
  • Setup:
    • Call dispose() on the dancePartyUpgrade instance.
    • Verify that the resourceService.unloadAssets() method is called for the textures.
  • Expected: The textures related to the Dance Party upgrade should be unloaded from memory.