Skip to content

Commit

Permalink
test: 테이블 그룹 서비스 예외 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
SeYun committed Oct 5, 2020
1 parent ba4285e commit a8efde4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/kitchenpos/application/TableGroupServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kitchenpos.application;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -38,11 +39,26 @@ void createTest() {
final OrderTable orderTable2 = TestFixture.getOrderTableWithEmpty();
final TableGroup tableGroup = TestFixture.getTableGroup(orderTable1, orderTable2);

when(orderTableDao.findAllByIdIn(anyList())).thenReturn(Arrays.asList(orderTable1, orderTable2));
when(tableGroupDao.save(any())).thenReturn(tableGroup);
final TableGroup actual = tableGroupService.create(tableGroup);

assertThat(actual.getOrderTables()).hasSize(2);
}

@DisplayName("create: 비어있지 않은 테이블이 있다면 예외처리")
@Test
void createTestByNotEmptyTable() {
final OrderTable orderTable1 = TestFixture.getOrderTableWithEmpty();
final OrderTable orderTable2 = TestFixture.getOrderTableWithNotEmpty();
final TableGroup tableGroup = TestFixture.getTableGroup(orderTable1, orderTable2);

when(orderTableDao.findAllByIdIn(anyList())).thenReturn(Arrays.asList(orderTable1, orderTable2));
when(tableGroupDao.save(any())).thenReturn(tableGroup);
tableGroupService.create(tableGroup);
}

// TODO: 2020/10/05 이런 경우에는 테스트를 어떻게 하는지 물어보기
@DisplayName("ungroup: 테이블 그룹 해제 테스트")
@Test
void ungroupTest() {
Expand All @@ -53,4 +69,17 @@ void ungroupTest() {
when(orderDao.existsByOrderTableIdInAndOrderStatusIn(anyList(), anyList())).thenReturn(false);
tableGroupService.ungroup(1L);
}

@DisplayName("ungroup: 테이블 상태가 Cocking이거나 Meal일 경우에는 예외처리")
@Test
void ungroupTestByStatusEqualsCokingAndMeal() {
final OrderTable orderTable1 = TestFixture.getOrderTableWithEmpty();
final OrderTable orderTable2 = TestFixture.getOrderTableWithEmpty();

when(orderTableDao.findAllByTableGroupId(anyLong())).thenReturn(Arrays.asList(orderTable1, orderTable2));
when(orderDao.existsByOrderTableIdInAndOrderStatusIn(anyList(), anyList())).thenReturn(true);

assertThatThrownBy(() -> tableGroupService.ungroup(1L))
.isInstanceOf(IllegalArgumentException.class);
}
}
1 change: 1 addition & 0 deletions src/test/java/kitchenpos/utils/TestFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import kitchenpos.domain.TableGroup;

public class TestFixture {

public static Product getProduct(final int price) {
final Product product = new Product();
product.setName("후라이드");
Expand Down

0 comments on commit a8efde4

Please sign in to comment.