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

[레거시 코드 리팩토링 - 4단계] 오찌(오지훈) 미션 제출합니다. #418

Open
wants to merge 5 commits into
base: ohzzi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 35 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,46 @@ plugins {
id 'java'
}

group = 'camp.nextstep.edu'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.11'
subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

repositories {
mavenCentral()
}
group = 'camp.nextstep.edu'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
mavenCentral()
}

dependencies {
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}

bootJar {
enabled = false
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
jar {
enabled = true
}

test {
useJUnitPlatform()
}
}

test {
useJUnitPlatform()
}

bootJar {
enabled = false
}

jar {
enabled = true
}
4 changes: 4 additions & 0 deletions kitchenpos-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testRuntimeOnly 'com.h2database:h2'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package kitchenpos.domain.menu;

import kitchenpos.domain.menu.MenuGroup;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MenuGroupRepository extends JpaRepository<MenuGroup, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kitchenpos.domain.menu;

import java.util.List;
import kitchenpos.domain.menu.Menu;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MenuRepository extends JpaRepository<Menu, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package kitchenpos.domain.order;

import static kitchenpos.domain.common.OrderStatus.COMPLETION;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -84,7 +82,7 @@ public void changeOrderStatus(final String orderStatusName) {
}

private void validateNotCompleted() {
if (orderStatus == COMPLETION) {
if (orderStatus == OrderStatus.COMPLETION) {
throw new CompletedOrderCannotChangeException();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package kitchenpos.domain.table;

import static kitchenpos.domain.common.OrderStatus.COMPLETION;

import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand Down Expand Up @@ -50,7 +48,7 @@ public void changeOrderStatus(final String orderStatusName) {
}

private void validateNotCompleted() {
if (orderStatus == COMPLETION) {
if (orderStatus == OrderStatus.COMPLETION) {
throw new CompletedOrderCannotChangeException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ public void changeEmpty(final boolean empty) {
}

private void validateCookingOrMealOrderNotExistsWhenChangeEmpty() {
orderStatusRecords.forEach(orderStatusRecord -> {
if (orderStatusRecord.isNotCompleted()) {
throw new CookingOrMealOrderTableCannotChangeEmptyException();
}
});
if (orderStatusRecords.stream().anyMatch(OrderStatusRecord::isNotCompleted)) {
throw new CookingOrMealOrderTableCannotChangeEmptyException();
}
}

private void validateNotGrouped() {
Expand Down Expand Up @@ -102,11 +100,9 @@ public void ungroup() {
}

private void validateCookingOrMealOrderNotExistsWhenUngroup() {
orderStatusRecords.forEach(orderStatusRecord -> {
if (orderStatusRecord.isNotCompleted()) {
throw new CookingOrMealOrderTableCannotUngroupedException();
}
});
if (orderStatusRecords.stream().anyMatch(OrderStatusRecord::isNotCompleted)) {
throw new CookingOrMealOrderTableCannotUngroupedException();
}
}

public void add(final OrderStatusRecord orderStatusRecord) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kitchenpos.domain.table;

import java.util.List;
import kitchenpos.domain.table.OrderTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package kitchenpos.domain.table;

import kitchenpos.domain.table.TableGroup;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TableGroupRepository extends JpaRepository<TableGroup, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kitchenpos.exception;

public abstract class ApplicationException extends RuntimeException {

private final int httpStatusCode;

public ApplicationException(final String message, final int httpStatusCode) {
super(message);
this.httpStatusCode = httpStatusCode;
}

public int getHttpStatusCode() {
return httpStatusCode;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package kitchenpos.exception.badrequest;

import kitchenpos.exception.ApplicationException;
import org.springframework.http.HttpStatus;

public abstract class BadRequestException extends ApplicationException {

private static final int BAD_REQUEST_CODE = 400;

protected BadRequestException(final String message) {
super(message, HttpStatus.BAD_REQUEST);
super(message, BAD_REQUEST_CODE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package kitchenpos;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class KitchenPosCoreApplication {

public static void main(String[] args) {
SpringApplication.run(KitchenPosCoreApplication.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package kitchenpos.domain.common;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import kitchenpos.exception.badrequest.NegativeNumberOfGuestsException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

class NumberOfGuestsTest {

@Test
void 인원_수는_음수일_수_없다() {
assertThatThrownBy(() -> new NumberOfGuests(-1)).isInstanceOf(NegativeNumberOfGuestsException.class);
Assertions.assertThatThrownBy(() -> new NumberOfGuests(-1)).isInstanceOf(NegativeNumberOfGuestsException.class);
}
}
16 changes: 16 additions & 0 deletions kitchenpos-external-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dependencies {
implementation project(':kitchenpos-core')
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtimeOnly 'com.h2database:h2'
}

bootJar {
enabled = true
}

jar {
enabled false
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GlobalControllerAdvice {

@ExceptionHandler(ApplicationException.class)
public ResponseEntity<ErrorResponse> handleApplicationException(final ApplicationException e) {
return ResponseEntity.status(e.getHttpStatus()).body(new ErrorResponse(e.getMessage()));
return ResponseEntity.status(e.getHttpStatusCode()).body(new ErrorResponse(e.getMessage()));
}

@ExceptionHandler(RuntimeException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kitchenpos.ServiceTest;
import kitchenpos.dto.menu.request.MenuGroupCreateRequest;
import kitchenpos.dto.menu.response.MenuGroupResponse;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -37,7 +38,7 @@ class MenuGroupServiceTest {

List<MenuGroupResponse> actual = menuGroupService.list();

assertThat(actual).hasSize(2)
Assertions.assertThat(actual).hasSize(2)
.extracting("id")
.containsExactly(menuGroup1Id, menuGroup2Id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import kitchenpos.dto.menu.response.MenuResponse;
import kitchenpos.exception.badrequest.MenuGroupNotExistsException;
import kitchenpos.exception.badrequest.ProductNotExistsException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -78,7 +79,7 @@ class MenuServiceTest {

List<MenuResponse> actual = menuService.list();

assertThat(actual).hasSize(2)
Assertions.assertThat(actual).hasSize(2)
.extracting("id")
.containsExactly(menuId1, menuId2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import kitchenpos.exception.badrequest.MenuNotExistsException;
import kitchenpos.exception.badrequest.OrderNotExistsException;
import kitchenpos.exception.badrequest.OrderTableNotExistsException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -79,7 +80,7 @@ class OrderServiceTest {

Optional<OrderStatusRecord> actual = orderStatusRecordRepository.findById(orderId);

assertThat(actual).isPresent();
Assertions.assertThat(actual).isPresent();
}

@Test
Expand Down Expand Up @@ -135,7 +136,7 @@ class OrderServiceTest {

List<OrderResponse> actual = orderService.list();

assertThat(actual).hasSize(1)
Assertions.assertThat(actual).hasSize(1)
.extracting("id")
.containsExactly(orderId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kitchenpos.ServiceTest;
import kitchenpos.dto.product.request.ProductCreateRequest;
import kitchenpos.dto.product.response.ProductResponse;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -32,7 +33,7 @@ class ProductServiceTest {

List<ProductResponse> actual = productService.list();

assertThat(actual).hasSize(1)
Assertions.assertThat(actual).hasSize(1)
.extracting("id")
.containsOnly(productId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import kitchenpos.dto.table.request.OrderTableCreateRequest;
import kitchenpos.dto.table.response.OrderTableResponse;
import kitchenpos.exception.badrequest.OrderNotExistsException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -44,7 +45,7 @@ class TableServiceTest {

List<OrderTableResponse> actual = tableService.list();

assertThat(actual).hasSize(2)
Assertions.assertThat(actual).hasSize(2)
.extracting("id")
.containsExactly(orderTableId1, orderTableId2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package kitchenpos.ui.menu;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.refEq;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand All @@ -13,6 +12,7 @@
import kitchenpos.dto.menu.request.MenuGroupCreateRequest;
import kitchenpos.dto.menu.response.MenuGroupResponse;
import kitchenpos.ui.product.RestControllerTest;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult;
Expand Down Expand Up @@ -48,7 +48,7 @@ class MenuGroupRestControllerTest extends RestControllerTest {
mvcResult.getResponse().getContentAsByteArray(), new TypeReference<List<MenuGroupResponse>>() {
});

assertThat(menuGroupResponses).hasSize(1)
Assertions.assertThat(menuGroupResponses).hasSize(1)
.usingFieldByFieldElementComparator()
.containsExactly(new MenuGroupResponse(expected.getId(), expected.getName()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package kitchenpos.ui.menu;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand All @@ -21,6 +20,7 @@
import kitchenpos.exception.badrequest.NegativePriceException;
import kitchenpos.exception.badrequest.ProductNotExistsException;
import kitchenpos.ui.product.RestControllerTest;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult;
Expand Down Expand Up @@ -124,7 +124,7 @@ class MenuRestControllerTest extends RestControllerTest {
new TypeReference<List<MenuResponse>>() {
});

assertThat(content).hasSize(1)
Assertions.assertThat(content).hasSize(1)
.extracting("id")
.containsExactly(1L);
}
Expand Down
Loading