LoanUpgrade - UQcsse3200/2024-studio-3 GitHub Wiki

Test Environment

  • Framework: JUNIT 5
  • Dependencies:
  • LoanUpgrade: Class being tested
  • CombatStatsComponent: Mocked to simulate players gold status
  • Entity: Represents player entity
  • EventHandler: Triggers various events
  • ServiceLocater: Retrieves certain services such as PlayerService & RandomComboService
  • RandomComboService: handles random combo events
  • Gdx 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 when getGold is called
    • Invoke activate method on instance
  • Expected Outcome: that addGold method of CombatStatsComponent 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 invokes activate
  • Expected Outcome: the trigger method of randomComboServiceEvents is called when arg is "notenoughmoney"

3. activates when key is pressed

  • Purpose: To verify the update method calls activate when L is pressed

  • Setup:

    • use reflection to mock Gdx.input to simulate key presses
    • Mock input to return true when L is pressed
    • Spies on LoanUpgrade to monitor calls to activate
    • Calls update method
  • Expected Outcome: activate method on loanupgrade is called when L is pressed