Skip to content

Commit

Permalink
#456 Fixed code smells and warnings for: StationCookingComponentTest.…
Browse files Browse the repository at this point in the history
…java
  • Loading branch information
Caleb Murphy committed Oct 8, 2024
1 parent 0da0199 commit 6cf88e1
Showing 1 changed file with 25 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.csse3200.game.components.station;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand All @@ -22,12 +19,13 @@
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(GameExtension.class)
public class StationCookingComponentTest {
class StationCookingComponentTest {

public Entity mockStation;
public GameTime mockTime;
Expand All @@ -39,7 +37,7 @@ public class StationCookingComponentTest {
public Entity fishEntity;

@BeforeEach
public void BeforeEach() {
void BeforeEach() {
// Clear service locator before each
ServiceLocator.clear();

Expand All @@ -60,12 +58,12 @@ public void BeforeEach() {
when(mockResourceService.getAsset(anyString(), any())).thenReturn(null);
ServiceLocator.registerResourceService(mockResourceService);

// Now creaate our fake entities
// Now create our fake entities

// Create a fish entity
mockIngredientComponent = mock(IngredientComponent.class);
when(mockIngredientComponent.getCookTime()).thenReturn(1);
mockCookIngredientComponent = new CookIngredientComponent();//mock(CookIngredientComponent.class);
mockCookIngredientComponent = new CookIngredientComponent();
fishEntity = new Entity()
.addComponent(mockIngredientComponent)
.addComponent(mockCookIngredientComponent);
Expand All @@ -85,48 +83,43 @@ public void BeforeEach() {
// Set up the fish entity for cooking and fake it being inside the itemHandler
when(mockItemHandler.peek()).thenReturn(fishEntity.getComponent(IngredientComponent.class));
when(mockItemHandler.peek().getEntity()).thenReturn(fishEntity);
assertNotNull(mockItemHandler.peek());
Assertions.assertNotNull(mockItemHandler.peek());
}

@Test
public void IngredientStartsCooking() {
void IngredientStartsCooking() {
// Need to call create on station here
mockStation.create();

// Test the ingredient starts cooking
mockStation.getEvents().trigger("Cook Ingredient");

//fishEntity.update();

// Now check the item is cooking
boolean isCooking = mockItemHandler.peek().getEntity().getComponent(CookIngredientComponent.class).getIsCooking();
assertTrue(isCooking);
Assertions.assertTrue(isCooking);
}

@Test
public void IngredientStartsCookingThenStops() {
void IngredientStartsCookingThenStops() {
// Need to call create on station here
mockStation.create();

// Test the ingredient starts cooking
mockStation.getEvents().trigger("Cook Ingredient");

//fishEntity.update();

// Now check the item is cooking
boolean isCooking = mockItemHandler.peek().getEntity().getComponent(CookIngredientComponent.class).getIsCooking();
assertTrue(isCooking);
Assertions.assertTrue(isCooking);

// Now stop ingredient cooking
mockStation.getEvents().trigger("Stop Cooking Ingredient");
//fishEntity.getEvents().trigger("stopCookingIngredient");

isCooking = mockItemHandler.peek().getEntity().getComponent(CookIngredientComponent.class).getIsCooking();
assertFalse(isCooking);
Assertions.assertFalse(isCooking);
}

@Test
public void TestIngredientCooks() {
void TestIngredientCooks() {
// Need to call create on station here
mockStation.create();

Expand All @@ -138,19 +131,19 @@ public void TestIngredientCooks() {

// Now check the item is cooking
boolean isCooking = mockItemHandler.peek().getEntity().getComponent(CookIngredientComponent.class).getIsCooking();
assertTrue(isCooking);
Assertions.assertTrue(isCooking);

// Now run the update thing
fishEntity.update();

// now check if it is cooked
verify(mockIngredientComponent).cookItem();
boolean isStillCooking = mockCookIngredientComponent.getIsCooking();
assertTrue(isStillCooking);
Assertions.assertTrue(isStillCooking);
}

@Test
public void TestIngredientBurns() {
void TestIngredientBurns() {
// Need to call create on station here
mockStation.create();

Expand All @@ -162,19 +155,19 @@ public void TestIngredientBurns() {

// Now check the item is cooking
boolean isCooking = mockItemHandler.peek().getEntity().getComponent(CookIngredientComponent.class).getIsCooking();
assertTrue(isCooking);
Assertions.assertTrue(isCooking);

// Now run the update thing
fishEntity.update();

// now check if it is cooked
verify(mockIngredientComponent).burnItem();
boolean isStillCooking = mockCookIngredientComponent.getIsCooking();
assertFalse(isStillCooking);
Assertions.assertFalse(isStillCooking);
}

@Test
public void TestIngredientCooksThenBurns() {
void TestIngredientCooksThenBurns() {
// Need to call create on station here
mockStation.create();

Expand All @@ -186,26 +179,26 @@ public void TestIngredientCooksThenBurns() {

// Now check the item is cooking
boolean isCooking = mockItemHandler.peek().getEntity().getComponent(CookIngredientComponent.class).getIsCooking();
assertTrue(isCooking);
Assertions.assertTrue(isCooking);

// Now run the update thing
fishEntity.update();

// now check if it is cooked
verify(mockIngredientComponent).cookItem();
boolean isStillCooking = mockCookIngredientComponent.getIsCooking();
assertTrue(isStillCooking);
Assertions.assertTrue(isStillCooking);

// Update the item again
fishEntity.update();

verify(mockIngredientComponent).burnItem();
boolean isStillStillCooking = mockCookIngredientComponent.getIsCooking();
assertFalse(isStillStillCooking);
Assertions.assertFalse(isStillStillCooking);
}

@Test
public void TestIngredientDoesntBurn() {
void TestIngredientDoesntBurn() {
// Need to call create on station here
mockStation.create();

Expand All @@ -217,15 +210,15 @@ public void TestIngredientDoesntBurn() {

// Now check the item is cooking
boolean isCooking = mockItemHandler.peek().getEntity().getComponent(CookIngredientComponent.class).getIsCooking();
assertTrue(isCooking);
Assertions.assertTrue(isCooking);

// Now run the update thing
fishEntity.update();

// now check if it is cooked
verify(mockIngredientComponent).cookItem();
boolean isStillCooking = mockCookIngredientComponent.getIsCooking();
assertTrue(isStillCooking);
Assertions.assertTrue(isStillCooking);

// Now attempt to stop the cooking
mockStation.getEvents().trigger("Stop Cooking Ingredient");
Expand All @@ -235,7 +228,7 @@ public void TestIngredientDoesntBurn() {

verify(mockIngredientComponent, times(0)).burnItem();
boolean isStillStillCooking = mockCookIngredientComponent.getIsCooking();
assertFalse(isStillStillCooking);
Assertions.assertFalse(isStillStillCooking);
}

}

0 comments on commit 6cf88e1

Please sign in to comment.