Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active December 23, 2022 19:47
Show Gist options
  • Save trikitrok/a9b2b77762045a77cfd9c6854046add7 to your computer and use it in GitHub Desktop.
Save trikitrok/a9b2b77762045a77cfd9c6854046add7 to your computer and use it in GitHub Desktop.
package unit_tests;
import beverages.*;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
public class BeveragesPricingTest {
private static final double PRECISION = 0.001;
@Test
public void computes_coffee_price() {
Beverage coffee = new Coffee();
assertThat(coffee.price(), is(closeTo(1.20, PRECISION)));
}
@Test
public void computes_tea_price() {
Beverage tea = new Tea();
assertThat(tea.price(), is(closeTo(1.50, PRECISION)));
}
@Test
public void computes_hot_chocolate_price() {
Beverage hotChocolate = new HotChocolate();
assertThat(hotChocolate.price(), is(closeTo(1.45, PRECISION)));
}
@Test
public void computes_tea_with_milk_price() {
Tea teaWithMilk = new TeaWithMilk();
assertThat(teaWithMilk.price(), is(closeTo(1.60, PRECISION)));
}
@Test
public void computes_coffee_with_milk_price() {
Coffee coffeeWithMilk = new CoffeeWithMilk();
assertThat(coffeeWithMilk.price(), is(closeTo(1.30, PRECISION)));
}
@Test
public void computes_coffee_with_milk_and_cream_price() {
Coffee coffeeWithMilkAndCream = new CoffeeWithMilkAndCream();
assertThat(coffeeWithMilkAndCream.price(), is(closeTo(1.45, PRECISION)));
}
@Test
public void computes_hot_chocolate_with_cream_price() {
HotChocolateWithCream hotChocolateWithCream = new HotChocolateWithCream();
assertThat(hotChocolateWithCream.price(), is(closeTo(1.60, PRECISION)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment