From 3b6dc092e02430f010c7219a51f872155fbd8b40 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Sun, 31 Mar 2024 18:30:55 +0900 Subject: [PATCH] =?UTF-8?q?test=20:=20=ED=86=A0=ED=81=B0=20=EC=9D=B8?= =?UTF-8?q?=EA=B0=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=20LectureRepos?= =?UTF-8?q?itory=20Mocking=20=EC=B6=94=EA=B0=80=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binaryho/imhere/security/SecurityConfigTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/gdsc/binaryho/imhere/security/SecurityConfigTest.java b/src/test/java/gdsc/binaryho/imhere/security/SecurityConfigTest.java index 96b98f7..eebb047 100644 --- a/src/test/java/gdsc/binaryho/imhere/security/SecurityConfigTest.java +++ b/src/test/java/gdsc/binaryho/imhere/security/SecurityConfigTest.java @@ -10,11 +10,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import gdsc.binaryho.imhere.core.lecture.infrastructure.LectureRepository; import gdsc.binaryho.imhere.core.member.Role; import gdsc.binaryho.imhere.core.member.infrastructure.MemberRepository; import gdsc.binaryho.imhere.security.jwt.Token; import gdsc.binaryho.imhere.security.jwt.TokenPropertyHolder; import gdsc.binaryho.imhere.security.jwt.TokenUtil; +import java.util.Collections; import java.util.Optional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -35,11 +37,14 @@ public class SecurityConfigTest { @Autowired private TokenUtil tokenUtil; + @Autowired + private TokenPropertyHolder tokenPropertyHolder; + @MockBean private MemberRepository memberRepository; - @Autowired - private TokenPropertyHolder tokenPropertyHolder; + @MockBean + private LectureRepository lectureRepository; @Test public void 인증이_필요한_경로에_접근하면_깃허브_로그인_페이지로_Redirection_된다() throws Exception { @@ -54,6 +59,9 @@ public class SecurityConfigTest { public void 토큰을_통해_인가_할_수_있다() throws Exception { given(memberRepository.findById(any())) .willReturn(Optional.of(MOCK_LECTURER)); + given(lectureRepository.findAllByLectureStateNot(any())) + .willReturn(Collections.emptyList()); + String prefix = tokenPropertyHolder.getAccessTokenPrefix(); Token token = tokenUtil.createToken(MOCK_LECTURER.getId(), Role.LECTURER);