Skip to content

Commit f39471c

Browse files
committed
feat: 조회 실패 테스트 추가 (DASOMBE-14)
1 parent f89951b commit f39471c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/test/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dmu.dasom.api.domain.executive.service;
22

3+
import dmu.dasom.api.domain.common.exception.CustomException;
4+
import dmu.dasom.api.domain.common.exception.ErrorCode;
35
import dmu.dasom.api.domain.executive.dto.ExecutiveCreationResponseDto;
46
import dmu.dasom.api.domain.executive.dto.ExecutiveRequestDto;
57
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
@@ -12,10 +14,13 @@
1214
import org.mockito.InjectMocks;
1315
import org.mockito.Mock;
1416
import org.mockito.junit.jupiter.MockitoExtension;
17+
import org.springframework.security.test.context.support.WithMockUser;
1518

1619
import java.util.Optional;
1720

1821
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertThrows;
1924
import static org.mockito.ArgumentMatchers.any;
2025
import static org.mockito.Mockito.*;
2126

@@ -56,13 +61,29 @@ void getExecutiveById_success() {
5661
verify(executiveRepository, times(1)).findById(id); // 메소드를 정확히 한 번만 호출했는지?
5762
}
5863

64+
@Test
65+
@DisplayName("임원진 멤버 조회 - 실패")
66+
void getExecutiveById_fail() {
67+
// given
68+
Long id = 1L;
69+
when(executiveRepository.findById(1L)).thenReturn(Optional.empty());
70+
71+
// when
72+
CustomException exception = assertThrows(CustomException.class, () -> {
73+
executiveService.getExecutiveById(1L);
74+
});
75+
76+
// then
77+
assertEquals(ErrorCode.EXECUTIVE_NOT_FOUND, exception.getErrorCode());
78+
}
79+
5980
@Test
6081
@DisplayName("임원진 멤버 생성 - 성공")
6182
void createExecutive_success() {
6283
// given
6384
Long id = 1L;
6485
ExecutiveRequestDto dto = new ExecutiveRequestDto(
65-
"김다솜", "회장", "https://github.com/dasom"
86+
id, "김다솜", "회장", "https://github.com/dasom"
6687
);
6788

6889
ExecutiveEntity entity = ExecutiveEntity.builder()
@@ -81,6 +102,13 @@ void createExecutive_success() {
81102
assertThat(responseDto.getId()).isEqualTo(id);
82103
}
83104

105+
@Test
106+
@DisplayName("임원진 멤버 생성 - 실패_권한 없음")
107+
@WithMockUser(roles = "MEMBER")
108+
public void createExecutive_fail_authority() {
109+
110+
}
111+
84112
@Test
85113
@DisplayName("임원진 멤버 삭제 - 성공")
86114
void deleteExecutive_success() {

0 commit comments

Comments
 (0)