Testing Plan for Weapon Factory - UQcsse3200/2024-studio-1 GitHub Wiki
WeaponFactoryTest
Test Case 1: Create MeleeWeapon
Objective: Test that the WeaponFactory can create a MeleeWeapon.
Setup:
- Create an instance of
WeaponFactory. - Use the
createmethod withCollectible.Type.MELEE_WEAPONand a valid melee weapon specification string.
Execution:
- Call the
createmethod with a valid melee weapon specification.
Expected Outcome:
- The returned
Collectibleobject is an instance ofMeleeWeapon.
Test Case 2: Create RangedWeapon
Objective: Test that the WeaponFactory can create a RangedWeapon.
Setup:
- Create an instance of
WeaponFactory. - Use the
createmethod withCollectible.Type.RANGED_WEAPONand a valid ranged weapon specification string.
Execution:
- Call the
createmethod with a valid ranged weapon specification.
Expected Outcome:
- The returned
Collectibleobject is an instance ofRangedWeapon.
Test Case 3: Create Invalid MeleeWeapon
Objective: Validate that the WeaponFactory throws an IllegalArgumentException when an invalid melee weapon specification is provided.
Setup:
- Create an instance of
WeaponFactory.
Execution:
- Call the
createmethod withCollectible.Type.MELEE_WEAPONand an invalid melee weapon specification string.
Expected Outcome:
- An
IllegalArgumentExceptionis thrown.
Test Case 4: Create Invalid RangedWeapon
Objective: Validate that the WeaponFactory throws an IllegalArgumentException when an invalid ranged weapon specification is provided.
Setup:
- Create an instance of
WeaponFactory.
Execution:
- Call the
createmethod withCollectible.Type.RANGED_WEAPONand an invalid ranged weapon specification string.
Expected Outcome:
- An
IllegalArgumentExceptionis thrown.
Test Case 5: Create Invalid Weapon Type
Objective: Test that the WeaponFactory throws an IllegalArgumentException when an invalid weapon type is provided.
Setup:
- Create an instance of
WeaponFactory.
Execution:
- Call the
createmethod with an invalid weapon type (Collectible.Type.ITEM) and a weapon specification string.
Expected Outcome:
- An
IllegalArgumentExceptionis thrown.
Test Case 6: Create Invalid Weapon Specification
Objective: Validate that the WeaponFactory throws an IllegalArgumentException when an invalid weapon specification is provided.
Setup:
- Create an instance of
WeaponFactory.
Execution:
- Call the
createmethod withCollectible.Type.RANGED_WEAPONand an incorrectly formatted ranged weapon specification string.
Expected Outcome:
- An
IllegalArgumentExceptionis thrown.
Conlusion:
- This set of tests ensures that the WeaponFactory class is capable of creating valid melee and ranged weapons and correctly handles invalid inputs by throwing appropriate exceptions. The results will help improve the robustness and reliability of the weapon creation process within the game. The commented-out test cases for valid melee and ranged weapon creation should be included in future test executions to ensure full coverage.