考慮這個如何模擬在方法內創建的對象?
public class UserManager {
private final CrudService crudService;
@Inject
public UserManager(@Nonnull final CrudService crudService) {
this.crudService = crudService;
}
@Nonnull
public List<UserPresentation> getUsersByState(@Nonnull final String state) {
return UserPresentation.getUserPresentations(new UserQueries(crudService).getUserByState(state));
}
}
我想模擬出
new UserQueries(crudService)
,這樣我可以模擬出其行爲
任何想法?
這也許可以幫助:http://docs.mockito.googlecode.com/hg/1.9.5/org/mockito/Spy.html – 2014-10-11 23:11:06