JpaRepository를 사용하여 컬렉션을 내 DB에 저장합니다. 다음은 메소드의 선언입니다 : 내 테스트에서Mockito WrongTypeOfReturnValue 목록 대신 반복 가능
<S extends T> List<S> save(Iterable<S> entities);
I는 다음과 같이 답변으로 returnsFirstArg
를 사용
doAnswer(returnsFirstArg()).when(userRepository)
.save(anyListOf(User.class));
그래서 내가 저장하지 않고 지정된 컬렉션을 반환합니다.
return userRepository.save(users);
나는 그 결과에 대한 주장을해야한다 : 나는 다음과 같은 코드를 테스트 때문에 null
을 반환 할 수 없습니다.
org.mockito.exceptions.misusing.WrongTypeOfReturnValue: The argument of type 'Iterable' cannot be returned because the following method should return the type 'List' -> userRepositorty bean.save()
The reason for this error can be : 1. The wanted argument position is incorrect. 2. The answer is used on the wrong interaction.
Position of the wanted argument is 0 and the possible argument indexes for this method are : [0] Iterable
가 어떻게이 문제를 해결할 수
:비웃음은 나에게 다음과 같은 오류를 준다? 오류 메시지에서 알 수 있듯이
Mockito 1.10.19
고마워요! 하지만 왜''i.getArguments() [0]'가 작동하고'returnsFirstArgument'가 아닌지 알 수 없습니다. 나는 그들이 같다고 생각했다. – Feeco