UpgradesDisplay - UQcsse3200/2024-studio-3 GitHub Wiki
Test Environment
- Framework: JUNIT 5
- Dependencies:
Mockito
: For mocking dependenciesParameterizedTest
: For testing different inputs
Test Cases
1. testVisibilityOnSetup
-
Purpose: Ensure that when the UpgradesDisplay is created, the visibility of various UI components is correctly set.
-
Setup:
- Create the UpgradesDisplay object.
- Check the visibility of the upgrades menu image, table, and buttons.
-
Expected Outcome: The upgrades menu image and table should not be visible initially. Also the buttons within the table should be visible
2. testCreateCallsDependencies
- Purpose: Ensure that UpgradesDisplay calls key methods during the
create()
process. - Setup: Spy on UpgradesDisplay and check that key methods like addUpgradeImage(), createUpgradesMenuDisplay(), and createButtonsTable() are called.
- Expected: The key methods should be invoked when create() is called.
3. testToggleVisibility
- Purpose: Verify that the visibility toggle correctly sets the display to visible.
- Setup: Toggle visibility and check that the upgrades menu image and table become visible.
- Expected: UpgradesDisplay, UpgradesMenuImage, and UpgradesTable should be visible, and MainGameScreen.pause() should be invoked.
4. testAddUpgradeImage
- Purpose: Check that the correct upgrade image is added based on the randomly selected upgrade.
- Setup: Mock the randomComboService to return different upgrades (Extortion, Speed, Loan, Dance party) and verify the correct texture is loaded.
- Expected: The correct texture path should be loaded based on the selected upgrade.
5. testCreateButtonsTable
- Purpose: Ensure that the correct buttons (YES and NO) are created in the upgrades menu.
- Setup: Call create() and check that the buttons table has two children: YES and NO buttons.
- Expected: The buttons table should contain YES and NO buttons with the correct labels.
6. testYesButtonClick - same logic used for NoButtonClick
- Purpose: Verify the behavior when the YES button is clicked (activating the upgrade).
- Setup: Simulate a YES button click and check that the upgrade is activated, and the visibility is toggled off.
- Expected: The randomComboService should trigger the activateUpgrade() method, and the response event should be triggered.
7. testDisplayNotEnoughGold
- Purpose: Check that the notEnoughGold UI is displayed correctly when triggered.
- Setup: Call displayNotEnoughGoldUI() and check that the appropriate image is displayed on the screen.
- Expected: The notEnoughGold texture should be loaded and visible in the NotEnoughGoldImages list.
8. testDispose
- Purpose: Ensure that the resources used by UpgradesDisplay are correctly disposed of.
- Setup: Call dispose() and verify that the assets associated with the upgrades menu and textures are unloaded.
- Expected: The upgradesMenuTexture and upgradeTexturePaths should be unloaded from the ResourceService.
9. testInvalidRandomChoice
- Purpose: Verify behavior when an invalid random choice is selected.
- Setup: Override getSelectedUpgrade() to return an invalid choice and check that the result is handled appropriately.
- Expected: An empty string ("") should be returned when an invalid random choice is made.