Merge pull request #433 from atheedom/master

Some minor changes for style and to sync with code in article
This commit is contained in:
Alex Theedom 2016-06-01 00:04:40 +03:00
commit 55c43d5801
3 changed files with 27 additions and 17 deletions

View File

@ -34,16 +34,23 @@ public class Pizza {
private int timeToDelivery; private int timeToDelivery;
public boolean isOrdered() {return false;} public boolean isOrdered() {
return false;
}
public boolean isReady() {return false;} public boolean isReady() {
return false;
}
public boolean isDelivered() {
return false;
}
public boolean isDelivered(){return false;}
public int getTimeToDelivery() { public int getTimeToDelivery() {
return timeToDelivery; return timeToDelivery;
} }
private PizzaStatusEnum (int timeToDelivery) { PizzaStatusEnum(int timeToDelivery) {
this.timeToDelivery = timeToDelivery; this.timeToDelivery = timeToDelivery;
} }
} }
@ -69,10 +76,9 @@ public class Pizza {
} }
public static EnumMap<PizzaStatusEnum, List<Pizza>> groupPizzaByStatus(List<Pizza> pzList) { public static EnumMap<PizzaStatusEnum, List<Pizza>> groupPizzaByStatus(List<Pizza> pzList) {
EnumMap<PizzaStatusEnum, List<Pizza>> map = pzList.stream().collect( return pzList.stream().collect(
Collectors.groupingBy(Pizza::getStatus, Collectors.groupingBy(Pizza::getStatus,
() -> new EnumMap<PizzaStatusEnum, List<Pizza>>(PizzaStatusEnum.class), Collectors.toList())); () -> new EnumMap<>(PizzaStatusEnum.class), Collectors.toList()));
return map;
} }
public void deliver() { public void deliver() {
@ -81,4 +87,5 @@ public class Pizza {
this.setStatus(PizzaStatusEnum.DELIVERED); this.setStatus(PizzaStatusEnum.DELIVERED);
} }
} }
} }

View File

@ -3,7 +3,8 @@ package com.baeldung.enums;
public enum PizzaDeliverySystemConfiguration { public enum PizzaDeliverySystemConfiguration {
INSTANCE; INSTANCE;
private PizzaDeliverySystemConfiguration() {
PizzaDeliverySystemConfiguration() {
// Do the configuration initialization which // Do the configuration initialization which
// involves overriding defaults like delivery strategy // involves overriding defaults like delivery strategy
} }

View File

@ -10,6 +10,7 @@ import java.util.List;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
public class PizzaTest { public class PizzaTest {
@Test @Test
public void givenPizaOrder_whenReady_thenDeliverable() { public void givenPizaOrder_whenReady_thenDeliverable() {
Pizza testPz = new Pizza(); Pizza testPz = new Pizza();
@ -19,7 +20,7 @@ public class PizzaTest {
@Test @Test
public void givenPizaOrders_whenRetrievingUnDeliveredPzs_thenCorrectlyRetrieved() { public void givenPizaOrders_whenRetrievingUnDeliveredPzs_thenCorrectlyRetrieved() {
List<Pizza> pzList = new ArrayList<Pizza>(); List<Pizza> pzList = new ArrayList<>();
Pizza pz1 = new Pizza(); Pizza pz1 = new Pizza();
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED); pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
@ -44,7 +45,7 @@ public class PizzaTest {
@Test @Test
public void givenPizaOrders_whenGroupByStatusCalled_thenCorrectlyGrouped() { public void givenPizaOrders_whenGroupByStatusCalled_thenCorrectlyGrouped() {
List<Pizza> pzList = new ArrayList<Pizza>(); List<Pizza> pzList = new ArrayList<>();
Pizza pz1 = new Pizza(); Pizza pz1 = new Pizza();
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED); pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
@ -75,4 +76,5 @@ public class PizzaTest {
pz.deliver(); pz.deliver();
assertTrue(pz.getStatus() == Pizza.PizzaStatusEnum.DELIVERED); assertTrue(pz.getStatus() == Pizza.PizzaStatusEnum.DELIVERED);
} }
} }