diff --git a/src/test/java/com/ajou/hertz/config/TestSecurityConfig.java b/src/test/java/com/ajou/hertz/config/TestSecurityConfig.java index e9acd79..38f2f10 100644 --- a/src/test/java/com/ajou/hertz/config/TestSecurityConfig.java +++ b/src/test/java/com/ajou/hertz/config/TestSecurityConfig.java @@ -2,7 +2,6 @@ import static org.mockito.BDDMockito.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Set; @@ -23,6 +22,7 @@ import com.ajou.hertz.domain.user.constant.RoleType; import com.ajou.hertz.domain.user.dto.UserDto; import com.ajou.hertz.domain.user.service.UserQueryService; +import com.ajou.hertz.util.ReflectionUtils; @Import({ SecurityConfig.class, @@ -45,13 +45,7 @@ public void securitySetUp() throws Exception { } private UserDto createUserDto() throws Exception { - Constructor userResponseConstructor = UserDto.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class, - LocalDateTime.class - ); - userResponseConstructor.setAccessible(true); - return userResponseConstructor.newInstance( + return ReflectionUtils.createUserDto( 1L, Set.of(RoleType.USER), "test@mail.com", diff --git a/src/test/java/com/ajou/hertz/integration/domain/instrument/repository/InstrumentRepositoryTest.java b/src/test/java/com/ajou/hertz/integration/domain/instrument/repository/InstrumentRepositoryTest.java index 65e6cbf..f852697 100644 --- a/src/test/java/com/ajou/hertz/integration/domain/instrument/repository/InstrumentRepositoryTest.java +++ b/src/test/java/com/ajou/hertz/integration/domain/instrument/repository/InstrumentRepositoryTest.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.util.List; import java.util.Set; @@ -49,6 +48,7 @@ import com.ajou.hertz.domain.user.constant.RoleType; import com.ajou.hertz.domain.user.entity.User; import com.ajou.hertz.domain.user.repository.UserRepository; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Integration] Repository - Instrument") @ActiveProfiles("test") @@ -73,7 +73,7 @@ public InstrumentRepositoryTest( // given InstrumentSortOption sortOption = InstrumentSortOption.CREATED_BY_DESC; InstrumentFilterConditions filterConditions = - createInstrumentFilterConditions(InstrumentProgressStatus.SELLING); + createEmptyInstrumentFilterConditions(InstrumentProgressStatus.SELLING); User user = userRepository.save(createUser()); List savedInstruments = sut.saveAll(List.of( createBassGuitar(user), @@ -92,7 +92,7 @@ public InstrumentRepositoryTest( void 베이스_기타_목록을_조회한다() throws Exception { // given InstrumentSortOption sortOption = InstrumentSortOption.CREATED_BY_DESC; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); User user = userRepository.save(createUser()); List savedInstruments = sut.saveAll(List.of( createElectricGuitar(user), @@ -111,7 +111,7 @@ public InstrumentRepositoryTest( void 어쿠스틱_클래식_기타_목록을_조회한다() throws Exception { // given InstrumentSortOption sortOption = InstrumentSortOption.CREATED_BY_DESC; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); User user = userRepository.save(createUser()); List savedInstruments = sut.saveAll(List.of( createElectricGuitar(user), @@ -132,7 +132,7 @@ public InstrumentRepositoryTest( void 이펙터_목록을_조회한다() throws Exception { // given InstrumentSortOption sortOption = InstrumentSortOption.CREATED_BY_DESC; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); User user = userRepository.save(createUser()); List savedInstruments = sut.saveAll(List.of( createElectricGuitar(user), @@ -151,7 +151,7 @@ public InstrumentRepositoryTest( void 앰프_목록을_조회한다() throws Exception { // given InstrumentSortOption sortOption = InstrumentSortOption.CREATED_BY_DESC; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); User user = userRepository.save(createUser()); List savedInstruments = sut.saveAll(List.of( createElectricGuitar(user), @@ -170,7 +170,7 @@ public InstrumentRepositoryTest( void 음향_장비_목록을_조회한다() throws Exception { // given InstrumentSortOption sortOption = InstrumentSortOption.CREATED_BY_ASC; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); User user = userRepository.save(createUser()); List savedInstruments = sut.saveAll(List.of( createElectricGuitar(user), @@ -190,12 +190,7 @@ private Address createAddress() { } private User createUser() throws Exception { - Constructor userConstructor = User.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class - ); - userConstructor.setAccessible(true); - return userConstructor.newInstance( + return ReflectionUtils.createUser( null, Set.of(RoleType.USER), "test@mail.com", @@ -210,13 +205,7 @@ private User createUser() throws Exception { } private ElectricGuitar createElectricGuitar(User seller) throws Exception { - Constructor electricGuitarConstructor = ElectricGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, Short.class, - Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, ElectricGuitarModel.class, - Short.class, GuitarColor.class - ); - electricGuitarConstructor.setAccessible(true); - return electricGuitarConstructor.newInstance( + return ReflectionUtils.createElectricGuitar( null, seller, "Test electric guitar", @@ -234,13 +223,7 @@ private ElectricGuitar createElectricGuitar(User seller) throws Exception { } private BassGuitar createBassGuitar(User seller) throws Exception { - Constructor bassGuitarConstructor = BassGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class - ); - bassGuitarConstructor.setAccessible(true); - return bassGuitarConstructor.newInstance( + return ReflectionUtils.createBassGuitar( null, seller, "Test electric guitar", @@ -258,15 +241,7 @@ private BassGuitar createBassGuitar(User seller) throws Exception { } private AcousticAndClassicGuitar createAcousticAndClassicGuitar(User seller) throws Exception { - Constructor acousticAndClassicGuitarConstructor = - AcousticAndClassicGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, - AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class - ); - acousticAndClassicGuitarConstructor.setAccessible(true); - return acousticAndClassicGuitarConstructor.newInstance( + return ReflectionUtils.createAcousticAndClassicGuitar( null, seller, "Test electric guitar", @@ -284,13 +259,7 @@ private AcousticAndClassicGuitar createAcousticAndClassicGuitar(User seller) thr } private Effector createEffector(User seller) throws Exception { - Constructor effectorConstructor = Effector.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - EffectorType.class, EffectorFeature.class - ); - effectorConstructor.setAccessible(true); - return effectorConstructor.newInstance( + return ReflectionUtils.createEffector( null, seller, "Title", @@ -306,13 +275,7 @@ private Effector createEffector(User seller) throws Exception { } private Amplifier createAmplifier(User seller) throws Exception { - Constructor amplifierConstructor = Amplifier.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class - ); - amplifierConstructor.setAccessible(true); - return amplifierConstructor.newInstance( + return ReflectionUtils.createAmplifier( null, seller, "Title", @@ -329,13 +292,7 @@ private Amplifier createAmplifier(User seller) throws Exception { } private AudioEquipment createAudioEquipment(User seller) throws Exception { - Constructor audioEquipmentConstructor = AudioEquipment.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AudioEquipmentType.class - ); - audioEquipmentConstructor.setAccessible(true); - return audioEquipmentConstructor.newInstance( + return ReflectionUtils.createAudioEquipment( null, seller, "Title", @@ -349,18 +306,13 @@ private AudioEquipment createAudioEquipment(User seller) throws Exception { ); } - private InstrumentFilterConditions createInstrumentFilterConditions() throws Exception { - Constructor instrumentFilterConditionsConstructor = - InstrumentFilterConditions.class.getDeclaredConstructor(); - instrumentFilterConditionsConstructor.setAccessible(true); - return instrumentFilterConditionsConstructor.newInstance(); + private InstrumentFilterConditions createEmptyInstrumentFilterConditions() throws Exception { + return ReflectionUtils.createInstrumentFilterConditions(null); } - private InstrumentFilterConditions createInstrumentFilterConditions(InstrumentProgressStatus progressStatus) throws - Exception { - Constructor instrumentFilterConditionsConstructor = - InstrumentFilterConditions.class.getDeclaredConstructor(InstrumentProgressStatus.class); - instrumentFilterConditionsConstructor.setAccessible(true); - return instrumentFilterConditionsConstructor.newInstance(progressStatus); + private InstrumentFilterConditions createEmptyInstrumentFilterConditions( + InstrumentProgressStatus progressStatus + ) throws Exception { + return ReflectionUtils.createInstrumentFilterConditions(progressStatus); } } diff --git a/src/test/java/com/ajou/hertz/unit/common/auth/controller/AuthControllerTest.java b/src/test/java/com/ajou/hertz/unit/common/auth/controller/AuthControllerTest.java index 54bbff6..36bfdf0 100644 --- a/src/test/java/com/ajou/hertz/unit/common/auth/controller/AuthControllerTest.java +++ b/src/test/java/com/ajou/hertz/unit/common/auth/controller/AuthControllerTest.java @@ -5,7 +5,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import java.lang.reflect.Constructor; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayName; @@ -24,6 +23,7 @@ import com.ajou.hertz.common.auth.service.AuthService; import com.ajou.hertz.common.kakao.service.KakaoService; import com.ajou.hertz.config.ControllerTestConfig; +import com.ajou.hertz.util.ReflectionUtils; import com.fasterxml.jackson.databind.ObjectMapper; @DisplayName("[Unit] Controller - Auth") @@ -93,23 +93,11 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() { } private LoginRequest createLoginRequest() throws Exception { - Constructor loginRequestConstructor = - LoginRequest.class.getDeclaredConstructor(String.class, String.class); - loginRequestConstructor.setAccessible(true); - return loginRequestConstructor.newInstance( - "test@mail.com", - "1q2w3e4r!" - ); + return ReflectionUtils.createLoginRequest("test@mail.com", "1q2w3e4r!"); } private static KakaoLoginRequest createKakaoLoginRequest() throws Exception { - Constructor kakaoLoginRequestConstructor = - KakaoLoginRequest.class.getDeclaredConstructor(String.class, String.class); - kakaoLoginRequestConstructor.setAccessible(true); - return kakaoLoginRequestConstructor.newInstance( - "authorization-code", - "https://redirect-uri" - ); + return ReflectionUtils.createKakaoLoginRequest("authorization-code", "https://redirect-uri"); } private JwtTokenInfoDto createJwtTokenInfoDto() { diff --git a/src/test/java/com/ajou/hertz/unit/common/auth/service/AuthServiceTest.java b/src/test/java/com/ajou/hertz/unit/common/auth/service/AuthServiceTest.java index 8e82afd..d45947a 100644 --- a/src/test/java/com/ajou/hertz/unit/common/auth/service/AuthServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/common/auth/service/AuthServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Set; @@ -25,6 +24,7 @@ import com.ajou.hertz.domain.user.constant.RoleType; import com.ajou.hertz.domain.user.dto.UserDto; import com.ajou.hertz.domain.user.service.UserQueryService; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Service - Auth") @ExtendWith(MockitoExtension.class) @@ -90,13 +90,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() { } private LoginRequest createLoginRequest() throws Exception { - Constructor loginRequestConstructor = - LoginRequest.class.getDeclaredConstructor(String.class, String.class); - loginRequestConstructor.setAccessible(true); - return loginRequestConstructor.newInstance( - "test@mail.com", - "encoded-password" - ); + return ReflectionUtils.createLoginRequest("test@mail.com", "encoded-password"); } private JwtTokenInfoDto createJwtTokenInfoDto() { @@ -107,13 +101,7 @@ private JwtTokenInfoDto createJwtTokenInfoDto() { } private UserDto createUserDto(long id) throws Exception { - Constructor userResponseConstructor = UserDto.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class, - LocalDateTime.class - ); - userResponseConstructor.setAccessible(true); - return userResponseConstructor.newInstance( + return ReflectionUtils.createUserDto( id, Set.of(RoleType.USER), "test@mail.com", diff --git a/src/test/java/com/ajou/hertz/unit/common/kakao/service/KakaoServiceTest.java b/src/test/java/com/ajou/hertz/unit/common/kakao/service/KakaoServiceTest.java index 33c9d92..f9d98c6 100644 --- a/src/test/java/com/ajou/hertz/unit/common/kakao/service/KakaoServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/common/kakao/service/KakaoServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Optional; @@ -32,6 +31,7 @@ import com.ajou.hertz.domain.user.dto.UserDto; import com.ajou.hertz.domain.user.service.UserCommandService; import com.ajou.hertz.domain.user.service.UserQueryService; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Service - Kakao") @ExtendWith(MockitoExtension.class) @@ -138,13 +138,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() { } private UserDto createUserDto(long id) throws Exception { - Constructor userResponseConstructor = UserDto.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class, - LocalDateTime.class - ); - userResponseConstructor.setAccessible(true); - return userResponseConstructor.newInstance( + return ReflectionUtils.createUserDto( id, Set.of(RoleType.USER), "test@mail.com", @@ -164,21 +158,14 @@ private UserDto createUserDto() throws Exception { } private static KakaoLoginRequest createKakaoLoginRequest() throws Exception { - Constructor kakaoLoginRequestConstructor = - KakaoLoginRequest.class.getDeclaredConstructor(String.class, String.class); - kakaoLoginRequestConstructor.setAccessible(true); - return kakaoLoginRequestConstructor.newInstance( + return ReflectionUtils.createKakaoLoginRequest( "authorization-code", "https://redirect-uri" ); } private static KakaoTokenResponse createKakaoTokenResponse() throws Exception { - Constructor kakaoTokenResponseConstructor = KakaoTokenResponse.class.getDeclaredConstructor( - String.class, String.class, Integer.class, String.class, Integer.class - ); - kakaoTokenResponseConstructor.setAccessible(true); - return kakaoTokenResponseConstructor.newInstance("bearer", "access-token", 43199, "refresh-token", 5184000); + return ReflectionUtils.createKakaoTokenResponse("bearer", "access-token", 43199, "refresh-token", 5184000); } private static KakaoUserInfoResponse createKakaoUserInfoResponse() { diff --git a/src/test/java/com/ajou/hertz/unit/domain/administrative_area/controller/AdministrativeAreaControllerTest.java b/src/test/java/com/ajou/hertz/unit/domain/administrative_area/controller/AdministrativeAreaControllerTest.java index ce91061..9a4ff48 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/administrative_area/controller/AdministrativeAreaControllerTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/administrative_area/controller/AdministrativeAreaControllerTest.java @@ -6,7 +6,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import java.lang.reflect.Constructor; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -25,6 +24,7 @@ import com.ajou.hertz.domain.administrative_area.repository.AdministrativeEmdRepository; import com.ajou.hertz.domain.administrative_area.repository.AdministrativeSggRepository; import com.ajou.hertz.domain.administrative_area.repository.AdministrativeSidoRepository; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Controller - AdministrativeArea") @Import(ControllerTestConfig.class) @@ -119,28 +119,15 @@ public class AdministrativeAreaControllerTest { } private AdministrativeAreaSido createSido(long id, String name) throws Exception { - Constructor sidoConstructor = AdministrativeAreaSido.class.getDeclaredConstructor( - Long.class, String.class - ); - sidoConstructor.setAccessible(true); - return sidoConstructor.newInstance(id, name); + return ReflectionUtils.createSido(id, name); } - private AdministrativeAreaSgg createSgg(long id, AdministrativeAreaSido sido, String name) throws - Exception { - Constructor sidoConstructor = AdministrativeAreaSgg.class.getDeclaredConstructor( - Long.class, AdministrativeAreaSido.class, String.class - ); - sidoConstructor.setAccessible(true); - return sidoConstructor.newInstance(id, sido, name); + private AdministrativeAreaSgg createSgg(long id, AdministrativeAreaSido sido, String name) throws Exception { + return ReflectionUtils.createSgg(id, sido, name); } private AdministrativeAreaEmd createEmd(long id, AdministrativeAreaSgg sgg, String name) throws Exception { - Constructor sidoConstructor = AdministrativeAreaEmd.class.getDeclaredConstructor( - Long.class, AdministrativeAreaSgg.class, String.class - ); - sidoConstructor.setAccessible(true); - return sidoConstructor.newInstance(id, sgg, name); + return ReflectionUtils.createEmd(id, sgg, name); } private void verifyEveryMocksShouldHaveNoMoreInteractions() { diff --git a/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java b/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java index 1e784ca..c2eded0 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java @@ -7,7 +7,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; @@ -69,6 +68,7 @@ import com.ajou.hertz.domain.user.constant.Gender; import com.ajou.hertz.domain.user.constant.RoleType; import com.ajou.hertz.domain.user.dto.UserDto; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Controller - Instrument") @Import(ControllerTestConfig.class) @@ -623,13 +623,7 @@ private MockMultipartFile createMultipartFile() { } private UserDto createUserDto(long id) throws Exception { - Constructor userResponseConstructor = UserDto.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class, - LocalDateTime.class - ); - userResponseConstructor.setAccessible(true); - return userResponseConstructor.newInstance( + return ReflectionUtils.createUserDto( id, Set.of(RoleType.USER), "test@mail.com", @@ -645,19 +639,11 @@ private UserDto createUserDto(long id) throws Exception { } private AddressDto createAddressDto() throws Exception { - Constructor addressDtoConstructor = AddressDto.class.getDeclaredConstructor( - String.class, String.class, String.class - ); - addressDtoConstructor.setAccessible(true); - return addressDtoConstructor.newInstance("서울특별시", "강남구", "청담동"); + return ReflectionUtils.createAddressDto("서울특별시", "강남구", "청담동"); } private InstrumentImageDto createInstrumentImageDto(long instrumentImageId) throws Exception { - Constructor instrumentImageDtoConstructor = InstrumentImageDto.class.getDeclaredConstructor( - Long.class, String.class, String.class - ); - instrumentImageDtoConstructor.setAccessible(true); - return instrumentImageDtoConstructor.newInstance( + return ReflectionUtils.createInstrumentImageDto( instrumentImageId, "image-name", "https://instrument-image-url" @@ -665,13 +651,7 @@ private InstrumentImageDto createInstrumentImageDto(long instrumentImageId) thro } private ElectricGuitarDto createElectricGuitarDto(long id, long sellerId) throws Exception { - Constructor electricGuitarDtoConstructor = ElectricGuitarDto.class.getDeclaredConstructor( - Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, - Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, ElectricGuitarModel.class, - Short.class, GuitarColor.class, List.class, List.class - ); - electricGuitarDtoConstructor.setAccessible(true); - return electricGuitarDtoConstructor.newInstance( + return ReflectionUtils.createElectricGuitarDto( id, createUserDto(sellerId), "Test electric guitar", @@ -681,28 +661,22 @@ private ElectricGuitarDto createElectricGuitarDto(long id, long sellerId) throws 550000, true, "description", - ElectricGuitarBrand.FENDER_USA, - ElectricGuitarModel.TELECASTER, - (short)2014, - GuitarColor.RED, List.of( createInstrumentImageDto(id + 1), createInstrumentImageDto(id + 2), createInstrumentImageDto(id + 3), createInstrumentImageDto(id + 4) ), - List.of() + List.of(), + ElectricGuitarBrand.FENDER_USA, + ElectricGuitarModel.TELECASTER, + (short)2014, + GuitarColor.RED ); } private BassGuitarDto createBassGuitarDto(long id, long sellerId) throws Exception { - Constructor bassGuitarDtoConstructor = BassGuitarDto.class.getDeclaredConstructor( - Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class - ); - bassGuitarDtoConstructor.setAccessible(true); - return bassGuitarDtoConstructor.newInstance( + return ReflectionUtils.createBassGuitarDto( id, createUserDto(sellerId), "Test electric guitar", @@ -727,15 +701,7 @@ private BassGuitarDto createBassGuitarDto(long id, long sellerId) throws Excepti } private AcousticAndClassicGuitarDto createAcousticAndClassicGuitarDto(long id, long sellerId) throws Exception { - Constructor acousticAndClassicGuitarDtoConstructor = - AcousticAndClassicGuitarDto.class.getDeclaredConstructor( - Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, - AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class - ); - acousticAndClassicGuitarDtoConstructor.setAccessible(true); - return acousticAndClassicGuitarDtoConstructor.newInstance( + return ReflectionUtils.createAcousticAndClassicGuitarDto( id, createUserDto(sellerId), "Test electric guitar", @@ -760,13 +726,7 @@ private AcousticAndClassicGuitarDto createAcousticAndClassicGuitarDto(long id, l } private EffectorDto createEffectorDto(long id, long sellerId) throws Exception { - Constructor effectorDtoConstructor = EffectorDto.class.getDeclaredConstructor( - Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - EffectorType.class, EffectorFeature.class - ); - effectorDtoConstructor.setAccessible(true); - return effectorDtoConstructor.newInstance( + return ReflectionUtils.createEffectorDto( id, createUserDto(sellerId), "Test electric guitar", @@ -789,13 +749,7 @@ private EffectorDto createEffectorDto(long id, long sellerId) throws Exception { } private AmplifierDto createAmplifierDto(long id, long sellerId) throws Exception { - Constructor amplifierDtoConstructor = AmplifierDto.class.getDeclaredConstructor( - Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class - ); - amplifierDtoConstructor.setAccessible(true); - return amplifierDtoConstructor.newInstance( + return ReflectionUtils.createAmplifierDto( id, createUserDto(sellerId), "Test electric guitar", @@ -819,13 +773,7 @@ private AmplifierDto createAmplifierDto(long id, long sellerId) throws Exception } private AudioEquipmentDto createAudioEquipmentDto(long id, long sellerId) throws Exception { - Constructor audioEquipmentDtoConstructor = AudioEquipmentDto.class.getDeclaredConstructor( - Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AudioEquipmentType.class - ); - audioEquipmentDtoConstructor.setAccessible(true); - return audioEquipmentDtoConstructor.newInstance( + return ReflectionUtils.createAudioEquipmentDto( id, createUserDto(sellerId), "Test electric guitar", @@ -847,47 +795,29 @@ private AudioEquipmentDto createAudioEquipmentDto(long id, long sellerId) throws } private AddressRequest createAddressRequest() throws Exception { - Constructor addressRequestConstructor = AddressRequest.class.getDeclaredConstructor( - String.class, String.class, String.class - ); - addressRequestConstructor.setAccessible(true); - return addressRequestConstructor.newInstance("서울특별시", "강남구", "청담동"); + return ReflectionUtils.createAddressRequest("서울특별시", "강남구", "청담동"); } private CreateNewElectricGuitarRequest createElectricGuitarRequest() throws Exception { - Constructor createNewElectricGuitarRequestConstructor = - CreateNewElectricGuitarRequest.class.getDeclaredConstructor( - String.class, List.class, InstrumentProgressStatus.class, AddressRequest.class, - Short.class, Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, - ElectricGuitarModel.class, Short.class, GuitarColor.class, List.class - ); - createNewElectricGuitarRequestConstructor.setAccessible(true); - return createNewElectricGuitarRequestConstructor.newInstance( + return ReflectionUtils.createElectricGuitarRequest( "Test electric guitar", - List.of(createMultipartFile(), createMultipartFile(), createMultipartFile(), createMultipartFile()), InstrumentProgressStatus.SELLING, createAddressRequest(), (short)3, 550000, true, "description", + List.of(createMultipartFile(), createMultipartFile(), createMultipartFile(), createMultipartFile()), + List.of("Fender", "Guitar"), ElectricGuitarBrand.FENDER_USA, ElectricGuitarModel.TELECASTER, (short)2014, - GuitarColor.RED, - List.of("Fender", "Guitar") + GuitarColor.RED ); } private CreateNewBassGuitarRequest createNewBassGuitarRequest() throws Exception { - Constructor createNewBassGuitarRequestConstructor = - CreateNewBassGuitarRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class - ); - createNewBassGuitarRequestConstructor.setAccessible(true); - return createNewBassGuitarRequestConstructor.newInstance( + return ReflectionUtils.createNewBassGuitarRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -905,15 +835,7 @@ private CreateNewBassGuitarRequest createNewBassGuitarRequest() throws Exception } private CreateNewAcousticAndClassicGuitarRequest createAcousticAndClassicGuitarRequest() throws Exception { - Constructor createNewAcousticAndClassicGuitarRequestConstructor = - CreateNewAcousticAndClassicGuitarRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, - AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class - ); - createNewAcousticAndClassicGuitarRequestConstructor.setAccessible(true); - return createNewAcousticAndClassicGuitarRequestConstructor.newInstance( + return ReflectionUtils.createAcousticAndClassicGuitarRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -931,14 +853,7 @@ private CreateNewAcousticAndClassicGuitarRequest createAcousticAndClassicGuitarR } private CreateNewEffectorRequest createEffectorRequest() throws Exception { - Constructor createNewEffectorRequestConstructor = - CreateNewEffectorRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - EffectorType.class, EffectorFeature.class - ); - createNewEffectorRequestConstructor.setAccessible(true); - return createNewEffectorRequestConstructor.newInstance( + return ReflectionUtils.createEffectorRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -954,14 +869,7 @@ private CreateNewEffectorRequest createEffectorRequest() throws Exception { } private CreateNewAmplifierRequest createAmplifierRequest() throws Exception { - Constructor createNewAmplifierRequestConstructor = - CreateNewAmplifierRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class - ); - createNewAmplifierRequestConstructor.setAccessible(true); - return createNewAmplifierRequestConstructor.newInstance( + return ReflectionUtils.createAmplifierRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -978,14 +886,7 @@ private CreateNewAmplifierRequest createAmplifierRequest() throws Exception { } private CreateNewAudioEquipmentRequest createAudioEquipmentRequest() throws Exception { - Constructor createNewAudioEquipmentRequestConstructor = - CreateNewAudioEquipmentRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AudioEquipmentType.class - ); - createNewAudioEquipmentRequestConstructor.setAccessible(true); - return createNewAudioEquipmentRequestConstructor.newInstance( + return ReflectionUtils.createAudioEquipmentRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -1000,11 +901,6 @@ private CreateNewAudioEquipmentRequest createAudioEquipmentRequest() throws Exce } private InstrumentFilterConditions createInstrumentFilterConditions() throws Exception { - Constructor instrumentFilterConditionsConstructor = - InstrumentFilterConditions.class.getDeclaredConstructor(InstrumentProgressStatus.class); - instrumentFilterConditionsConstructor.setAccessible(true); - return instrumentFilterConditionsConstructor.newInstance( - InstrumentProgressStatus.SELLING - ); + return ReflectionUtils.createInstrumentFilterConditions(InstrumentProgressStatus.SELLING); } } diff --git a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java index d028605..21114d5 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.util.List; import java.util.Set; @@ -68,6 +67,7 @@ import com.ajou.hertz.domain.user.constant.RoleType; import com.ajou.hertz.domain.user.entity.User; import com.ajou.hertz.domain.user.service.UserQueryService; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Service(Command) - Instrument") @ExtendWith(MockitoExtension.class) @@ -321,12 +321,7 @@ private MockMultipartFile createMultipartFile() { } private User createUser(Long id) throws Exception { - Constructor userConstructor = User.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class - ); - userConstructor.setAccessible(true); - return userConstructor.newInstance( + return ReflectionUtils.createUser( id, Set.of(RoleType.USER), "test@mail.com", @@ -345,11 +340,7 @@ private Address createAddress() { } private InstrumentImage createInstrumentImage(Long id, Instrument instrument) throws Exception { - Constructor instrumentImageConstructor = InstrumentImage.class.getDeclaredConstructor( - Long.class, Instrument.class, String.class, String.class, String.class - ); - instrumentImageConstructor.setAccessible(true); - return instrumentImageConstructor.newInstance( + return ReflectionUtils.createInstrumentImage( id, instrument, "original-name", @@ -359,21 +350,11 @@ private InstrumentImage createInstrumentImage(Long id, Instrument instrument) th } private InstrumentHashtag createInstrumentHashtag(Long id, Instrument instrument) throws Exception { - Constructor instrumentHashtagConstructor = InstrumentHashtag.class.getDeclaredConstructor( - Long.class, Instrument.class, String.class - ); - instrumentHashtagConstructor.setAccessible(true); - return instrumentHashtagConstructor.newInstance(id, instrument, "content"); + return ReflectionUtils.createInstrumentHashtag(id, instrument, "content"); } private ElectricGuitar createElectricGuitar(Long id, User seller) throws Exception { - Constructor electricGuitarConstructor = ElectricGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, Short.class, - Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, ElectricGuitarModel.class, - Short.class, GuitarColor.class - ); - electricGuitarConstructor.setAccessible(true); - return electricGuitarConstructor.newInstance( + return ReflectionUtils.createElectricGuitar( id, seller, "Test electric guitar", @@ -391,13 +372,7 @@ private ElectricGuitar createElectricGuitar(Long id, User seller) throws Excepti } private BassGuitar createBassGuitar(long id, User seller) throws Exception { - Constructor bassGuitarConstructor = BassGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class - ); - bassGuitarConstructor.setAccessible(true); - return bassGuitarConstructor.newInstance( + return ReflectionUtils.createBassGuitar( id, seller, "Test electric guitar", @@ -415,15 +390,7 @@ private BassGuitar createBassGuitar(long id, User seller) throws Exception { } private AcousticAndClassicGuitar createAcousticAndClassicGuitar(long id, User seller) throws Exception { - Constructor acousticAndClassicGuitarConstructor = - AcousticAndClassicGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, - AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class - ); - acousticAndClassicGuitarConstructor.setAccessible(true); - return acousticAndClassicGuitarConstructor.newInstance( + return ReflectionUtils.createAcousticAndClassicGuitar( id, seller, "Test electric guitar", @@ -441,13 +408,7 @@ private AcousticAndClassicGuitar createAcousticAndClassicGuitar(long id, User se } private Effector createEffector(long id, User seller) throws Exception { - Constructor effectorConstructor = Effector.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - EffectorType.class, EffectorFeature.class - ); - effectorConstructor.setAccessible(true); - return effectorConstructor.newInstance( + return ReflectionUtils.createEffector( id, seller, "Title", @@ -463,13 +424,7 @@ private Effector createEffector(long id, User seller) throws Exception { } private Amplifier createAmplifier(long id, User seller) throws Exception { - Constructor amplifierConstructor = Amplifier.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class - ); - amplifierConstructor.setAccessible(true); - return amplifierConstructor.newInstance( + return ReflectionUtils.createAmplifier( id, seller, "Title", @@ -486,13 +441,7 @@ private Amplifier createAmplifier(long id, User seller) throws Exception { } private AudioEquipment createAudioEquipment(long id, User seller) throws Exception { - Constructor audioEquipmentConstructor = AudioEquipment.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AudioEquipmentType.class - ); - audioEquipmentConstructor.setAccessible(true); - return audioEquipmentConstructor.newInstance( + return ReflectionUtils.createAudioEquipment( id, seller, "Title", @@ -507,55 +456,33 @@ private AudioEquipment createAudioEquipment(long id, User seller) throws Excepti } private FileDto createFileDto() throws Exception { - Constructor fileDtoConstructor = FileDto.class.getDeclaredConstructor( - String.class, String.class, String.class - ); - fileDtoConstructor.setAccessible(true); - return fileDtoConstructor.newInstance("original-name", "stored-name", "https://file-url"); + return ReflectionUtils.createFileDto("original-name", "stored-name", "https://file-url"); } private AddressRequest createAddressRequest() throws Exception { - Constructor addressRequestConstructor = AddressRequest.class.getDeclaredConstructor( - String.class, String.class, String.class - ); - addressRequestConstructor.setAccessible(true); - return addressRequestConstructor.newInstance("서울특별시", "강남구", "청담동"); + return ReflectionUtils.createAddressRequest("서울특별시", "강남구", "청담동"); } private CreateNewElectricGuitarRequest createElectricGuitarRequest() throws Exception { - Constructor createNewElectricGuitarRequestConstructor = - CreateNewElectricGuitarRequest.class.getDeclaredConstructor( - String.class, List.class, InstrumentProgressStatus.class, AddressRequest.class, - Short.class, Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, - ElectricGuitarModel.class, Short.class, GuitarColor.class, List.class - ); - createNewElectricGuitarRequestConstructor.setAccessible(true); - return createNewElectricGuitarRequestConstructor.newInstance( + return ReflectionUtils.createElectricGuitarRequest( "Title", - List.of(createMultipartFile()), InstrumentProgressStatus.SELLING, createAddressRequest(), (short)3, 550000, true, "description", + List.of(createMultipartFile()), + List.of("Fender", "Guitar"), ElectricGuitarBrand.FENDER_USA, ElectricGuitarModel.TELECASTER, (short)2014, - GuitarColor.RED, - List.of("Fender", "Guitar") + GuitarColor.RED ); } private CreateNewBassGuitarRequest createBassGuitarRequest() throws Exception { - Constructor createNewBassGuitarRequestConstructor = - CreateNewBassGuitarRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class - ); - createNewBassGuitarRequestConstructor.setAccessible(true); - return createNewBassGuitarRequestConstructor.newInstance( + return ReflectionUtils.createNewBassGuitarRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -573,15 +500,7 @@ private CreateNewBassGuitarRequest createBassGuitarRequest() throws Exception { } private CreateNewAcousticAndClassicGuitarRequest createAcousticAndClassicGuitarRequest() throws Exception { - Constructor createNewAcousticAndClassicGuitarRequestConstructor = - CreateNewAcousticAndClassicGuitarRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, - AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class - ); - createNewAcousticAndClassicGuitarRequestConstructor.setAccessible(true); - return createNewAcousticAndClassicGuitarRequestConstructor.newInstance( + return ReflectionUtils.createAcousticAndClassicGuitarRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -599,14 +518,7 @@ private CreateNewAcousticAndClassicGuitarRequest createAcousticAndClassicGuitarR } private CreateNewEffectorRequest createEffectorRequest() throws Exception { - Constructor createNewEffectorRequestConstructor = - CreateNewEffectorRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - EffectorType.class, EffectorFeature.class - ); - createNewEffectorRequestConstructor.setAccessible(true); - return createNewEffectorRequestConstructor.newInstance( + return ReflectionUtils.createEffectorRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -622,14 +534,7 @@ private CreateNewEffectorRequest createEffectorRequest() throws Exception { } private CreateNewAmplifierRequest createAmplifierRequest() throws Exception { - Constructor createNewAmplifierRequestConstructor = - CreateNewAmplifierRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class - ); - createNewAmplifierRequestConstructor.setAccessible(true); - return createNewAmplifierRequestConstructor.newInstance( + return ReflectionUtils.createAmplifierRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -646,14 +551,7 @@ private CreateNewAmplifierRequest createAmplifierRequest() throws Exception { } private CreateNewAudioEquipmentRequest createAudioEquipmentRequest() throws Exception { - Constructor createNewAudioEquipmentRequestConstructor = - CreateNewAudioEquipmentRequest.class.getDeclaredConstructor( - String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, - Integer.class, Boolean.class, String.class, List.class, List.class, - AudioEquipmentType.class - ); - createNewAudioEquipmentRequestConstructor.setAccessible(true); - return createNewAudioEquipmentRequestConstructor.newInstance( + return ReflectionUtils.createAudioEquipmentRequest( "Title", InstrumentProgressStatus.SELLING, createAddressRequest(), diff --git a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java index 477150b..6e927b3 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.util.List; import java.util.Set; @@ -58,6 +57,7 @@ import com.ajou.hertz.domain.user.constant.Gender; import com.ajou.hertz.domain.user.constant.RoleType; import com.ajou.hertz.domain.user.entity.User; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Service(Query) - Instrument") @ExtendWith(MockitoExtension.class) @@ -101,7 +101,7 @@ class InstrumentQueryServiceTest { // given int page = 0; int pageSize = 10; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); InstrumentSortOption sort = InstrumentSortOption.CREATED_BY_DESC; User user = createUser(); Page expectedResult = new PageImpl<>(List.of( @@ -130,7 +130,7 @@ class InstrumentQueryServiceTest { // given int page = 0; int pageSize = 10; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); InstrumentSortOption sort = InstrumentSortOption.CREATED_BY_DESC; User user = createUser(); Page expectedResult = new PageImpl<>(List.of( @@ -158,7 +158,7 @@ class InstrumentQueryServiceTest { // given int page = 0; int pageSize = 10; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); InstrumentSortOption sort = InstrumentSortOption.CREATED_BY_DESC; User user = createUser(); Page expectedResult = new PageImpl<>(List.of( @@ -188,7 +188,7 @@ class InstrumentQueryServiceTest { // given int page = 0; int pageSize = 10; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); InstrumentSortOption sort = InstrumentSortOption.CREATED_BY_DESC; User user = createUser(); Page expectedResult = new PageImpl<>(List.of( @@ -216,7 +216,7 @@ class InstrumentQueryServiceTest { // given int page = 0; int pageSize = 10; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); InstrumentSortOption sort = InstrumentSortOption.CREATED_BY_DESC; User user = createUser(); Page expectedResult = new PageImpl<>(List.of( @@ -244,7 +244,7 @@ class InstrumentQueryServiceTest { // given int page = 0; int pageSize = 10; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); + InstrumentFilterConditions filterConditions = createEmptyInstrumentFilterConditions(); InstrumentSortOption sort = InstrumentSortOption.CREATED_BY_DESC; User user = createUser(); Page expectedResult = new PageImpl<>(List.of( @@ -276,14 +276,23 @@ private Address createAddress() { return new Address("서울특별시", "강남구", "청담동"); } - private Instrument createInstrument(long instrumentId, User seller) throws Exception { - Constructor bassGuitarConstructor = BassGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + private User createUser(long id) throws Exception { + return ReflectionUtils.createUser( + id, + Set.of(RoleType.USER), + "test@mail.com", + "password", + "12345", + "https://user-default-profile-image-url", + LocalDate.of(2024, 1, 1), + Gender.ETC, + "01012345678", + null ); - bassGuitarConstructor.setAccessible(true); - return bassGuitarConstructor.newInstance( + } + + private Instrument createInstrument(long instrumentId, User seller) throws Exception { + return ReflectionUtils.createBassGuitar( instrumentId, seller, "Test electric guitar", @@ -301,13 +310,7 @@ private Instrument createInstrument(long instrumentId, User seller) throws Excep } private ElectricGuitar createElectricGuitar(long id, User seller) throws Exception { - Constructor electricGuitarConstructor = ElectricGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, Short.class, - Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, ElectricGuitarModel.class, - Short.class, GuitarColor.class - ); - electricGuitarConstructor.setAccessible(true); - return electricGuitarConstructor.newInstance( + return ReflectionUtils.createElectricGuitar( id, seller, "Test electric guitar", @@ -325,13 +328,7 @@ private ElectricGuitar createElectricGuitar(long id, User seller) throws Excepti } private BassGuitar createBassGuitar(long id, User seller) throws Exception { - Constructor bassGuitarConstructor = BassGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class - ); - bassGuitarConstructor.setAccessible(true); - return bassGuitarConstructor.newInstance( + return ReflectionUtils.createBassGuitar( id, seller, "Test electric guitar", @@ -348,36 +345,8 @@ private BassGuitar createBassGuitar(long id, User seller) throws Exception { ); } - private User createUser(long id) throws Exception { - Constructor userConstructor = User.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class - ); - userConstructor.setAccessible(true); - return userConstructor.newInstance( - id, - Set.of(RoleType.USER), - "test@mail.com", - "password", - "12345", - "https://user-default-profile-image-url", - LocalDate.of(2024, 1, 1), - Gender.ETC, - "01012345678", - null - ); - } - private AcousticAndClassicGuitar createAcousticAndClassicGuitar(long id, User seller) throws Exception { - Constructor acousticAndClassicGuitarConstructor = - AcousticAndClassicGuitar.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, - AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class - ); - acousticAndClassicGuitarConstructor.setAccessible(true); - return acousticAndClassicGuitarConstructor.newInstance( + return ReflectionUtils.createAcousticAndClassicGuitar( id, seller, "Test electric guitar", @@ -395,13 +364,7 @@ private AcousticAndClassicGuitar createAcousticAndClassicGuitar(long id, User se } private Effector createEffector(long id, User seller) throws Exception { - Constructor effectorConstructor = Effector.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - EffectorType.class, EffectorFeature.class - ); - effectorConstructor.setAccessible(true); - return effectorConstructor.newInstance( + return ReflectionUtils.createEffector( id, seller, "Title", @@ -417,13 +380,7 @@ private Effector createEffector(long id, User seller) throws Exception { } private Amplifier createAmplifier(long id, User seller) throws Exception { - Constructor amplifierConstructor = Amplifier.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class - ); - amplifierConstructor.setAccessible(true); - return amplifierConstructor.newInstance( + return ReflectionUtils.createAmplifier( id, seller, "Title", @@ -440,13 +397,7 @@ private Amplifier createAmplifier(long id, User seller) throws Exception { } private AudioEquipment createAudioEquipment(long id, User seller) throws Exception { - Constructor audioEquipmentConstructor = AudioEquipment.class.getDeclaredConstructor( - Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, - Short.class, Integer.class, Boolean.class, String.class, - AudioEquipmentType.class - ); - audioEquipmentConstructor.setAccessible(true); - return audioEquipmentConstructor.newInstance( + return ReflectionUtils.createAudioEquipment( id, seller, "Title", @@ -464,10 +415,7 @@ private User createUser() throws Exception { return createUser(1L); } - private InstrumentFilterConditions createInstrumentFilterConditions() throws Exception { - Constructor instrumentFilterConditionsConstructor = - InstrumentFilterConditions.class.getDeclaredConstructor(); - instrumentFilterConditionsConstructor.setAccessible(true); - return instrumentFilterConditionsConstructor.newInstance(); + private InstrumentFilterConditions createEmptyInstrumentFilterConditions() throws Exception { + return ReflectionUtils.createInstrumentFilterConditions(null); } } diff --git a/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java b/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java index 9cb5500..281631b 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java @@ -6,7 +6,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Set; @@ -38,6 +37,7 @@ import com.ajou.hertz.domain.user.dto.request.SignUpRequest; import com.ajou.hertz.domain.user.service.UserCommandService; import com.ajou.hertz.domain.user.service.UserQueryService; +import com.ajou.hertz.util.ReflectionUtils; import com.fasterxml.jackson.databind.ObjectMapper; @DisplayName("[Unit] Controller - User") @@ -218,11 +218,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() { } private SignUpRequest createSignUpRequest(String email, String password, String phone) throws Exception { - Constructor signUpRequestConstructor = SignUpRequest.class.getDeclaredConstructor( - String.class, String.class, LocalDate.class, Gender.class, String.class - ); - signUpRequestConstructor.setAccessible(true); - return signUpRequestConstructor.newInstance( + return ReflectionUtils.createSignUpRequest( email, password, LocalDate.of(2024, 1, 1), @@ -240,13 +236,7 @@ private SignUpRequest createSignUpRequest() throws Exception { } private UserDto createUserDto(long id) throws Exception { - Constructor userResponseConstructor = UserDto.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class, - LocalDateTime.class - ); - userResponseConstructor.setAccessible(true); - return userResponseConstructor.newInstance( + return ReflectionUtils.createUserDto( id, Set.of(RoleType.USER), "test@mail.com", diff --git a/src/test/java/com/ajou/hertz/unit/domain/user/service/UserCommandServiceTest.java b/src/test/java/com/ajou/hertz/unit/domain/user/service/UserCommandServiceTest.java index a0a62da..1e1dedd 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/user/service/UserCommandServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/user/service/UserCommandServiceTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.params.provider.Arguments.*; import static org.mockito.BDDMockito.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.util.Set; import java.util.stream.Stream; @@ -34,6 +33,7 @@ import com.ajou.hertz.domain.user.repository.UserRepository; import com.ajou.hertz.domain.user.service.UserCommandService; import com.ajou.hertz.domain.user.service.UserQueryService; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Service(Command) - User") @ExtendWith(MockitoExtension.class) @@ -178,12 +178,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() { } private static User createUser(Long id, String password, String kakaoUid, Gender gender) throws Exception { - Constructor userConstructor = User.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class - ); - userConstructor.setAccessible(true); - return userConstructor.newInstance( + return ReflectionUtils.createUser( id, Set.of(RoleType.USER), "test@test.com", @@ -202,11 +197,7 @@ private static User createUser(Long id, String password, String kakaoUid) throws } private SignUpRequest createSignUpRequest(String email, String phone) throws Exception { - Constructor signUpRequestConstructor = SignUpRequest.class.getDeclaredConstructor( - String.class, String.class, LocalDate.class, Gender.class, String.class - ); - signUpRequestConstructor.setAccessible(true); - return signUpRequestConstructor.newInstance( + return ReflectionUtils.createSignUpRequest( email, "1q2w3e4r!", LocalDate.of(2024, 1, 1), diff --git a/src/test/java/com/ajou/hertz/unit/domain/user/service/UserQueryServiceTest.java b/src/test/java/com/ajou/hertz/unit/domain/user/service/UserQueryServiceTest.java index e0c6271..5597b02 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/user/service/UserQueryServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/user/service/UserQueryServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; -import java.lang.reflect.Constructor; import java.time.LocalDate; import java.util.Optional; import java.util.Set; @@ -24,6 +23,7 @@ import com.ajou.hertz.domain.user.exception.UserNotFoundByPhoneException; import com.ajou.hertz.domain.user.repository.UserRepository; import com.ajou.hertz.domain.user.service.UserQueryService; +import com.ajou.hertz.util.ReflectionUtils; @DisplayName("[Unit] Service(Query) - User") @ExtendWith(MockitoExtension.class) @@ -205,12 +205,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() { } private User createUser(Long id, String email, String kakaoUid, String phone) throws Exception { - Constructor userConstructor = User.class.getDeclaredConstructor( - Long.class, Set.class, String.class, String.class, String.class, - String.class, LocalDate.class, Gender.class, String.class, String.class - ); - userConstructor.setAccessible(true); - return userConstructor.newInstance( + return ReflectionUtils.createUser( id, Set.of(RoleType.USER), email, diff --git a/src/test/java/com/ajou/hertz/util/ReflectionUtils.java b/src/test/java/com/ajou/hertz/util/ReflectionUtils.java new file mode 100644 index 0000000..2f7ff82 --- /dev/null +++ b/src/test/java/com/ajou/hertz/util/ReflectionUtils.java @@ -0,0 +1,747 @@ +package com.ajou.hertz.util; + +import java.lang.reflect.Constructor; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; + +import org.springframework.web.multipart.MultipartFile; + +import com.ajou.hertz.common.auth.dto.request.KakaoLoginRequest; +import com.ajou.hertz.common.auth.dto.request.LoginRequest; +import com.ajou.hertz.common.dto.AddressDto; +import com.ajou.hertz.common.dto.request.AddressRequest; +import com.ajou.hertz.common.entity.Address; +import com.ajou.hertz.common.file.dto.FileDto; +import com.ajou.hertz.common.kakao.dto.response.KakaoTokenResponse; +import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaEmd; +import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSgg; +import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSido; +import com.ajou.hertz.domain.instrument.constant.AcousticAndClassicGuitarBrand; +import com.ajou.hertz.domain.instrument.constant.AcousticAndClassicGuitarModel; +import com.ajou.hertz.domain.instrument.constant.AcousticAndClassicGuitarPickUp; +import com.ajou.hertz.domain.instrument.constant.AcousticAndClassicGuitarWood; +import com.ajou.hertz.domain.instrument.constant.AmplifierBrand; +import com.ajou.hertz.domain.instrument.constant.AmplifierType; +import com.ajou.hertz.domain.instrument.constant.AmplifierUsage; +import com.ajou.hertz.domain.instrument.constant.AudioEquipmentType; +import com.ajou.hertz.domain.instrument.constant.BassGuitarBrand; +import com.ajou.hertz.domain.instrument.constant.BassGuitarPickUp; +import com.ajou.hertz.domain.instrument.constant.BassGuitarPreAmplifier; +import com.ajou.hertz.domain.instrument.constant.EffectorFeature; +import com.ajou.hertz.domain.instrument.constant.EffectorType; +import com.ajou.hertz.domain.instrument.constant.ElectricGuitarBrand; +import com.ajou.hertz.domain.instrument.constant.ElectricGuitarModel; +import com.ajou.hertz.domain.instrument.constant.GuitarColor; +import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.dto.AcousticAndClassicGuitarDto; +import com.ajou.hertz.domain.instrument.dto.AmplifierDto; +import com.ajou.hertz.domain.instrument.dto.AudioEquipmentDto; +import com.ajou.hertz.domain.instrument.dto.BassGuitarDto; +import com.ajou.hertz.domain.instrument.dto.EffectorDto; +import com.ajou.hertz.domain.instrument.dto.ElectricGuitarDto; +import com.ajou.hertz.domain.instrument.dto.InstrumentImageDto; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewAcousticAndClassicGuitarRequest; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewAmplifierRequest; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewAudioEquipmentRequest; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewBassGuitarRequest; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewEffectorRequest; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewElectricGuitarRequest; +import com.ajou.hertz.domain.instrument.dto.request.InstrumentFilterConditions; +import com.ajou.hertz.domain.instrument.entity.AcousticAndClassicGuitar; +import com.ajou.hertz.domain.instrument.entity.Amplifier; +import com.ajou.hertz.domain.instrument.entity.AudioEquipment; +import com.ajou.hertz.domain.instrument.entity.BassGuitar; +import com.ajou.hertz.domain.instrument.entity.Effector; +import com.ajou.hertz.domain.instrument.entity.ElectricGuitar; +import com.ajou.hertz.domain.instrument.entity.Instrument; +import com.ajou.hertz.domain.instrument.entity.InstrumentHashtag; +import com.ajou.hertz.domain.instrument.entity.InstrumentImage; +import com.ajou.hertz.domain.user.constant.Gender; +import com.ajou.hertz.domain.user.constant.RoleType; +import com.ajou.hertz.domain.user.dto.UserDto; +import com.ajou.hertz.domain.user.dto.request.SignUpRequest; +import com.ajou.hertz.domain.user.entity.User; + +public class ReflectionUtils { + + /** + * Entity + */ + public static User createUser( + Long id, + Set roleTypes, + String email, + String password, + String kakaoUid, + String profileImageUrl, + LocalDate birth, + Gender gender, + String phone, + String contactLink + ) throws Exception { + Constructor constructor = User.class.getDeclaredConstructor( + Long.class, Set.class, String.class, String.class, String.class, + String.class, LocalDate.class, Gender.class, String.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, roleTypes, email, password, kakaoUid, profileImageUrl, birth, gender, phone, contactLink + ); + } + + public static InstrumentImage createInstrumentImage( + Long id, + Instrument instrument, + String originalName, + String storedName, + String url + ) throws Exception { + Constructor constructor = InstrumentImage.class.getDeclaredConstructor( + Long.class, Instrument.class, String.class, String.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(id, instrument, originalName, storedName, url); + } + + public static InstrumentHashtag createInstrumentHashtag( + Long id, + Instrument instrument, + String content + ) throws Exception { + Constructor constructor = InstrumentHashtag.class.getDeclaredConstructor( + Long.class, Instrument.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(id, instrument, content); + } + + public static ElectricGuitar createElectricGuitar( + Long id, + User seller, + String title, + InstrumentProgressStatus progressStatus, + Address tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + ElectricGuitarBrand brand, + ElectricGuitarModel model, + Short productionYear, + GuitarColor color + ) throws Exception { + Constructor constructor = ElectricGuitar.class.getDeclaredConstructor( + Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, Short.class, + Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, ElectricGuitarModel.class, + Short.class, GuitarColor.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, + brand, model, productionYear, color + ); + } + + public static BassGuitar createBassGuitar( + Long id, + User seller, + String title, + InstrumentProgressStatus progressStatus, + Address tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + BassGuitarBrand brand, + BassGuitarPickUp pickUp, + BassGuitarPreAmplifier preAmplifier, + GuitarColor color + ) throws Exception { + Constructor constructor = BassGuitar.class.getDeclaredConstructor( + Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, + Short.class, Integer.class, Boolean.class, String.class, + BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, + brand, pickUp, preAmplifier, color + ); + } + + public static AcousticAndClassicGuitar createAcousticAndClassicGuitar( + Long id, + User seller, + String title, + InstrumentProgressStatus progressStatus, + Address tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + AcousticAndClassicGuitarBrand brand, + AcousticAndClassicGuitarModel model, + AcousticAndClassicGuitarWood wood, + AcousticAndClassicGuitarPickUp pickUp + ) throws Exception { + Constructor constructor = AcousticAndClassicGuitar.class.getDeclaredConstructor( + Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, + Short.class, Integer.class, Boolean.class, String.class, + AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, + AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, + brand, model, wood, pickUp + ); + } + + public static Effector createEffector( + Long id, + User seller, + String title, + InstrumentProgressStatus progressStatus, + Address tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + EffectorType type, + EffectorFeature feature + ) throws Exception { + Constructor constructor = Effector.class.getDeclaredConstructor( + Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, + Short.class, Integer.class, Boolean.class, String.class, + EffectorType.class, EffectorFeature.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, + type, feature + ); + } + + public static Amplifier createAmplifier( + Long id, + User seller, + String title, + InstrumentProgressStatus progressStatus, + Address tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + AmplifierType type, + AmplifierBrand brand, + AmplifierUsage usage + ) throws Exception { + Constructor constructor = Amplifier.class.getDeclaredConstructor( + Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, + Short.class, Integer.class, Boolean.class, String.class, + AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, + type, brand, usage + ); + } + + public static AudioEquipment createAudioEquipment( + Long id, + User seller, + String title, + InstrumentProgressStatus progressStatus, + Address tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + AudioEquipmentType type + ) throws Exception { + Constructor constructor = AudioEquipment.class.getDeclaredConstructor( + Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, + Short.class, Integer.class, Boolean.class, String.class, + AudioEquipmentType.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, type + ); + } + + public static AdministrativeAreaSido createSido(Long id, String name) throws Exception { + Constructor constructor = AdministrativeAreaSido.class.getDeclaredConstructor( + Long.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(id, name); + } + + public static AdministrativeAreaSgg createSgg(Long id, AdministrativeAreaSido sido, String name) throws + Exception { + Constructor constructor = AdministrativeAreaSgg.class.getDeclaredConstructor( + Long.class, AdministrativeAreaSido.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(id, sido, name); + } + + public static AdministrativeAreaEmd createEmd(Long id, AdministrativeAreaSgg sgg, String name) throws Exception { + Constructor constructor = AdministrativeAreaEmd.class.getDeclaredConstructor( + Long.class, AdministrativeAreaSgg.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(id, sgg, name); + } + + /** + * DTO + */ + public static UserDto createUserDto( + Long id, + Set roleTypes, + String email, + String password, + String kakaoUid, + String profileImageUrl, + LocalDate birth, + Gender gender, + String phone, + String contactLink, + LocalDateTime createdAt + ) throws Exception { + Constructor constructor = UserDto.class.getDeclaredConstructor( + Long.class, Set.class, String.class, String.class, String.class, + String.class, LocalDate.class, Gender.class, String.class, String.class, + LocalDateTime.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, roleTypes, email, password, kakaoUid, profileImageUrl, birth, gender, phone, contactLink, createdAt + ); + } + + public static FileDto createFileDto(String originalName, String storedName, String url) throws Exception { + Constructor constructor = FileDto.class.getDeclaredConstructor( + String.class, String.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(originalName, storedName, url); + } + + public static AddressDto createAddressDto(String sido, String sgg, String emd) throws Exception { + Constructor constructor = AddressDto.class.getDeclaredConstructor( + String.class, String.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(sido, sgg, emd); + } + + public static InstrumentImageDto createInstrumentImageDto(Long id, String name, String url) throws Exception { + Constructor constructor = InstrumentImageDto.class.getDeclaredConstructor( + Long.class, String.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(id, name, url); + } + + public static ElectricGuitarDto createElectricGuitarDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + ElectricGuitarBrand brand, + ElectricGuitarModel model, + Short productionYear, + GuitarColor color + ) throws Exception { + Constructor constructor = ElectricGuitarDto.class.getDeclaredConstructor( + Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, + Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, ElectricGuitarModel.class, + Short.class, GuitarColor.class, List.class, List.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, + brand, model, productionYear, color, images, hashtags + ); + } + + public static BassGuitarDto createBassGuitarDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + BassGuitarBrand brand, + BassGuitarPickUp pickUp, + BassGuitarPreAmplifier preAmplifier, + GuitarColor color + ) throws Exception { + Constructor constructor = BassGuitarDto.class.getDeclaredConstructor( + Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, + hashtags, brand, pickUp, preAmplifier, color + ); + } + + public static AcousticAndClassicGuitarDto createAcousticAndClassicGuitarDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + AcousticAndClassicGuitarBrand brand, + AcousticAndClassicGuitarModel model, + AcousticAndClassicGuitarWood wood, + AcousticAndClassicGuitarPickUp pickUp + ) throws Exception { + Constructor constructor = AcousticAndClassicGuitarDto.class.getDeclaredConstructor( + Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, + AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, + hashtags, brand, model, wood, pickUp + ); + } + + public static EffectorDto createEffectorDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + EffectorType type, + EffectorFeature feature + ) throws Exception { + Constructor constructor = EffectorDto.class.getDeclaredConstructor( + Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + EffectorType.class, EffectorFeature.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, + hashtags, type, feature + ); + } + + public static AmplifierDto createAmplifierDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + AmplifierType type, + AmplifierBrand brand, + AmplifierUsage usage + ) throws Exception { + Constructor constructor = AmplifierDto.class.getDeclaredConstructor( + Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, + hashtags, type, brand, usage + ); + } + + public static AudioEquipmentDto createAudioEquipmentDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + AudioEquipmentType type + ) throws Exception { + Constructor constructor = AudioEquipmentDto.class.getDeclaredConstructor( + Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + AudioEquipmentType.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + id, seller, title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, + hashtags, type + ); + } + + /** + * DTO(Request) + */ + public static SignUpRequest createSignUpRequest( + String email, + String password, + LocalDate birth, + Gender gender, + String phone + ) throws Exception { + Constructor constructor = SignUpRequest.class.getDeclaredConstructor( + String.class, String.class, LocalDate.class, Gender.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(email, password, birth, gender, phone); + } + + public static LoginRequest createLoginRequest(String email, String password) throws Exception { + Constructor constructor = LoginRequest.class.getDeclaredConstructor(String.class, String.class); + constructor.setAccessible(true); + return constructor.newInstance(email, password); + } + + public static KakaoLoginRequest createKakaoLoginRequest( + String authorizationCode, + String redirectUri + ) throws Exception { + Constructor constructor = KakaoLoginRequest.class.getDeclaredConstructor( + String.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(authorizationCode, redirectUri); + } + + public static AddressRequest createAddressRequest(String sido, String sgg, String emd) throws Exception { + Constructor constructor = AddressRequest.class.getDeclaredConstructor( + String.class, String.class, String.class + ); + constructor.setAccessible(true); + return constructor.newInstance(sido, sgg, emd); + } + + public static CreateNewElectricGuitarRequest createElectricGuitarRequest( + String title, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + ElectricGuitarBrand brand, + ElectricGuitarModel model, + Short productionYear, + GuitarColor color + ) throws Exception { + Constructor constructor = CreateNewElectricGuitarRequest.class.getDeclaredConstructor( + String.class, List.class, InstrumentProgressStatus.class, AddressRequest.class, + Short.class, Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, + ElectricGuitarModel.class, Short.class, GuitarColor.class, List.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + title, images, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, + brand, model, productionYear, color, hashtags + ); + } + + public static CreateNewBassGuitarRequest createNewBassGuitarRequest( + String title, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + BassGuitarBrand brand, + BassGuitarPickUp pickUp, + BassGuitarPreAmplifier preAmplifier, + GuitarColor color + ) throws Exception { + Constructor constructor = CreateNewBassGuitarRequest.class.getDeclaredConstructor( + String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, hashtags, + brand, pickUp, preAmplifier, color + ); + } + + public static CreateNewAcousticAndClassicGuitarRequest createAcousticAndClassicGuitarRequest( + String title, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + AcousticAndClassicGuitarBrand brand, + AcousticAndClassicGuitarModel model, + AcousticAndClassicGuitarWood wood, + AcousticAndClassicGuitarPickUp pickUp + ) throws Exception { + Constructor constructor = CreateNewAcousticAndClassicGuitarRequest.class.getDeclaredConstructor( + String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + AcousticAndClassicGuitarBrand.class, AcousticAndClassicGuitarModel.class, + AcousticAndClassicGuitarWood.class, AcousticAndClassicGuitarPickUp.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, hashtags, + brand, model, wood, pickUp + ); + } + + public static CreateNewEffectorRequest createEffectorRequest( + String title, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + EffectorType type, + EffectorFeature feature + ) throws Exception { + Constructor constructor = CreateNewEffectorRequest.class.getDeclaredConstructor( + String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + EffectorType.class, EffectorFeature.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, hashtags, + type, feature + ); + } + + public static CreateNewAmplifierRequest createAmplifierRequest( + String title, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + AmplifierType type, + AmplifierBrand brand, + AmplifierUsage usage + ) throws Exception { + Constructor constructor = CreateNewAmplifierRequest.class.getDeclaredConstructor( + String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + AmplifierType.class, AmplifierBrand.class, AmplifierUsage.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, hashtags, + type, brand, usage + ); + } + + public static CreateNewAudioEquipmentRequest createAudioEquipmentRequest( + String title, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + AudioEquipmentType type + ) throws Exception { + Constructor constructor = CreateNewAudioEquipmentRequest.class.getDeclaredConstructor( + String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + AudioEquipmentType.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, hashtags, type + ); + } + + public static InstrumentFilterConditions createInstrumentFilterConditions( + InstrumentProgressStatus progressStatus + ) throws Exception { + Constructor constructor = InstrumentFilterConditions.class.getDeclaredConstructor( + InstrumentProgressStatus.class + ); + constructor.setAccessible(true); + return constructor.newInstance(progressStatus); + } + + /** + * DTO(Response) + */ + public static KakaoTokenResponse createKakaoTokenResponse( + String tokenType, + String accessToken, + Integer expiresIn, + String refreshToken, + Integer refreshTokenExpiresIn + ) throws Exception { + Constructor constructor = KakaoTokenResponse.class.getDeclaredConstructor( + String.class, String.class, Integer.class, String.class, Integer.class + ); + constructor.setAccessible(true); + return constructor.newInstance( + tokenType, accessToken, expiresIn, refreshToken, refreshTokenExpiresIn + ); + } +}