-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Mason
authored and
Kevin Mason
committed
Mar 18, 2024
1 parent
df5ce00
commit 66e0bb8
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...07/objects/objects_app/src/test/java/com/codedifferently/lesson7/kevinmason/FoodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.codedifferently.lesson7.kevinmason; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class FoodTest { | ||
|
||
@Test | ||
public void testIsHealthy() { | ||
Food healthyFood = new Food("Apple", 1.0, true, 50, Food.Category.FRUIT); | ||
Food unhealthyFood = new Food("Chocolate", 2.0, false, 600, Food.Category.SNACK); | ||
|
||
assertTrue(healthyFood.isHealthy()); | ||
// Ensure unhealthy food is not considered healthy | ||
assertTrue(!unhealthyFood.isHealthy()); | ||
} | ||
|
||
@Test | ||
public void testPurchase() { | ||
Food food = new Food("Apple", 1.0, true, 50, Food.Category.FRUIT); | ||
food.purchase(3); | ||
// Assert purchase successful | ||
// You can add additional assertions based on your specific implementation | ||
} | ||
|
||
@Test | ||
public void testIsExpired() { | ||
Food food = new Food("Apple", 1.0, true, 50, Food.Category.FRUIT); | ||
// Ensure food is not expired | ||
assertTrue(!food.isExpired()); | ||
} | ||
|
||
@Test | ||
public void testParseCategory() { | ||
try { | ||
Food.Category fruitCategory = Food.parseCategory("fruit"); | ||
assertEquals(Food.Category.FRUIT, fruitCategory); | ||
} catch (Food.InvalidFoodCategoryException e) { | ||
// Fail if exception is thrown for a valid category | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testPrintFoodDetails() { | ||
Food food = new Food("Apple", 1.0, true, 50, Food.Category.FRUIT); | ||
int times = 3; | ||
food.printFoodDetails(times); | ||
// Ensure no assertion is needed as this method only prints details | ||
} | ||
} |