Skip to content

Commit

Permalink
[REFACTOR] Test 클래스 리팩토링
Browse files Browse the repository at this point in the history
- 와일드 카드 static import 제거
- Parameterized 전환
- DisplayName 지정
  • Loading branch information
yummygyudon committed Dec 10, 2024
1 parent 4f4d7d2 commit f7b4b4a
Showing 1 changed file with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sopt.makers.authentication.usecase.auth.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -12,8 +11,13 @@
import sopt.makers.authentication.usecase.auth.port.in.GetSocialAccountUsecase;
import sopt.makers.authentication.usecase.auth.port.out.UserRepository;

import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand All @@ -24,6 +28,8 @@
@ActiveProfiles("local")
@TestPropertySource(locations = {"classpath:env/local.env"})
class GetSocialAccountPlatformServiceTest {
private static final String PLATFORM_NAME_GOOGLE = "GOOGLE";
private static final String PLATFORM_NAME_APPLE = "APPLE";
private static final String TEST_AUTH_ID = "test";
private static final String TEST_USER_PHONE_FOR_GOOGLE = "01012345678";
private static final String TEST_USER_PHONE_FOR_APPLE = "01087654321";
Expand Down Expand Up @@ -51,24 +57,29 @@ void setMockUser() {
when(userRepository.findByPhone(TEST_USER_PHONE_FOR_APPLE)).thenReturn(mockedUserForApple);
}

@Test
void 주어진_Command에_대해_의도한_결과값을_반환한다() {
// given
GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommandForGoogle =
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
null, TEST_USER_PHONE_FOR_GOOGLE);
GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommandForApple =
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
null, TEST_USER_PHONE_FOR_APPLE);

@ParameterizedTest(name = "({index}) command : {0} -> result : {1}")
@DisplayName("주어진 Command에 대해 의도한 결과값을 반환한다")
@MethodSource("argsForGetPlatformInfoTest")
void 주어진_Command에_대해_의도한_결과값을_반환한다(
// given
GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommand, String expectedResult) {
// when
GetSocialAccountUsecase.SocialAccountPlatformInfo resultForGoogle =
getSocialAccountPlatformService.getSocialAccountPlatform(givenCommandForGoogle);
GetSocialAccountUsecase.SocialAccountPlatformInfo resultForApple =
getSocialAccountPlatformService.getSocialAccountPlatform(givenCommandForApple);
GetSocialAccountUsecase.SocialAccountPlatformInfo result =
getSocialAccountPlatformService.getSocialAccountPlatform(givenCommand);

// then
assertThat(resultForGoogle.platformName()).isEqualTo("GOOGLE");
assertThat(resultForApple.platformName()).isEqualTo("APPLE");
assertThat(result.platformName()).isEqualTo(expectedResult);
}

static Stream<Arguments> argsForGetPlatformInfoTest() {
return Stream.of(
Arguments.of(
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
null, TEST_USER_PHONE_FOR_GOOGLE),
PLATFORM_NAME_GOOGLE),
Arguments.of(
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
null, TEST_USER_PHONE_FOR_APPLE),
PLATFORM_NAME_APPLE));
}
}

0 comments on commit f7b4b4a

Please sign in to comment.