Lab 5 - Toppings On Its Own
Rename BurgerToppings¶
The name no longer seems right as it refers to a specific topping, so you'll rename it.
-
Do all the tests pass?
-
Do a
Refactor > Rename...to renameBurgerToppingsto the singularBurgerTopping. -
Make sure all tests pass
Toppings On Its Own¶
Create a new Toppings class that is completely responsible for keeping track of and calculating the price of toppings.
-
Are all tests passing?
-
Create a new TEST class that will exercise the Toppings class:
package com.welltestedlearning.mealkiosk; public class ToppingsTest { @Test public void noToppingsIsZeroPrice() { Toppings toppings = new Toppings(); assertThat(toppings.price()) .isZero(); } @Test public void baconAndCheeseCosts3() { Toppings toppings = new Toppings(); toppings.add(BurgerTopping.CHEESE); toppings.add(BurgerTopping.BACON); assertThat(toppings.price()) .isEqualTo(3); } } -
Make sure these two tests fail
-
Write code to make the new tests pass by implementing the
Toppingsclass.Note
You will not need to modify any code in
Burger, the only code you will write in this part is in theToppingsclass.- First write code to make the
noToppingsIsZeroPricetest pass - Next write code to make the
baconAndCheeseCosts3test pass - All other existing tests on
Burger, etc., should continue to work
- First write code to make the
-
Make sure all tests pass
Delegate To Toppings¶
-
Remove the
List<BurgerTopping>fromBurgerand replace it with an instance ofToppings. -
Delegate all code that used to use the
Listwith theToppings -
Make sure all tests continue to pass