与标题一样,是否可以在ConversionSevice mock上调用实际方法?
例如,当我做这样的事情时:
private static final Date REQUEST_DATE = new Date();
@Mock
ConversionService conversionService;
@InjectMocks
ClaimRequestToClaimRequestTypeConverter converter = new ClaimRequestToClaimRequestTypeConverter();
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void convertTest() throws Exception {
when(conversionService.convert(eq(REQUEST_DATE), eq(XMLGregorianCalendar.class))).thenCallRealMethod();
ClaimRequest claim = new ClaimRequest();
ClaimRequestType claimType = converter.convert(claim);
verify(conversionService, times(3)).convert(eq(REQUEST_DATE), eq(XMLGregorianCalendar.class));
verify(conversionService, times(2)).convert(isA(ClaimRequestAction.class), eq(ClaimRequestActionType.class));
verifyNoMoreInteractions(conversionService);
}
我得到了:
org.mockito.exceptions.base.MockitoException:
Cannot call real method on java interface. Interface does not have any implementation!
Calling real methods is only possible when mocking concrete classes.
//correct example:
when(mockOfConcreteClass.doStuff()).thenCallRealMethod();
Mockito版本:1.8.5
春季版:3.2.8