Skip to content

Commit

Permalink
Update CoffeeShopDomain.png, update README.md with instructions, fix …
Browse files Browse the repository at this point in the history
…broken links in SETUP.md, add getters tests for records, remove some unused code
  • Loading branch information
emilie-robichaud committed Sep 12, 2023
1 parent 2b4655c commit 1b74fbb
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 79 deletions.
Binary file removed coffee-shop-kata-solutions/coffeeshop.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CoffeeShopOrder {

private final String customerName;
private final int orderNumber;
private final List<Item> orderItems;

public CoffeeShopOrder(String customerName, List<Item> orderItems) {
this.customerName = customerName;
this.orderItems = orderItems;
this.orderNumber = new Random().nextInt();
}

public String getCustomerName() {
return customerName;
}

public int getOrderNumber() {
return orderNumber;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,31 @@ public void generateReceiptTest() {
public void testBagelRecord() {
Bagel bagel2 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true);
assertTrue(Bagel.class.isRecord());
assertEquals(bagel1, bagel2);
assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString());
}

@Test
public void testBagelGetters() {
assertTrue(bagel1.toasted());
assertEquals(bagel1.bagelType(), EVERYTHING);
assertEquals(bagel1.spreadType(), HERB_GARLIC_CREAM_CHEESE);
assertEquals(bagel1, bagel2);
assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString());
}

@Test
public void testCookieRecord() {
Cookie cookie2 = new Cookie(CHOCOLATE_CHIP, true);
assertTrue(Cookie.class.isRecord());
assertTrue(cookie1.warmed());
assertEquals(cookie1.cookieType(), CHOCOLATE_CHIP);
assertEquals(cookie1, cookie2);
assertEquals("Cookie[cookieType=CHOCOLATE_CHIP, warmed=true]", cookie1.toString());
}

@Test
public void testCookieGetters() {
assertTrue(cookie1.warmed());
assertEquals(cookie1.cookieType(), CHOCOLATE_CHIP);
}

