[Kotlin] "Handler dispatch failed; nested exception is kotlin.NotImplementedError: An operation is not implemented: Not yet implemented" 오류 수정

최동근·2023년 4월 1일
2

예외수정

목록 보기
3/3

안녕하세요 오늘은 코틀린(Kotlin) 을 이용한 대출 심사 프로젝트 를 진행하던 도중 마주친 An operation is not implemented: Not yet implemented 오류 해결에 대해 기록을 남겨보려고 합니다 🤔

해당 프로젝트는 대출 심사 프로젝트 🏦 을 참고해주세요!
먼저 오류와 관련된 코드 부분부터 살펴보겠습니다 ❗️

👨‍🔧 관련 코드

// 대출 심사 요청하는 컨트롤러
// LoanRequestController 
@RestController
@RequestMapping("/loan/api/v1")
class LoanRequestController(
        private val loanRequestServiceImpl: LoanRequestServiceImpl
) {

    @PostMapping("/request")
    fun loanRequest(
            @RequestBody loanRequestInputDto: LoanRequestDto.LoanRequestInputDto
    ): ResponseEntity<LoanRequestDto.LoanRequestResponseDto> {
        return ResponseEntity.ok(
                loanRequestServiceImpl.loanRequestMain(loanRequestInputDto)
        )
    }
}
// 대출 심사 요청과 관련된 DTO
// LoanRequestDto

class LoanRequestDto {

    data class LoanRequestInputDto( // 요청
            val userName: String,
            val userIncomeAmount: Long,
            var userRegistrationNumber: String
    ) {
        fun toUserInfoDto(userKey: String) =
                UserInfoDto(
                        this.userRegistrationNumber,
                        this.userName,
                        userKey,
                        this.userIncomeAmount
                )
    }


    data class LoanRequestResponseDto( // 응답
            val userKey: String
    )
}
// 대출 심사 요청 로직을 구현한 Service
// LoanRequestServiceImpl
@Service
class LoanRequestServiceImpl(
        private val generateUserKey: GenerateUserKey,
        private val userInfoRepository: UserInfoRepository,
        private val encryptComponent: Encryptor
) : LoanRequestService {
    override fun loanRequestMain(
            loanRequestInputDto: LoanRequestDto.LoanRequestInputDto
    ): LoanRequestDto.LoanRequestResponseDto {

        val userKey = generateUserKey.generateUserKey()

        loanRequestInputDto.userRegistrationNumber = encryptComponent.encryptString(loanRequestInputDto.userRegistrationNumber)

        saveUserInfo(
                loanRequestInputDto.toUserInfoDto(userKey)
        )

        loanRequestReview("")

        return LoanRequestDto.LoanRequestResponseDto(userKey)
    }

    override fun saveUserInfo(userInfoDto: UserInfoDto) =
            userInfoRepository.save(userInfoDto.toEntity())


    override fun loanRequestReview(userKey: String) {
        TODO("Not yet implemented")
    }
}

이제 오류를 발생시킨 대망의 테스트 코드를 살펴보겠습니다 🤔

// 대출 심사 요청 컨트롤러 테스트 코드
// LoanRequestControllerTest
@WebMvcTest(LoanRequestController::class)
internal class LoanRequestControllerTest {

    private lateinit var mockMvc: MockMvc

    private lateinit var loanRequestController: LoanRequestController

    private lateinit var generateKey: GenerateUserKey

    private lateinit var encryptComponent: Encryptor

    private val userInfoRepository: UserInfoRepository = mockk()

    private lateinit var objectMapper: ObjectMapper // 직렬화를 위한 라이브러리

    @MockBean
    private lateinit var loanRequestServiceImpl: LoanRequestServiceImpl

    companion object {
        private const val baseUrl = "/loan/api/v1"
    }


    @BeforeEach
    fun init() {

        generateKey = GenerateUserKey()
        encryptComponent = Encryptor()

        loanRequestServiceImpl = LoanRequestServiceImpl(
                generateKey, userInfoRepository, encryptComponent
        )

        loanRequestController = LoanRequestController(loanRequestServiceImpl)

        mockMvc = MockMvcBuilders.standaloneSetup(loanRequestController).build()

        objectMapper = ObjectMapper().registerModule(KotlinModule.Builder().build())
    }


    @Test
    @DisplayName("성공적인 대출 심사 요청")
    fun successLoanRequestTest() {
        // given
        val loanRequestInputDto: LoanRequestDto.LoanRequestInputDto =
                LoanRequestDto.LoanRequestInputDto(
                        userName = "TEST",
                        userIncomeAmount = 10000,
                        userRegistrationNumber = "971201-1216826"
                )

        every {userInfoRepository.save(any())} returns UserInfo(
                "","","",1
        )

        // when
        mockMvc.post(
                "$baseUrl/request"
        ) {
            contentType = MediaType.APPLICATION_JSON
            accept = MediaType.APPLICATION_JSON
            content = objectMapper.writeValueAsString(loanRequestInputDto)
        }.andExpect {
            status{ isOk() }
        }
        // then
    }
}

테스트를 잘 작성하고 코드를 돌려보았습니다 그런데...

Handler dispatch failed; nested exception is kotlin.NotImplementedError: An operation is not implemented: Not yet implemented
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is kotlin.NotImplementedError: An operation is not implemented: Not yet implemented

👨‍🔧 해결방안

해당 오류가 발생했습니다.
약 1시간 동안 이상없는 코드만 만지작 거리는 중 TODO() Kotlin 인라인 함수 가 있으면 해당 에러를 무조건 발생시킨다는 블로그 글을 보게되었습니다 ❗️

Command + Shift + F 단축키로 전체 찾기 기능을 통해 TODO() 를 찾아보게되었습니다.

이런 역시나 제가 모르는 사이에 TODO() 를 남겨두었다는 사실을 발견하게 되고 해당 코드를 주석처리 한 후 실행해시켜보았습니다 😳
결과는 테스트 통과 🌱

해당 오류로 고생하실 다른 분들을 위해 이렇게 글을 남겨보았습니다.

지금까지 다양한 오류를 경험했지만 항상 느끼는 것은 당황하지 말고 차근차근 검색을 하다보면 올바른 해답을 찾을 수 있다는 사실입니다 😆


참고

kotlin.NotImplementedError: 작업이 구현되지 않음: ImageButton 클릭에서 구현되지 않은 오류
오류 삽질

profile
비즈니스가치를추구하는개발자

0개의 댓글