1
有測試代碼,其中thorws異常,我不明白 - 爲什麼?Mockito異常
例外:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
測試代碼:
@Test
public void testUpdateBookingFormData() throws Exception {
when(registrantFormService.getRegistrantFormByUUID(any(String.class))).thenReturn(registrantForm);
when(bookingService.getById(any(Long.class))).thenReturn(booking);
when(eventFieldRepository.findByEventIdOrderBySortIndexAsc(any(Long.class))).thenReturn(eventFieldList);
when(registrantAggregateService.getRegistrantDataAggregate(any(RegistrantKey.class))).thenReturn(registrantAggregate);
when(bookingFormStrategiesFactory.chooseStrategy(any(Long.class))).thenReturn(bookingFormStrategy);
when(bookingFormValidatorsFactory.getValidatorForForm(any(Booking.class))).thenReturn(validator);
when(validator.validate(any(BookingFormBean.class))).thenReturn(true);
when(bookingFormStrategy.getFormByKey(any(Booking.class), any(RegistrantKey.class))).thenReturn(bookingFormBean);
BookingFormsCollectionBean bookingFormsCollectionBean = bookingFormsService.updateBookingFormData(eq(booking.getKey().getVisitorId()), anyString(), anyMapOf(String.class, String[].class));
assertThat(bookingFormsCollectionBean, is(IsNull.notNullValue()));
}
我做錯了嗎?
UPD:全碼http://pastebin.com/rprLG8Nt
UPD2:這個全異常消息:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
1 matchers expected, 3 recorded:
-> at com.evm.front.service.logic.bookingprocess.BookingFormsServiceTest.testUpdateBookingFormData(BookingFormsServiceTest.java:106)
-> at com.evm.front.service.logic.bookingprocess.BookingFormsServiceTest.testUpdateBookingFormData(BookingFormsServiceTest.java:106)
-> at com.evm.front.service.logic.bookingprocess.BookingFormsServiceTest.testUpdateBookingFormData(BookingFormsServiceTest.java:106)
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
For more info see javadoc for Matchers class.
at com.evm.front.service.logic.bookingprocess.BookingFormsService.updateBookingFormData(BookingFormsService.java:202)
at com.evm.front.service.logic.bookingprocess.BookingFormsServiceTest.testUpdateBookingFormData(BookingFormsServiceTest.java:106)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
你是如何創建模擬對象? –
@BilboBaggins好吧,我在這個http://pastebin.com/rprLG8Nt添加我所有的代碼 –
什麼是完全例外?即哪一行是有問題的? –