Skip to content

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.

  1. Do all the tests pass?

  2. Do a Refactor > Rename... to rename BurgerToppings to the singular BurgerTopping.

  3. 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.

  1. Are all tests passing?

  2. 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);
      }
    }
    
  3. Make sure these two tests fail

  4. 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 the Toppings 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
  5. Make sure all tests pass

Delegate To Toppings

  1. Remove the List<BurgerTopping> from Burger and replace it with an instance of Toppings.

  2. Delegate all code that used to use the List with the Toppings

  3. Make sure all tests continue to pass