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 renameBurgerToppings
to 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
Toppings
class.Note
You will not need to modify any code in
Burger
, the only code you will write in this part is in theToppings
class.- First write code to make the
noToppingsIsZeroPrice
test pass - Next write code to make the
baconAndCheeseCosts3
test 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>
fromBurger
and replace it with an instance ofToppings
. -
Delegate all code that used to use the
List
with theToppings
-
Make sure all tests continue to pass