-
Notifications
You must be signed in to change notification settings - Fork 185
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: 테스트를 통한 코드 보호 #535
base: seungjoopet
Are you sure you want to change the base?
step3: 테스트를 통한 코드 보호 #535
Changes from 2 commits
6487a50
00f88dd
03fd8a0
9e7536f
9808ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kitchenpos.domain; | ||
|
||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MenuGroupJpaRepository | ||
extends JpaRepository<MenuGroup, UUID>, MenuGroupRepository { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface MenuGroupRepository extends JpaRepository<MenuGroup, UUID> { | ||
public interface MenuGroupRepository { | ||
|
||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repository 추상화 👍 |
||
MenuGroup save(final MenuGroup entity); | ||
|
||
Optional<MenuGroup> findById(final UUID id); | ||
|
||
List<MenuGroup> findAll(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kitchenpos.domain; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface MenuJpaRepository extends JpaRepository<Menu, UUID>, MenuRepository { | ||
|
||
List<Menu> findAllByIdIn(List<UUID> ids); | ||
|
||
@Query("select m from Menu m, MenuProduct mp where mp.product.id = :productId") | ||
List<Menu> findAllByProductId(@Param("productId") UUID productId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface MenuRepository extends JpaRepository<Menu, UUID> { | ||
List<Menu> findAllByIdIn(List<UUID> ids); | ||
public interface MenuRepository { | ||
|
||
Menu save(final Menu entity); | ||
|
||
Optional<Menu> findById(final UUID id); | ||
|
||
List<Menu> findAll(); | ||
|
||
List<Menu> findAllByIdIn(final List<UUID> ids); | ||
|
||
@Query("select m from Menu m, MenuProduct mp where mp.product.id = :productId") | ||
List<Menu> findAllByProductId(@Param("productId") UUID productId); | ||
List<Menu> findAllByProductId(final UUID productId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kitchenpos.domain; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProductJpaRepository extends JpaRepository<Product, UUID>, ProductRepository { | ||
|
||
List<Product> findAllByIdIn(List<UUID> ids); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface ProductRepository extends JpaRepository<Product, UUID> { | ||
List<Product> findAllByIdIn(List<UUID> ids); | ||
public interface ProductRepository { | ||
|
||
Optional<Product> findById(final UUID id); | ||
|
||
List<Product> findAllByIdIn(final List<UUID> ids); | ||
|
||
List<Product> findAll(); | ||
|
||
Product save(final Product entity); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package kitchenpos.application; | ||
|
||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import kitchenpos.domain.Menu; | ||
import kitchenpos.domain.MenuGroup; | ||
import kitchenpos.domain.MenuProduct; | ||
import kitchenpos.domain.Product; | ||
|
||
|
||
public abstract class AbstractApplicationServiceTest { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테스트를 위한 객체 생성 메서드들이 모여있는데요. 클래스 이름은 조금 어색한 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이름이 너무 고민이네요 ^_ㅠ |
||
protected Product createProductRequest(final String name, final BigDecimal price) { | ||
final Product product = new Product(); | ||
product.setName(name); | ||
product.setPrice(price); | ||
|
||
return product; | ||
} | ||
|
||
protected Menu createMenuRequest(final String name, final BigDecimal price, | ||
final List<MenuProduct> menuProducts, final MenuGroup menuGroup, final boolean display) { | ||
|
||
final Menu menu = new Menu(); | ||
menu.setName(name); | ||
menu.setPrice(price); | ||
menu.setMenuGroup(menuGroup); | ||
menu.setMenuProducts(menuProducts); | ||
menu.setMenuGroupId(menuGroup.getId()); | ||
menu.setDisplayed(display); | ||
|
||
return menu; | ||
} | ||
|
||
protected MenuGroup createMenuGroupRequest(final String name) { | ||
final MenuGroup menuGroup = new MenuGroup(); | ||
menuGroup.setName(name); | ||
|
||
return menuGroup; | ||
} | ||
|
||
protected MenuProduct createMenuProductRequest(final Product product, final long quantity) { | ||
final MenuProduct menuProduct = new MenuProduct(); | ||
menuProduct.setProduct(product); | ||
menuProduct.setProductId(product.getId()); | ||
menuProduct.setQuantity(quantity); | ||
|
||
return menuProduct; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트를 작성 했으면 체크리스트는 체크해도 좋을 것 같아요. 🙂
#535 (comment)
테스트에 대한 설명이 요구 사항을 그대로 반영하면 다른 구성원이 테스트만 보고 비즈니스를 파악할 수 있지 않을까요?