Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step3 pull request #82

Open
wants to merge 20 commits into
base: umanking
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d6ed4da
refactor (Number): 파라미터 검증 추가
umanking Feb 13, 2020
e993690
refactor (StringCalculator): 메소드 레퍼런스로 변경
umanking Feb 13, 2020
c85780e
test (ProductBoTest): 상품 등록,조회 테스트
umanking Feb 13, 2020
d90d43b
refactor (README): 요구사항 중심으로 수정
umanking Feb 13, 2020
3b4ab4f
refactor (Numbers): pass by reference 수정
umanking Feb 13, 2020
7a401cb
test (MenuGroupBoTest): 테스트 케이스 작성
umanking Feb 15, 2020
a76c968
test (MenuTest): 테스트 케이스 작성
umanking Feb 15, 2020
f641567
test (MenuTest): 테스트 케이스 작성
umanking Feb 15, 2020
b650506
refactor (Fixtures): 공통 영역 Fixture로 빼기
umanking Feb 15, 2020
e5bb6a9
test (TableBoTest): 테스트 케이스 작성
umanking Feb 15, 2020
1b18873
test (TableGroupBoTest): 테스트 케이스 작성
umanking Feb 15, 2020
ba515e2
test (OrderBoTest): 테스트 케이스 작성
umanking Feb 15, 2020
c427f24
style (TestPackage): formatting & indent
umanking Feb 15, 2020
d430573
delete bin directory
umanking Feb 17, 2020
f0802f7
refactoring: 코드 리뷰 요청 사항 반영
umanking Feb 20, 2020
0d5f61a
refactoring: ID 변수명 변경 및 클래스별 개행 수정
umanking Feb 23, 2020
1066496
refactor(Fixtures): 접근제어자 수정
umanking Feb 27, 2020
dddfc08
refactor(MenuBoTest): 메뉴를 조회할 수 있다. 테스트 케이스
umanking Feb 27, 2020
cee64c3
refactor(MenuBoTest): assertAll 로 변경
umanking Feb 27, 2020
7a372fe
refactor(Test): 누락 된 부분이 많았습니다. (꾸벅)
umanking Feb 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ build/
*.iml
*.ipr
out/
bin/


### NetBeans ###
/nbproject/private/
Expand Down
71 changes: 36 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,52 @@
- 오프라인 매장인 키친 포스를 구현한다.

- 상품 (Products)
- [ ] 상품을 등록 한다.
- [ ] 상품은 이름(name)과 가격(price)를 가진다.
- [ ] 상품의 가격이 올바르지 않으면 등록할 수 없다.
- [ ] 상품을 조회 한다.
- [ ] 상품을 등록 할 수 있다.
- [ ] 상품은 이름과 가격으로 구성 된다.
- [ ] 상품의 가격이 올바르지 않으면 등록할 수 없다.
- [ ] 상품 목록을 조회 할 수 있다.

- 메뉴 그룹 (MenuGroups)
- [ ] 메뉴 그룹을 등록 한다.
- [ ] 메뉴 그룹은 이름(name)를 가진다.
- [ ] 메뉴 그룹들을 조회 한다.
- [ ] 메뉴 그룹을 등록 할 수 있다.
- [ ] 메뉴 그룹은 이름으로 구성 된다.
- [ ] 메뉴 그룹 목록을 조회 할 수 있다.

- 메뉴 (Menu)
- [ ] 메뉴를 등록 한다.
- [ ] 메뉴는 이름, 가격, 메뉴그룹Id, 메뉴상품들로 구성된다.
- [ ] 메뉴의 가격이 올바르지 않으면 등록할 수 없다.
- [ ] 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다
- [ ] 메뉴 상품은 상품Id, 수량으로 배열 형태로 구성된다.
- [ ] 메뉴를 조회 한다.
- [ ] 메뉴를 등록 할 수 있다.
- [ ] 메뉴의 가격이 올바르지 않으면 등록할 수 없다.
- [ ] 메뉴 그룹이 존재 하지 않으면 등록할 수 없다.
- [ ] 메뉴의 가격이, 메뉴에 속한 상품 금액의 합 보다 크면 안된다.
- [ ] 메뉴를 조회 할 수 있다.

- 테이블 (Table)
- [ ] 전체 테이블들을 조회한다.
- [ ] 특정 테이블을 비움(empty)로 업데이트 할 수 있다.
- [ ] 비움(empty)로 업데이트할 때는 반드시 주문 상태(OrderStatus)가 COMPLETION 인 경우에 가능하다.
- [ ] 주문 테이블을 등록할 수 있다.
- [ ] 주문 테이블 목록을 조회 할 수 있다.
- [ ] 주문 테이블의 상태를 비움으로 업데이트 할 수 있다.
- [ ] 주문 테이블이 정상값 이어야 한다.
- [ ] 반드시 식사가 끝난 경우에 상태를 비움으로 업데이트 할 수 있다.
- [ ] 특정 테이블의 인원수를 업데이트 한다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"빈 테이블은 방문한 손님 수를 입력할 수 없다."라는 요구 사항이 필요해 보여요. 아래의 코드를 참고해 주세요.

