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
&RandomComboService
RandomComboService
: handles random combo eventsGdx and Input
: simulates key presses
Test Cases
1. activate when sufficient gold
-
Purpose: Verifies that
activate
method adds gold -
Setup:
- Mock
CombatStatsComponent
to return 20 gold whengetGold
is called - Invoke
activate
method on instance
- Mock
-
Expected Outcome: that
addGold
method ofCombatStatsComponent
is called with arg 100 to add gold to player
2. not activate when insufficient gold
- Purpose: To ensure
activate
triggers the "notenoughmoney" event if player has insufficient money - Setup: Mocks
CombatStatsComponent
and invokesactivate
- Expected Outcome: the
trigger
method ofrandomComboServiceEvents
is called when arg is "notenoughmoney"
3. activates when key is pressed
-
Purpose: To verify the
update
method callsactivate
whenL
is pressed -
Setup:
- use reflection to mock
Gdx.input
to simulate key presses - Mock
input
to return true whenL
is pressed - Spies on
LoanUpgrade
to monitor calls toactivate
- Calls
update
method
- use reflection to mock
-
Expected Outcome:
activate
method onloanupgrade
is called whenL
is pressed