Skip to content

Commit 36f8365

Browse files
committed
test(volunteer): sonar qube 이슈 해결 커버리지 테스트 추가
1 parent e4aea21 commit 36f8365

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/test/java/com/somemore/volunteer/service/UpdateVolunteerLockServiceTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.somemore.volunteer.service;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5+
import static org.mockito.ArgumentMatchers.any;
6+
import static org.mockito.ArgumentMatchers.anyLong;
7+
import static org.mockito.BDDMockito.given;
48

59
import com.somemore.support.IntegrationTestSupport;
610
import com.somemore.volunteer.domain.NEWVolunteer;
@@ -12,7 +16,9 @@
1216
import org.junit.jupiter.api.AfterEach;
1317
import org.junit.jupiter.api.DisplayName;
1418
import org.junit.jupiter.api.Test;
19+
import org.redisson.api.RLock;
1520
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.boot.test.mock.mockito.MockBean;
1622

1723
class UpdateVolunteerLockServiceTest extends IntegrationTestSupport {
1824

@@ -22,6 +28,9 @@ class UpdateVolunteerLockServiceTest extends IntegrationTestSupport {
2228
@Autowired
2329
private NEWVolunteerJpaRepository volunteerRepository;
2430

31+
@MockBean
32+
private RLock lock;
33+
2534
@AfterEach
2635
void tearDown() {
2736
volunteerRepository.deleteAllInBatch();
@@ -79,6 +88,24 @@ void updateVolunteerStatsWithConcurrency() throws InterruptedException {
7988
assertThat(find.getTotalVolunteerHours()).isEqualTo(hours * threadCnt);
8089
}
8190

91+
@DisplayName("봉사활동 정보 업데이트 중 인터럽트 예외 발생")
92+
@Test
93+
void UpdateVolunteerStats_InterruptedException() throws InterruptedException {
94+
// given
95+
UUID id = UUID.randomUUID();
96+
int hours = 5;
97+
98+
given(lock.tryLock(anyLong(), anyLong(), any()))
99+
.willThrow(new InterruptedException());
100+
101+
// when
102+
// then
103+
assertThatThrownBy(
104+
() -> updateVolunteerLockService.updateVolunteerStats(id, hours))
105+
.isInstanceOf(RuntimeException.class);
106+
107+
}
108+
82109
private static NEWVolunteer createVolunteer() {
83110
UUID userId = UUID.randomUUID();
84111
return NEWVolunteer.createDefault(userId);

0 commit comments

Comments
 (0)