-
argThat을 사용해서 primitive 타입을 확인하려고 할 때 주의사항프레임워크/JUnit 2024. 4. 17. 00:24
1. argThat을 사용할 때 NullPointExeception을 만날 수 있습니다.
"org.mockito.ArgumentMatchers.argThat(org.mockito.ArgumentMatcher)" is null
문제의 코드입니다. 서비스 메소드에서 Long이 아닌 long을 받고 있습니다.
argThat을 사용해서 id를 비교하려고 하니 예외가 발생합니다.
argThat은 기본적으로 Wrapper type을 기대하는데 primitive 타입을 사용하니 NullPointException을 던집니다.
이럴 때는 eq() 사용해서 더욱 간단히 표현하면 좋겠습니다.
'프레임워크 > JUnit' 카테고리의 다른 글
내부에서 실행되는 메소드에 인자가 잘 전달되는지 테스트 (0) 2024.04.17 멀티 쓰레드 환경에서 게시글 조회수 증가에 대한 검증 (0) 2024.04.15 InvalidUseOfMatchersException (0) 2024.03.27