Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package unit_tests;
import beverages.*;
import beverages.supplements.WithCinnamon;
import beverages.supplements.WithCream;
import beverages.supplements.WithMilk;
import org.junit.Assert;
import org.junit.Test;
import static;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
public class BeveragesPricingTest {
private static final double PRECISION = 0.001;
public void computes_coffee_price() {
Beverage coffee = new Coffee();
assertThat(coffee.price(), is(closeTo(1.20, PRECISION)));
public void computes_tea_price() {
Beverage tea = new Tea();
assertThat(tea.price(), is(closeTo(1.50, PRECISION)));
public void computes_hot_chocolate_price() {
Beverage hotChocolate = new HotChocolate();
assertThat(hotChocolate.price(), is(closeTo(1.45, PRECISION)));
public void computes_tea_with_milk_price() {
Beverage teaWithMilk = new WithMilk(new Tea());
assertThat(teaWithMilk.price(), is(closeTo(1.60, PRECISION)));
public void computes_coffee_with_milk_price() {
Beverage coffeWithMilk = new WithMilk(new Coffee());
assertThat(coffeWithMilk.price(), is(closeTo(1.30, PRECISION)));
public void computes_coffee_with_milk_and_cream_price() {
Beverage coffeeWithMilkAndCream = new WithMilk(new WithCream(new Coffee()));
assertThat(coffeeWithMilkAndCream.price(), is(closeTo(1.45, PRECISION)));
public void computes_hot_chocolate_with_cream_price() {
Beverage hotChocolateWithCream = new WithCream(new HotChocolate());
assertThat(hotChocolateWithCream.price(), is(closeTo(1.60, PRECISION)));
public void computes_coffee_with_cinnamon_price() {
Beverage coffeeWithCinamon = new WithCinnamon(new Coffee());
Assert.assertThat(coffeeWithCinamon.price(), is(closeTo(1.25, PRECISION)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment