해결된 질문
작성
·
124
0
@Test
void createOrder() {
Long memberId = 1L;
Member member = new Member(memberId, "memberA", Grade.VIP);
memberService.join(member);
Order order = orderService.createOrder(memberId, "itemA", 10000);
Assertions.assertThat(order.getDiscountPrice()).isEqualTo(1000);
}
답변 1
0
안녕하세요. 찬빈님, 공식 서포터즈 y2gcoder입니다.
public class OrderServiceImpl implements OrderService {
private final MemberRepository memberRepository = new MemoryMemberRepository();
private final DiscountPolicy discountPolicy = new FixDiscountPolicy();
@Override
public Order createOrder(Long memberId, String itemName, int itemPrice) {
Member member = memberRepository.findById(memberId);
int discountPrice = discountPolicy.discount(member, itemPrice);
return new Order(memberId, itemName, itemPrice, discountPrice);
}
}
OrderServiceImpl 의 createOrder() 코드를 보시면 memberId를 통해 Member 객체를 찾아오는 로직이 있습니다.
이를 위해서는 memberService.join()을 통해 먼저 member 객체를 회원가입(저장) 해주셔야 합니다 🙂
감사합니다.
감사합니다