LoanUpgrade - UQcsse3200/2024-studio-3 GitHub Wiki
Test Environment
- Framework: JUNIT 5
- Dependencies:
LoanUpgrade: Class being testedCombatStatsComponent: Mocked to simulate players gold statusEntity: Represents player entityEventHandler: Triggers various eventsServiceLocater: Retrieves certain services such asPlayerService&RandomComboServiceRandomComboService: handles random combo eventsGdx and Input: simulates key presses
Test Cases
1. activate when sufficient gold
-
Purpose: Verifies that
activatemethod adds gold -
Setup:
- Mock
CombatStatsComponentto return 20 gold whengetGoldis called - Invoke
activatemethod on instance
- Mock
-
Expected Outcome: that
addGoldmethod ofCombatStatsComponentis called with arg 100 to add gold to player
2. not activate when insufficient gold
- Purpose: To ensure
activatetriggers the "notenoughmoney" event if player has insufficient money - Setup: Mocks
CombatStatsComponentand invokesactivate - Expected Outcome: the
triggermethod ofrandomComboServiceEventsis called when arg is "notenoughmoney"
3. activates when key is pressed
-
Purpose: To verify the
updatemethod callsactivatewhenLis pressed -
Setup:
- use reflection to mock
Gdx.inputto simulate key presses - Mock
inputto return true whenLis pressed - Spies on
LoanUpgradeto monitor calls toactivate - Calls
updatemethod
- use reflection to mock
-
Expected Outcome:
activatemethod onloanupgradeis called whenLis pressed