33import static org .junit .jupiter .api .Assertions .assertEquals ;
44import static org .junit .jupiter .api .Assertions .assertTrue ;
55
6+ import com .codedifferently .lesson16 .Lunch .InvalidCalorieException ;
67import com .codedifferently .lesson16 .Lunch .Lunch ;
78import java .util .ArrayList ;
89import org .junit .jupiter .api .BeforeEach ;
1112public class LunchTest {
1213
1314 private Lunch lunch ;
15+ private Lunch impossibleLunch ;
1416
1517 @ BeforeEach
16- public void setUp () {
18+ public void setUp () throws InvalidCalorieException {
1719 lunch = new Lunch ("Grilled Chicken" , "Caesar Salad" , 450 , Lunch .LunchType .NON_VEGETARIAN );
1820 }
1921
@@ -33,13 +35,13 @@ public void testAddDrink() {
3335 }
3436
3537 @ Test
36- public void testGetHealthMessageHealthy () {
38+ public void testGetHealthMessageHealthy () throws InvalidCalorieException {
3739 lunch = new Lunch ("Salad" , "Fruit" , 300 , Lunch .LunchType .VEGAN );
3840 assertEquals ("This lunch is healthy!" , lunch .getHealthMessage ());
3941 }
4042
4143 @ Test
42- public void testGetHealthMessageUnhealthy () {
44+ public void testGetHealthMessageUnhealthy () throws InvalidCalorieException {
4345 lunch = new Lunch ("Cheeseburger" , "Fries" , 800 , Lunch .LunchType .NON_VEGETARIAN );
4446 assertEquals ("This lunch is high in calories." , lunch .getHealthMessage ());
4547 }
@@ -56,4 +58,52 @@ public void testDisplayDrinks() {
5658 public ArrayList <String > getDrinks () {
5759 return lunch .getDrinks ();
5860 }
59- }
61+
62+ @ Test
63+ public void testLunchType () throws InvalidCalorieException {
64+ lunch = new Lunch ("Tofu Stir Fry" , "Brown Rice" , 350 , Lunch .LunchType .VEGAN );
65+ assertEquals (Lunch .LunchType .VEGAN , lunch .getLunchType ());
66+ }
67+
68+ @ Test
69+ public void testAddMultipleDrinks () {
70+ lunch .addDrink ("Soda" );
71+ lunch .addDrink ("Juice" );
72+ lunch .addDrink ("Coffee" );
73+
74+ ArrayList <String > expectedDrinks = new ArrayList <>();
75+ expectedDrinks .add ("Soda" );
76+ expectedDrinks .add ("Juice" );
77+ expectedDrinks .add ("Coffee" );
78+
79+ assertEquals (expectedDrinks .size (), lunch .getDrinks ().size ());
80+ assertTrue (lunch .getDrinks ().containsAll (expectedDrinks ));
81+ }
82+
83+ @ Test
84+ public void testHighCalories () throws InvalidCalorieException {
85+ lunch = new Lunch ("Double Cheeseburger" , "Loaded Fries" , 2000 , Lunch .LunchType .NON_VEGETARIAN );
86+ assertEquals (2000 , lunch .getCalories ());
87+ }
88+
89+ @ Test
90+ public void testEmptyMainDish () throws InvalidCalorieException {
91+ lunch = new Lunch ("" , "Salad" , 300 , Lunch .LunchType .VEGETARIAN );
92+ assertEquals ("" , lunch .getMainDish ());
93+ }
94+
95+ // Expected to fail with exception message: Calories cannot be zero or negative
96+ @ Test
97+ public void testZeroCalories () throws InvalidCalorieException {
98+ lunch = new Lunch ("Fruit Salad" , "Yogurt" , 0 , Lunch .LunchType .VEGAN );
99+ assertEquals ("Fruit Salad" , lunch .getMainDish ());
100+ assertEquals (0 , lunch .getCalories ());
101+ }
102+
103+ // Expected to fail with exception message: Calories cannot be zero or negative
104+ @ Test
105+ public void testNegativeCaloriesThrowsException () throws InvalidCalorieException {
106+ impossibleLunch = new Lunch ("Grilled Chicken" , "Caesar Salad" , -100 , Lunch .LunchType .NON_VEGETARIAN );
107+ assertEquals (-100 , lunch .getCalories ());
108+ }
109+ }
0 commit comments