Test Plan for IngredientComponent - UQcsse3200/2024-studio-3 GitHub Wiki
Test Environment
- Framework: JUnit 5
- Extensions: GameExtension
- Language: Java
- Dependencies: None
Overview
This test plan is designed to validate the functionality of the IngredientComponent class in the game. The class represents ingredients that can be cooked, chopped, or burnt depending on their properties. JUnit tests were used to cover the construction of the IngredientComponent objects which tests various methods that interact with the state of the ingredient. The test cases ensure that the functionality related to cooking, chopping, and state management behaves correctly across different scenarios.
Test Objectives
- Verify the correct construction of IngredientComponent objects with different configurations.
- Ensure that the cookItem, burnItem, and chopItem methods correctly modify the item state or throw appropriate exceptions.
- Validate the behavior of the setItemState and rawItem methods.
- Confirm that the getters for the isCookable and isChoppable properties return the expected values based on the input parameters.
Test Cases
- Constructor Tests
-
Cookable and Choppable Ingredient: Ensure that an ingredient like "Cucumber" is correctly initialized with non-zero cook and chop times. Validate the isCookable and isChoppable flags.
-
Cookable but Not Choppable Ingredient: Ensure that an ingredient like "Beef" is correctly initialized with a non-zero cook time and zero chop time. Validate that it is cookable but not choppable.
-
Choppable but Not Cookable Ingredient: Ensure that an ingredient like "Strawberry" is correctly initialized with a non-zero chop time and zero cook time. Validate that it is choppable but not cookable.
-
Neither Cookable nor Choppable Ingredient: Ensure that an ingredient like "Lettuce" is correctly initialized with both cook time and chop time set to zero. Validate that it is neither cookable nor choppable.
- State Transition Tests
- Cook Item: Verify that calling
cookItem()
changes the itemState to "cooked" for a cookable item (e.g., "Beef"). - Burn Item: Verify that calling
burnItem()
changes the itemState to "burnt" for a cookable item (e.g., "Beef"). - Chop Item: Verify that calling
chopItem()
changes the itemState to "chopped" for a choppable item (e.g., "Banana"). - Set Item State: Test the
setItemState()
method to ensure it correctly updates the itemState of the ingredient.
- Exception Handling Tests
- Cook Unsupported Item: Ensure that attempting to cook a non-cookable item (e.g., "Banana") throws an
UnsupportedOperationException()
with the message "This item is not cookable." - Burn Unsupported Item: Ensure that attempting to burn a non-cookable item throws an
UnsupportedOperationException()
with the message "This item is not able to be burnt." - Chop Unsupported Item: Ensure that attempting to chop a non-choppable item (e.g., "Beef") throws an
UnsupportedOperationException()
with the message "This item is not choppable."
- Raw State Test
- Raw Item: Verify that calling
rawItem()
resets the itemState to "raw" regardless of the current state.
- Getter Method Tests
- IsCookable: Validate that the
getIsCookable()
method correctly returns true or false based on whether the ingredient has a non-zero cook time. - IsChoppable: Validate that the
getIsChoppable()
method correctly returns true or false based on whether the ingredient has a non-zero chop time. - Cook Time and Chop Time: Validate the
getCookTime()
andgetChopTime()
methods return the correct values for the ingredient.