ExtortionUpgrade - UQcsse3200/2024-studio-3 GitHub Wiki
Test Environment
- Framework: JUNIT 5
- Dependencies:
Mockito
: For mocking dependenciesParameterizedTest
: For testing different inputs
Test Cases
1. testExtortionUpgradeActivates
- Purpose: Ensure that the Extortion upgrade activates correctly and all relevant UI elements become visible.
- Setup:
- Set player gold to a sufficient amount (100).
- Call activate() on the extortionUpgrade instance.
- Trigger the event "extortion active".
- Expected Outcome:
- The upgrade should activate, and the layout should be visible.
- The meter should show full (value = 1.0), and the event "extortion active"
- activateTimeRemaining should be set to UPGRADE_DURATION.
2. testExtortionUpgradeDeactivates
- Purpose: Ensure the Extortion upgrade deactivates correctly and UI elements are hidden.
- Setup:
- Call activate() and then deactivate() on the extortionUpgrade.
- 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 Extortion upgrade is purchased.
- Setup:
- Set player gold to 100.
- Call activate() on extortionUpgrade.
- Expected: The player's gold should decrease by 40 upon activation.
4. testInsufficientGold
- Purpose: Ensure the Extortion 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, and the layout should remain hidden. Also event notenoughmoney should be triggered
5. testExtortionUpgradeFor30Seconds
- Purpose: Ensure the Extortion 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.
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 Extortion upgrade are unloaded correctly when dispose() is called.
- Setup:
- Call dispose() on the extortionUpgrade instance.
- Verify that the resourceService.unloadAssets() method is called for the textures.
- Expected: The textures related to the Extortion upgrade should be unloaded from memory.