@Test
public void testDonutRecord() {
Donut donut2 = new Donut(GLAZED);
Expand All @@ -82,6 +90,11 @@ public void testDonutRecord() {
assertEquals("Donut[donutType=GLAZED]", donut1.toString());
}

@Test
public void testDonutGetters() {
assertEquals(donut1.donutType(), GLAZED);
}

@Test
public void testSealedClasses(){
assertTrue(CoffeeDrink.class.isSealed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CoffeeShopOrder {

private final String customerName;
private final int orderNumber;
private final List<Item> orderItems;
private final double totalPrice;

public CoffeeShopOrder(String customerName, List<Item> orderItems) {
this.customerName = customerName;
this.orderItems = orderItems;
this.totalPrice = calculateTotalPrice();
this.orderNumber = new Random().nextInt();
}

public double calculateTotalPrice() {
double total = 0;
for (Item i : this.orderItems) {
total += i.getPrice();
}
return total;
}

public String getCustomerName() {
return customerName;
}

public int getOrderNumber() {
return orderNumber;
}

public double getTotalPrice() {
return totalPrice;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* NOTE: This class hierarchy shows the usage of sealed classes
*/

//TODO Convert to Sealed interface
//TODO Convert to Sealed interface
public interface CoffeeDrink extends Beverage {
int espressoShot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,49 @@ public void testBagelRecord() {
// TODO: Convert Bagel to record
Bagel bagel2 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true);
assertTrue(Bagel.class.isRecord());
// assertTrue(bagel1.toasted());
// assertEquals(bagel1.bagelType(), EVERYTHING);
// assertEquals(bagel1.spreadType(), HERB_GARLIC_CREAM_CHEESE);
assertEquals(bagel1, bagel2);
assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString());
}

@Test
public void testBagelGetters() {
// TODO: Convert assertions to use Record getters
assertTrue(bagel1.isToasted());
assertEquals(bagel1.getBagelType(), EVERYTHING);
assertEquals(bagel1.getSpreadType(), HERB_GARLIC_CREAM_CHEESE);
}

@Test
public void testCookieRecord() {
// TODO: Convert Cookie to record
Cookie cookie2 = new Cookie(CHOCOLATE_CHIP, true);
assertTrue(Cookie.class.isRecord());
// assertTrue(cookie1.warmed());
// assertEquals(cookie1.cookieType(), CHOCOLATE_CHIP);
assertEquals(cookie1, cookie2);
assertEquals("Cookie[cookieType=CHOCOLATE_CHIP, warmed=true]", cookie1.toString());
}

@Test
public void testCookieGetters() {
// TODO: Convert assertions to use Record getters
assertTrue(cookie1.isWarmed());
assertEquals(cookie1.getCookieType(), CHOCOLATE_CHIP);
}

@Test
public void testDonutRecord() {
// TODO: Convert Donut to record
Donut donut2 = new Donut(GLAZED);
assertTrue(Donut.class.isRecord());
// assertEquals(donut1.donutType(), GLAZED);
assertEquals(donut1, donut2);
assertEquals("Donut[donutType=GLAZED]", donut1.toString());
}

@Test
public void testDonutGetters() {
// TODO: Convert assertions to use Record getters
assertEquals(donut1.getDonutType(), GLAZED);
}

@Test
public void testSealedClasses(){
//TODO Convert Coffee Drink to sealed class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,11 @@
public class CoffeeShopOrder {

private final String customerName;
private final int orderNumber;
private final List<Item> orderItems;
private final double totalPrice;

public CoffeeShopOrder(String customerName, java.util.List<Item> orderItems) {
this.customerName = customerName;
this.orderItems = orderItems;
this.totalPrice = calculateTotalPrice();
this.orderNumber = new java.util.Random().nextInt();
}

public double calculateTotalPrice() {
double total = 0;
for (Item i : this.orderItems) {
total += i.getPrice();
}
return total;
}

public String getCustomerName() {
return customerName;
}

public int getOrderNumber() {
return orderNumber;
}

public double getTotalPrice() {
return totalPrice;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,48 @@ public void getFoodItemsForOrderTest() {
public void generateReceiptTest() {
String expectedReceipt =
"Bagel: EVERYTHING $2.5\n" +
"Cookie: CHOCOLATE_CHIP $1.25\n" +
"Donut: GLAZED $1.75\n" +
"Total: $5.5";
"Cookie: CHOCOLATE_CHIP $1.25\n" +
"Donut: GLAZED $1.75\n" +
"Total: $5.5";
assertEquals(expectedReceipt, coffeeShopOrder.generateReceipt());
}

@Test
public void testBagelClass() {
Bagel bagel2 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true);
assertEquals(bagel1, bagel2);
assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString());
}

@Test
public void testBagelGetters() {
assertTrue(bagel1.isToasted());
assertEquals(bagel1.getBagelType(), EVERYTHING);
assertEquals(bagel1.getSpreadType(), HERB_GARLIC_CREAM_CHEESE);
assertEquals(bagel1, bagel2);
assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString());
}

@Test
public void testCookieClass() {
Cookie cookie2 = new Cookie(CHOCOLATE_CHIP, true);
assertTrue(cookie1.isWarmed());
assertEquals(cookie1.getCookieType(), CHOCOLATE_CHIP);
assertEquals(cookie1, cookie2);
assertEquals("Cookie[cookieType=CHOCOLATE_CHIP, warmed=true]", cookie1.toString());
}

@Test
public void testCookieGetters() {
assertTrue(cookie1.isWarmed());
assertEquals(cookie1.getCookieType(), CHOCOLATE_CHIP);
}

@Test
public void testDonutClass() {
Donut donut2 = new Donut(GLAZED);
assertEquals(donut1.getDonutType(), GLAZED);
assertEquals(donut1, donut2);
assertEquals("Donut[donutType=GLAZED]", donut1.toString());
}

@Test
public void testDonutGetters() {
assertEquals(donut1.getDonutType(), GLAZED);
}
}

0 comments on commit 1b74fbb

Please sign in to comment.