您可以控制模拟的默认答案。在创建模拟时,请使用:
Mockito.mock(ObjectNeedToMock.class, new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { if (String.class.equals(invocation.getMethod().getReturnType())) { return "This is my default answer for all methods that returns string"; } else { return RETURNS_DEFAULTS.answer(invocation); } }}));


