Chi tiết lỗi:
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Boolean cannot be returned by updateItemAttributesByJuId()
updateItemAttributesByJuId() should return ResultRich
This exception might occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
mã của tôi :
@InjectMocks
protected ItemArrangeManager arrangeManagerSpy = spy(new ItemArrangeManagerImpl());
@Mock
protected JuItemWriteService juItemWriteService;
when(arrangeManagerSpy
.updateItemAttributes(mapCaptor.capture(), eq(juId), eq(itemTO.getSellerId())))
.thenReturn(false);
Như bạn thấy, tôi kêu gọi whentrên updateItemAttributes(mà không trở lại một boolean) không vào updateItemAttributesByJuId.
- Tại sao Mockito lại cố gắng trả lại
booleantừupdateItemAttributesByJuId? - Làm thế nào điều này có thể được khắc phục?
@Repositoryphương pháp Spring DAO với @Aspect . nếu tôi làm vậywhen(someDao.someMethod()).thenReturn(List<xxx>), tôi có ngoại lệ WrongTypeOfReturnValue này. Thông qua gỡ lỗi, tôi có thể thấy rằngsomeMethodphương thức thực sự được gọi trong câu lệnh trên và kích hoạt Lời khuyên xung quanh và trả về anullnhưng Mockito đang mong đợi aList<xxx>.