Testing Plan for ConcreteMeleeWeapon component - UQcsse3200/2024-studio-1 GitHub Wiki

Test Plan for ConcreteMeleeWeapon component

Objective

The objective of this test plan is to validate the functionality of the ConcreteMeleeWeapon class, ensuring correct behavior for creating melee weapons, managing weapon entities, handling pickups and drops in inventory, and verifying weapon attributes like name, icon, damage, range, and fire rate.

Test Environment

Framework: JUnit 5 with Mockito for mocking dependencies

Objects Used:

  • ConcreteMeleeWeapon: Represents a concrete implementation of a melee weapon.
  • Entity: Represents game entities like players or weapons.
  • InventoryComponent: Manages the player's inventory.
  • FiringController: Handles firing logic for the weapon (added to weapon entities).
  • WeaponFactory: Factory class for creating weapon objects (mocked).
  • Inventory: A class representing the player's inventory system.

Setup:

  • The beforeEach() method registers the required services (RenderService, EntityService, PhysicsService, and ResourceService) and loads projectile textures.
  • Mocks are created for Entity (for the weapon entity) and ConcreteMeleeWeapon.

Test Cases

Test Case 1: Create Collectible Melee Weapon

Objective: Verify that a ConcreteMeleeWeapon instance is successfully created.

Setup: Instantiate a new ConcreteMeleeWeapon with parameters: name, icon path, damage, range, and fire rate.

Expected Outcome:

  • The instance is successfully created and is a type of MeleeWeapon.

Test Case 2: Set Weapon Entity

Objective: Test the functionality of assigning a weapon entity to the ConcreteMeleeWeapon.

Setup:

  1. Create a ConcreteMeleeWeapon instance.
  2. Create a new Entity representing the weapon entity.
  3. Use the setWeaponEntity() method to assign the entity to the melee weapon.

Expected Outcome:

  • The getWeaponEntity() method should return the assigned entity.

Test Case 3: Pickup Weapon

Objective: Ensure that the melee weapon can be picked up and added to the player's inventory.

Setup:

  1. Create a ConcreteMeleeWeapon instance and set a weapon entity.
  2. Create an InventoryComponent and add it to a player entity.
  3. Create an Inventory object and call pickup() with the inventory.

Expected Outcome:

  • The weapon should be added to the player's inventory, and inventory.getMelee().isPresent() should return true.

Test Case 4: Drop Weapon

Objective: Ensure that the melee weapon can be dropped and removed from the player's inventory.

Setup:

  1. Create a ConcreteMeleeWeapon instance and set a weapon entity.
  2. Create an InventoryComponent and add it to a player entity.
  3. Create an Inventory object, call pickup() to add the weapon to the inventory, and then call drop().

Expected Outcome:

  • The weapon should be removed from the inventory, and inventory.getMelee().isPresent() should return false.

Test Case 5: Get Weapon Specification

Objective: Validate the weapon specification string returned by the getSpecification() method.

Setup:

  1. Create a ConcreteMeleeWeapon instance with the name "knife".
  2. Call getSpecification().

Expected Outcome:

  • The result should be "melee:knife".

Test Case 6: Get Weapon Name

Objective: Ensure the weapon's name is correctly retrieved using the getName() method.

Setup:

  1. Create a ConcreteMeleeWeapon instance with the name "knife".
  2. Call getName().

Expected Outcome:

  • The result should be "knife".

Test Case 7: Get Icon Path

Objective: Validate that the weapon's icon path is correctly retrieved.

Setup:

  1. Create a ConcreteMeleeWeapon instance with the icon path "knife.png".
  2. Call the iconPath attribute directly.

Expected Outcome:

  • The result should be "knife.png".

Test Case 8: Getters for Weapon Attributes

Objective: Verify that the weapon's damage, range, and fire rate can be retrieved correctly.

Setup:

  1. Create a ConcreteMeleeWeapon instance with values 10 for damage, range, and fire rate.
  2. Call getDamage(), getRange(), and getFireRate().

Expected Outcome:

  • The results should be 10 for all three attributes.

Test Case 9: Setters for Weapon Attributes

Objective: Ensure that the weapon's damage, range, and fire rate can be modified correctly using setter methods.

Setup:

  1. Create a ConcreteMeleeWeapon instance with initial values.
  2. Use setDamage(), setRange(), and setFireRate() to change the values to 20.
  3. Call the respective getter methods to verify the changes.

Expected Outcome:

  • The values should be updated to 20 for damage, range, and fire rate.

Test Case 10: Weapon Attack

Objective: Validate that the weapon can successfully perform an attack and remain present in the player's inventory.

Setup:

  1. Create a ConcreteMeleeWeapon instance and set a weapon entity.
  2. Create an InventoryComponent and add it to a player entity.
  3. Call pickup() to add the weapon to the inventory, and then call attack().

Expected Outcome:

  • The weapon should remain in the inventory after the attack, and inventory.getMelee().isPresent() should return true.

Conclusion

This test plan ensures that the ConcreteMeleeWeapon class performs as expected in creating weapons, managing weapon entities, interacting with the player's inventory, and verifying key weapon attributes such as damage, range, and fire rate.