Skip to content

Lab 6 - "Is It Hot in Here?" Chicken

Adding New Menu Item

The R&D Chefs have come up with a new tasty Chicken Sandwich. Your job is to add that to the menu by creating a new class, ChickenSandwich. In addition to offering the same toppings as the burger, it also has an option for spicy. By default, if not otherwise chosen, the chicken will be spicy (gotta ask for the mild version if you can't take the spice).

Pricing for this sandwich, with no toppings (the "base" price) is $6. For now, the toppings are the same as offered for the Burger (despite protests from the chefs). Later on we'll satisfy the chefs and allow only certain chef-approved toppings.

Run All Tests

Make sure all of your tests pass before getting started.

Overview

You'll be doing the following steps (more detailed instructions are in the next section), so take it slow, write tests first, and write just enough code to make them pass.

  • Create a test for the base sandwich that costs $6
  • Write the code to implement the base sandwich and make the test pass
  • Write a test for adding it to a MealOrder
  • Create a test for asserting that the sandwich is spicy
    • Use a constructor that lets you set that option
  • Write the code to implement the spiciness and make the test pass
  • Write tests and code to allow for the same toppings as on the Burger

Detailed Steps

1. Base ChickenSandwich

  1. Create a test class ChickenSandwichTest and a test for a "base" Chicken Sandwich that costs $6. Your test method might have this code in it:

    ChickenSandwich chickenSandwich = new ChickenSandwich();
    
    assertThat(chickenSandwich.price())
        .isEqualTo(6);
    
  2. Write the code to make that test pass. Make sure to implement the MenuItem interface, e.g.:

    public class ChickenSandwich implements MenuItem {
    }
    
  3. Add a test to MealOrderTest that adds a chicken sandwich and a regular drink to a MealOrder and asserts that it's $7 (chicken = $6, regular drink = $1).

Run All Tests

Make sure all of your tests pass before continuing. It might also be a good time to do a git commit. From the command-line, do:

$ git add --all
$ git commit -m 'Finished base sandwich'

2. Is It Hot In Here?

  1. Write a test for the spiciness of the chicken. Start with the default being spicy, so your test code might look like this:

    ChickenSandwich chickenSandwich = new ChickenSandwich();
    
    assertThat(chickenSandwich.isSpicy())
        .isTrue();
    
  2. Make the test compile, run it and make sure it fails

  3. Write code in ChickenSandwich to make the test pass. Then make sure all tests pass.

  4. Add another test to create a sandwich that's not spicy by using a new constructor, so your test might look like this:

    ChickenSandwich chickenSandwich = new ChickenSandwich(false);
    
    assertThat(chickenSandwich.isSpicy())
        .isFalse();
    

Run All Tests

Make sure all of your tests pass before continuing. It might also be a good time to do a git commit. From the command-line, do:

$ git add --all
$ git commit -m 'Finished spicy sandwich'

3. Add Toppings

  1. Add a test that adds a topping to the chicken and ensure that the price is correct, e.g.:

    ChickenSandwich chickenSandwich = new ChickenSandwich();
    chickenSandwich.addTopping(BurgerTopping.CHEESE);
    
    assertThat(chickenSandwich.price())
        .isEqualTo(7);
    
  2. Make the test compile (adding just enough code) and make sure it fails.

  3. Write code in your ChickenSandwich that uses the Toppings class to support adding toppings. Write just enough code to make the test pass.

Run All Tests

Make sure all of your tests pass. It might also be a good time to do a git commit. From the command-line, do:

$ git add --all
$ git commit -m 'Completed toppings for the chicken sandwich'

You're Done!

If all your tests passed, then you are done with this lab!