Test Plan for ItemFactory Component - UQcsse3200/2024-studio-3 GitHub Wiki

Overview

The 'ItemFactoryTest' class is designed to test the functionality of the 'ItemFactory' class, which is responsible for creating various item and meal entities within the game. This class uses Junit testing to validate that the factory methods produce the correct entities and they are equipped with the necessary components.

Test Methods

Each test method in 'ItemFactoryTest' verifies the creation of a specific type of item or meal entity. The general structure of the tests includes:

  • Entity Creation: Calls the appropriate factory method to create an entity.
  • Assertions: Verifies that the entity is not null and contains the expected components. It also checks specific attributes to ensure the correct type is assigned to the item.

Common method

  • baseComponentsAssertion(Entity e): A helper method used by multiple test cases to assert that an entity has essential components: PhysicsComponent, HitboxComponent, and ColliderComponent. This method is called after the entity is created to ensure it has all necessary components.

Test Cases

  1. createTemplateItem() method: Objective: Verify that createTemplateItem() creates an Entity with the correct components. Should verify that the created template item has the required physics components and is not 'null'.

  2. createFish() method: Objective: Testing the ItemFactory.createFish(String state) method for creating a fish item with the "raw" state. Asserts that the item type is ItemType.FISH and verifies the presence of base components.

  3. createBeef(String cookedLevel) method:

  • Objective: Verify that createBeef(String cookedLevel) creates a beef entity with the correct attributes based on cookedLevel.

  • Input: "raw", "cooked", "burnt"

  • Expected Output:

  • The entity should have IngredientComponent with the name "Beef" and the appropriate cooked level.

  • The TextureRenderComponent should use the correct path based on cookedLevel.

  • ColliderComponentshould have a density of 1.5f.

  1. Testing createBanana(String chopLevel) Method
  • Objective: Verify that createBanana(String chopLevel) creates a banana entity with the correct attributes based on chopLevel.

  • Input: "raw", "chopped"

Expected Output:

  • The entity should have IngredientComponent with the name "Banana" and the appropriate chop level.
  • The TextureRenderComponent should use the correct path based on chopLevel.
  • ColliderComponent should have a density of 1.5f.

Call ItemFactory.createBanana("raw"). Verify that the entity has IngredientComponent with name "Banana" and chop level "raw". Verify that TextureRenderComponent uses path "images/ingredients/raw_banana.png". Repeat for "chopped" level.

  1. Testing createMeal() Methods Objective: Verify that each meal creation method (e.g., createFruitSalad, createAcaiBowl, createSalad, createSteakMeal, createBananaSplit) creates the correct meal entity with the appropriate components and ingredients.

Expected Output:

  • The entity should have MealComponent with the correct name, item type, and ingredients.
  • TextureRenderComponent should use the correct path for the meal image.
  • ColliderComponent should have a density of 1.5f.

Additionally we test to:

  • Ensure that the PhysicsUtils.setScaledCollider() method is functioning correctly by checking the scaled collider dimensions.
  • Verify that each TextureRenderComponent path is correctly formatted and points to an existing image file.