if (savedOrderTable.isEmpty()) {
    throw new IllegalArgumentException();
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 수정했습니다.

- [ ] 인원수를 업데이트 가능한 조건은 GUEST 숫자값이 정상(0보다 큰)값 이어야 한다.
- [ ] 인원수를 업데이트 가능한 조건은 주문테이블이 빈 상태(empty)가 아니어야 한다.


- [ ] 인원수는 정상값만 입력 받는다.
- [ ] 주문 테이블이 반드시 존재해야 인원수 업데이트가 가능하다.
- [ ] 주문 테이블이 비어있는 상태에서는 인원수 업데이트가 불가능 하다.
- 테이블 그룹 (Table Groups)
- [ ] 주문한 테이블을 등록한다.
- [ ] 테이블 등록이 안되는 경우: 주문 테이블이 비어있거나, 2보다 작은 경우
- [ ] 테이블 등록이 안되는 경우: 파라미터로 넘기는 주문테이블의 사이즈와 DB에서 찾은 사이즈와 같지 않은 경우
- [ ] 테이블 그룹을 삭제한다.
- [ ] 테이블 그룹을 삭제할때는 반드시 OrderStatus가 COMPLETION 이어야 한다.
- [ ] 테이블 그룹을 만들 수 있다.
- [ ] 주문테이블이 2개 이상인 경우에 만들 수 있다.
- [ ] 주문테이블의 사이즈와 동일해야 만들 수 있다.
- [ ] 테이블 그룹을 삭제 할 수 있다.
- [ ] 주문 상태가 요리중이거나 먹고있으면 삭제 할 수 없다.

- 주문 (Order)
- [ ] 주문을 등록할 수 있다.
- [ ] 등록할 수 없는 경우: orderLineItems 비어있는 경우
- [ ] 등록할 수 없는 경우: orderLineItems의 size와 menu의 개수가 일치하지 않는 경우
- [ ] 등록할 수 없는 경우: 주문테이블 id로 조회했을 때 값이 존재하지 않는 경우
- [ ] 등록할 수 없는 경우: OrderStatus 값이 COMPLETION 인 경우
- [ ] 주문은 주문테이블Id, 주문Item들로 구성 된다.
- [ ] 주문Item은 메뉴Id, 수량으로 배열 형태로 구성 된다.
- [ ] 전체 주문을 조회 한다.
- [ ] 주문 상태를 업데이트 한다.
- [ ] 주문 상태는 MEAL, COOKING, COMPLETION 으로 구성된다.
- [ ] 주문을 수 있다.
- [ ] 아이템이 존재해야 주문을 할 수 있다.
- [ ] 주문한 아이템의 메뉴 개수와 메뉴DB에서 개수와 동일해야 한다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 코멘트에 대해 고민해 봐요.
#35 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 코드 중심으로 나열했었네요! 수정하겠습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 반영되지 않았어요. 확인 부탁드려요.

- [ ] 주문 테이블이 존재해야 한다.
- [ ] 주문을 할때는 주문상태를 COOKING 으로 설정한다.
- [ ] 전체 주문 목록을 조회 할 수 있다.
- [ ] 주문 상태를 업데이트 할 수 있다.
- [ ] 주문 상태는 식사중, 요리중, 식사 완료로 구성 된다.
- [ ] 주문 번호가 반드시 존재해야지 업데이트 가능하다.
- [ ] 주문의 상태가 완료되면 업데이트 할 수 없다.

## 용어 사전

Expand Down
17 changes: 10 additions & 7 deletions src/main/java/calculator/Number.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package calculator;

import java.util.Objects;

/**
* @author Geonguk Han
* @since 2020-02-12
Expand All @@ -8,26 +10,27 @@ public class Number {

private final int value;

public Number(String value) {
public Number(final String value) {
this(Integer.parseInt(value));
}

public Number(int value) {
public Number(final int value) {
Objects.requireNonNull(value, "can not be null");
validateNumber(value);
this.value = value;
validateNumber();
}

public int getValue() {
return value;
}

private void validateNumber() {
if (isNegative()) {
private void validateNumber(final int value) {
if (value < 0) {
throw new RuntimeException();
}
}

private boolean isNegative() {
return value < 0;
public Number sum(final Number number) {
return new Number(value + number.value);
}
}
15 changes: 6 additions & 9 deletions src/main/java/calculator/Numbers.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package calculator;

import java.util.Arrays;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* @author Geonguk Han
* @since 2020-02-08
*/
public class Numbers {

private List<Number> numbers;
private final List<Number> numbers;

public Numbers(List<Number> numbers) {
this.numbers = numbers;
public Numbers(final List<Number> numbers) {
this.numbers = new ArrayList<>(numbers);
}

public int sum() {
return numbers.stream()
.map(number -> number.getValue())
.reduce(0, Integer::sum);
.reduce(new Number(0), Number::sum)
.getValue();
}
}
8 changes: 4 additions & 4 deletions src/main/java/calculator/StringCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public int add(final String input) {
if (matcher.find()) {
final String delimiter = matcher.group(1);
final String[] split = matcher.group(2).split(delimiter);
Numbers numbers = parseToNumbers(split);
final Numbers numbers = parseToNumbers(split);
return numbers.sum();
}

final String[] split = input.split(DEFAULT_DELIMITER);
Numbers numbers = parseToNumbers(split);
final Numbers numbers = parseToNumbers(split);
return numbers.sum();
}

private Numbers parseToNumbers(final String[] numbers) {
List<Number> collect = Arrays.asList(numbers)
final List<Number> collect = Arrays.asList(numbers)
.stream()
.map(s -> new Number(s))
.map(Number::new)
.collect(Collectors.toList());

return new Numbers(collect);
Expand Down
121 changes: 121 additions & 0 deletions src/test/java/kitchenpos/bo/Fixtures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package kitchenpos.bo;

import kitchenpos.model.*;
import org.junit.jupiter.api.BeforeAll;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* @author Geonguk Han
* @since 2020-02-15
*/
public class Fixtures {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 픽스처(test fixture) 👍


private static final int QUANTITY_ONE = 1;
private static final long PRODUCT_ID = 1L;
private static final long PRODUCT_ID2 = 2L;
private static final long MENU_ID = 1L;
private static final long MENU_GROUP_ID = 1L;
private static final long MENU_GROUP_ID2 = 2L;
private static final long TABLE_GROUP_ID = 1L;
private static final long ORDER_TABLE_ID = 1L;
private static final long ORDER_TABLE_ID2 = 2L;
private static final long ORDER_TABLE_ID3 = 3L;
private static final long SEQ_ID = 1L;
private static final long SEQ_ID2 = 2L;

public static List<Product> products = Collections.emptyList();
public static List<MenuGroup> menuGroups = Collections.emptyList();
public static Menu menu;
public static List<MenuProduct> menuProducts = Collections.emptyList();
public static List<OrderTable> orderTables = Collections.emptyList();
public static OrderTable orderTable;

@BeforeAll
public static void setUp() {
makeProduct();
makeMenuGroup();
makeMenu();
makeMenuProduct();
makeOrderTable();
}

private static void makeProduct() {
final Product product1 = new Product();
product1.setId(PRODUCT_ID);
product1.setName("짜장면");
product1.setPrice(BigDecimal.valueOf(6000));

final Product product2 = new Product();
product2.setId(PRODUCT_ID2);
product2.setName("짬봉");
product2.setPrice(BigDecimal.valueOf(7000));

products = Arrays.asList(product1, product2);
}

private static void makeMenuGroup() {
final MenuGroup menuGroup1 = new MenuGroup();
menuGroup1.setId(MENU_GROUP_ID);
menuGroup1.setName("면 요리 세트");

final MenuGroup menuGroup2 = new MenuGroup();
menuGroup2.setId(MENU_GROUP_ID2);
menuGroup2.setName("밥 요리 세트");

menuGroups = Arrays.asList(menuGroup1, menuGroup2);
}

private static void makeMenu() {
final Menu newMenu = new Menu();
newMenu.setId(MENU_ID);
newMenu.setName("메뉴");
newMenu.setPrice(products.get(0).getPrice().add(products.get(1).getPrice()));
newMenu.setMenuGroupId(menuGroups.get(0).getId());

menu = newMenu;
}

private static void makeMenuProduct() {
final MenuProduct menuProduct1 = new MenuProduct();
menuProduct1.setSeq(SEQ_ID);
menuProduct1.setMenuId(MENU_ID);
menuProduct1.setProductId(PRODUCT_ID);
menuProduct1.setQuantity(QUANTITY_ONE);

final MenuProduct menuProduct2 = new MenuProduct();
menuProduct2.setSeq(SEQ_ID2);
menuProduct2.setMenuId(MENU_ID);
menuProduct2.setProductId(PRODUCT_ID2);
menuProduct2.setQuantity(QUANTITY_ONE);

menuProducts = Arrays.asList(menuProduct1, menuProduct2);
}

private static void makeOrderTable() {
final OrderTable newOrderTable1 = new OrderTable();
newOrderTable1.setId(ORDER_TABLE_ID);
newOrderTable1.setTableGroupId(TABLE_GROUP_ID);
newOrderTable1.setNumberOfGuests(2);
newOrderTable1.setEmpty(false);

orderTable = newOrderTable1;

final OrderTable newOrderTable2 = new OrderTable();
newOrderTable2.setId(ORDER_TABLE_ID2);
newOrderTable2.setTableGroupId(TABLE_GROUP_ID);
newOrderTable2.setNumberOfGuests(4);
newOrderTable2.setEmpty(false);

final OrderTable newOrderTable3 = new OrderTable();
newOrderTable3.setId(ORDER_TABLE_ID3);
newOrderTable3.setTableGroupId(TABLE_GROUP_ID);
newOrderTable3.setNumberOfGuests(4);
newOrderTable3.setEmpty(false);

orderTables = Arrays.asList(newOrderTable1, newOrderTable2, newOrderTable3);
}
}
Loading