Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: PK 타입을 Long 으로 변경 #61

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/verby/indp/domain/contact/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Contact extends BaseTimeEntity {
@Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "contact_id")
private long contactId;
private Long contactId;

@Embedded
private ContactUserName userName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Notification extends BaseTimeEntity {
@Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "notification_id")
private long notificationId;
private Long notificationId;

@Column(name = "subject")
private String subject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Recommendation extends BaseTimeEntity {
@Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "recommendation_id")
private long recommendationId;
private Long recommendationId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/verby/indp/domain/song/SongForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SongForm {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "song_form_id")
private long songFormId;
private Long songFormId;

@Embedded
private SongFormName name;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/verby/indp/domain/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Store extends BaseTimeEntity {
@Getter
@Column(name = "store_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long storeId;
private Long storeId;

@Embedded
private StoreName name;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/verby/indp/domain/theme/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Theme {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "theme_id")
private long themeId;
private Long themeId;

@Embedded
private ThemeName name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.verby.indp.domain.contact.controller;

import static com.verby.indp.domain.contact.fixture.ContactFixture.contact;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
Expand Down Expand Up @@ -29,7 +30,7 @@ void registerContact() throws Exception {
RegisterContactRequest request = new RegisterContactRequest(contact.getUserName(),
contact.getContent(), contact.getPhoneNumber());

when(contactService.registerContact(request)).thenReturn(contact.getContactId());
when(contactService.registerContact(request)).thenReturn(anyLong());

// when
ResultActions resultActions = mockMvc.perform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.util.ReflectionTestUtils;

@ExtendWith(MockitoExtension.class)
class ContactServiceTest {
Expand All @@ -40,6 +41,7 @@ class RegisterContact {
void registerContact() {
// given
Contact contact = contact();
ReflectionTestUtils.setField(contact, "contactId", 1L);

RegisterContactRequest request = new RegisterContactRequest(contact.getUserName(),
contact.getContent(), contact.getPhoneNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.verby.indp.domain.recommendation.fixture.RecommendationFixture.recommendation;
import static com.verby.indp.domain.store.fixture.StoreFixture.store;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders;
Expand All @@ -19,6 +20,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.ResultActions;

class RecommendationControllerTest extends BaseControllerTest {
Expand All @@ -28,12 +30,13 @@ class RecommendationControllerTest extends BaseControllerTest {
void registerRecommendation() throws Exception {
// given
Store store = store();
ReflectionTestUtils.setField(store, "storeId", 1L);
Recommendation recommendation = recommendation(store());

RegisterRecommendationRequest request = new RegisterRecommendationRequest(store.getStoreId(),
recommendation.getInformation(), recommendation.getPhoneNumber());

when(recommendationService.registerRecommendation(request)).thenReturn(recommendation.getRecommendationId());
when(recommendationService.registerRecommendation(request)).thenReturn(anyLong());

// when
ResultActions resultActions = mockMvc.perform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.util.ReflectionTestUtils;

@ExtendWith(MockitoExtension.class)
class RecommendationServiceTest {
Expand All @@ -50,14 +51,15 @@ class RegisterRecommendation {
@DisplayName("성공: 추천 음악 정보를 저장한다.")
void registerRecommendation() {
// given
long storeId = 1L;
Store store = store();
ReflectionTestUtils.setField(store, "storeId", 1L);
Recommendation recommendation = recommendation(store);

RegisterRecommendationRequest request = new RegisterRecommendationRequest(storeId,
ReflectionTestUtils.setField(recommendation, "recommendationId", 1L);

RegisterRecommendationRequest request = new RegisterRecommendationRequest(store.getStoreId(),
recommendation.getInformation(), recommendation.getPhoneNumber());

when(storeRepository.findById(anyLong())).thenReturn(Optional.of(store));
when(storeRepository.findById(store.getStoreId())).thenReturn(Optional.of(store));
when(recommendationRepository.save(any(Recommendation.class))).thenReturn(
recommendation);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.verby.indp.domain.store.controller;

import static com.verby.indp.domain.store.constant.Region.서울;
import static com.verby.indp.domain.store.fixture.StoreFixture.stores;
import static com.verby.indp.domain.store.fixture.StoreFixture.storesWithId;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.payload.JsonFieldType.ARRAY;
Expand Down Expand Up @@ -41,7 +41,7 @@ void findSimpleStores() throws Exception {
int page = 0;
int size = 2;

List<Store> stores = stores(List.of(), List.of(), count);
List<Store> stores = storesWithId(List.of(), List.of(), count);
Pageable pageable = PageRequest.of(page, size);
Page<Store> pageStores = new PageImpl<>(stores.subList(page * size, size), pageable, count);

Expand Down Expand Up @@ -88,7 +88,7 @@ void findStores() throws Exception {
int page = 0;
int size = 2;

List<Store> stores = stores(List.of(), List.of(), count, 서울);
List<Store> stores = storesWithId(List.of(), List.of(), count, 서울);
Pageable pageable = PageRequest.of(page, size);
Page<Store> pageStores = new PageImpl<>(stores.subList(page * size, size), pageable, count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.springframework.test.util.ReflectionTestUtils;

public class StoreFixture {

Expand Down Expand Up @@ -66,6 +67,20 @@ public static List<Store> stores(
.collect(Collectors.toCollection(ArrayList::new));
}

public static List<Store> storesWithId(
List<Theme> themes,
List<SongForm> songForms,
int count
) {
return IntStream.range(0, count)
.mapToObj(i -> {
Store store = store(themes, songForms);
ReflectionTestUtils.setField(store, "storeId", (long) i);
return store;
})
.collect(Collectors.toCollection(ArrayList::new));
}

public static List<Store> stores(
List<Theme> themes,
List<SongForm> songForms,
Expand All @@ -77,4 +92,19 @@ public static List<Store> stores(
.collect(Collectors.toCollection(ArrayList::new));
}

public static List<Store> storesWithId(
List<Theme> themes,
List<SongForm> songForms,
int count,
Region region
) {
return IntStream.range(0, count)
.mapToObj(i -> {
Store store = store(themes, songForms, region);
ReflectionTestUtils.setField(store, "storeId", (long) i);
return store;
})
.collect(Collectors.toCollection(ArrayList::new));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import static com.verby.indp.domain.store.constant.Region.경기;
import static com.verby.indp.domain.store.constant.Region.서울;
import static com.verby.indp.domain.store.fixture.StoreFixture.stores;
import static com.verby.indp.domain.store.fixture.StoreFixture.storesWithId;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -47,7 +47,7 @@ void findSimpleStores() {
int page = 0;
int size = 10;

List<Store> stores = stores(List.of(), List.of(), count);
List<Store> stores = storesWithId(List.of(), List.of(), count);
Pageable pageable = PageRequest.of(page, size);
Page<Store> pageStores = new PageImpl<>(stores.subList(page, size), pageable, count);

Expand Down Expand Up @@ -81,7 +81,7 @@ void findStoresOfRegion() {
int page = 0;
int size = 10;

List<Store> seoulStores = stores(List.of(), List.of(), seoulCount, 서울);
List<Store> seoulStores = storesWithId(List.of(), List.of(), seoulCount, 서울);
Pageable pageable = PageRequest.of(page, size);
Page<Store> pageStores = new PageImpl<>(
seoulStores.subList(page, Math.min(size, seoulCount)), pageable, seoulCount);
Expand Down Expand Up @@ -113,8 +113,8 @@ void findStores() {
int page = 0;
int size = 10;

List<Store> seoulStores = stores(List.of(), List.of(), seoulCount, 서울);
List<Store> gyeonggiStores = stores(List.of(), List.of(), gyeonggiCount, 경기);
List<Store> seoulStores = storesWithId(List.of(), List.of(), seoulCount, 서울);
List<Store> gyeonggiStores = storesWithId(List.of(), List.of(), gyeonggiCount, 경기);
List<Store> allStores = new ArrayList<>();
allStores.addAll(seoulStores);
allStores.addAll(gyeonggiStores);
Expand Down
Loading