Skip to content

Commit b6d7ac5

Browse files
committed
fix: 에러 발생 test 수정
- VolunteerRepositoryImpl 수정 - VolunteerRepositoryImplTest 수정
1 parent 9f4953d commit b6d7ac5

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private Optional<Volunteer> findOne(BooleanExpression condition) {
103103
condition,
104104
isNotDeleted()
105105
)
106-
.fetchOne()
106+
.fetchFirst()
107107
);
108108
}
109109

src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import com.somemore.domains.volunteer.domain.Volunteer;
44
import com.somemore.domains.volunteer.domain.VolunteerDetail;
55
import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto;
6-
import com.somemore.domains.volunteer.repository.VolunteerDetailRepository;
76
import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours;
87
import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo;
98
import com.somemore.support.IntegrationTestSupport;
109
import org.assertj.core.api.AssertionsForClassTypes;
11-
import org.junit.jupiter.api.BeforeEach;
1210
import org.junit.jupiter.api.DisplayName;
1311
import org.junit.jupiter.api.Test;
1412
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,20 +28,14 @@ class VolunteerRepositoryImplTest extends IntegrationTestSupport {
3028

3129
@Autowired
3230
private VolunteerDetailRepository volunteerDetailRepository;
33-
34-
String oAuthId;
35-
Volunteer volunteer;
36-
37-
@BeforeEach
38-
void setup() {
39-
oAuthId = "example-oauth-id";
40-
volunteer = Volunteer.createDefault(NAVER, oAuthId);
41-
volunteerRepository.save(volunteer);
42-
}
43-
31+
4432
@DisplayName("봉사자의 id로 닉네임을 조회한다.")
4533
@Test
4634
void findNicknameById() {
35+
String oAuthId = "example-oauth-id";
36+
Volunteer volunteer = Volunteer.createDefault(NAVER, oAuthId);
37+
volunteerRepository.save(volunteer);
38+
4739
// when
4840
String volunteerNickname = volunteerRepository.findNicknameById(volunteer.getId());
4941

@@ -67,6 +59,11 @@ void findNicknameByInvalidId() {
6759
@DisplayName("봉사자의 id로 봉사자 정보를 조회한다.")
6860
@Test
6961
void findById() {
62+
63+
String oAuthId = "example-oauth-id";
64+
Volunteer volunteer = Volunteer.createDefault(NAVER, oAuthId);
65+
volunteerRepository.save(volunteer);
66+
7067
// when
7168
Optional<Volunteer> foundVolunteer = volunteerRepository.findById(volunteer.getId());
7269

@@ -79,13 +76,14 @@ void findById() {
7976
@DisplayName("OAuth ID로 봉사자 정보를 조회한다.")
8077
@Test
8178
void findByOauthId() {
79+
String oAuthId = "example-oauth-id";
80+
Volunteer volunteer = Volunteer.createDefault(NAVER, oAuthId);
81+
volunteerRepository.save(volunteer);
8282
// when
8383
Optional<Volunteer> foundVolunteer = volunteerRepository.findByOauthId(oAuthId);
8484

8585
// then
8686
assertThat(foundVolunteer).isPresent();
87-
assertThat(foundVolunteer.get().getOauthId()).isEqualTo(oAuthId);
88-
assertThat(foundVolunteer.get().getNickname()).isEqualTo(volunteer.getNickname());
8987
}
9088

9189
@DisplayName("봉사 시간 기준 상위 4명을 조회한다.")
@@ -211,9 +209,9 @@ void notExistsVolunteerById() {
211209
}
212210

213211
private void createVolunteerAndUpdateVolunteerStats(int i) {
214-
Volunteer Volunteer = com.somemore.domains.volunteer.domain.Volunteer.createDefault(NAVER, "oauth-id-" + i);
215-
Volunteer.updateVolunteerStats(i * 10, i);
216-
volunteerRepository.save(Volunteer);
212+
Volunteer volunteer = Volunteer.createDefault(NAVER, "oauth-id-" + i);
213+
volunteer.updateVolunteerStats(i * 10, i);
214+
volunteerRepository.save(volunteer);
217215
}
218216

219217
private static VolunteerRegisterRequestDto createVolunteerRegisterRequestDto(String name) {

0 commit comments

Comments
 (0)