From 5e7454b18d1314b79d22ed4e609777e2f77a3274 Mon Sep 17 00:00:00 2001 From: na0th <105775683+na0th@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:24:31 +0900 Subject: [PATCH] =?UTF-8?q?Test=20:=20=EC=84=B8=EC=85=98=EC=97=90=20?= =?UTF-8?q?=EA=B0=92=20=EC=9E=84=EC=8B=9C=20=EC=A0=80=EC=9E=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -추가된 내용 : 1. 세션에 orderId, amount 값을 임시 저장한 것이 제대로 저장되었는지 테스트 이유 : 결제 최종 승인 요청 전에 값이 변조되지 않았는지 검증하기 위함 미흡 : 결제 요청 받았을 때, 세션에 값이 저장되지 않았을 경우에 대한 예외 처리 미완 --- .../repository/PaymentRepositoryTest.java | 4 ++ .../service/PaymentServiceImplTest.java | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/test/java/com/tasksprints/auction/domain/payment/repository/PaymentRepositoryTest.java create mode 100644 src/test/java/com/tasksprints/auction/domain/payment/service/PaymentServiceImplTest.java diff --git a/src/test/java/com/tasksprints/auction/domain/payment/repository/PaymentRepositoryTest.java b/src/test/java/com/tasksprints/auction/domain/payment/repository/PaymentRepositoryTest.java new file mode 100644 index 0000000..e94f6a9 --- /dev/null +++ b/src/test/java/com/tasksprints/auction/domain/payment/repository/PaymentRepositoryTest.java @@ -0,0 +1,4 @@ +package com.tasksprints.auction.domain.payment.repository; + +public class PaymentRepositoryTest { +} diff --git a/src/test/java/com/tasksprints/auction/domain/payment/service/PaymentServiceImplTest.java b/src/test/java/com/tasksprints/auction/domain/payment/service/PaymentServiceImplTest.java new file mode 100644 index 0000000..fa13c0d --- /dev/null +++ b/src/test/java/com/tasksprints/auction/domain/payment/service/PaymentServiceImplTest.java @@ -0,0 +1,58 @@ +package com.tasksprints.auction.domain.payment.service; + +import com.tasksprints.auction.domain.payment.dto.request.PaymentRequest; +import jakarta.servlet.http.HttpSession; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class PaymentServiceImplTest { + @InjectMocks + private PaymentServiceImpl paymentService; + + @Mock + private HttpSession session; + + @Nested + @DisplayName("결제 전 세션 임시 저장 테스트") + class 임시_저장_테스트{ + @Test + void 결제_요청을_받았을_때_세션에_값이_저장되면_성공한다 () { + //given + String orderId = "testOrderId"; + BigDecimal amount = BigDecimal.valueOf(1000.00); + PaymentRequest.Prepare prepareRequest = new PaymentRequest.Prepare(orderId, amount); + + when(session.getAttribute("orderId")).thenReturn(orderId); + when(session.getAttribute("amount")).thenReturn(amount); + //when + paymentService.prepare(session, prepareRequest); + //then + verify(session).setAttribute("orderId", orderId); + verify(session).setAttribute("amount", amount); + + assertThat(orderId).isEqualTo(session.getAttribute("orderId")); + assertThat(amount).isEqualTo(session.getAttribute("amount")); + } + @Test + void 결제_요청을_받았을_때_세션에_값이_저장되지_않으면_예외_처리 () { + //given + //when + //then + } + } +}