我想测试我班级的 equals() 方法,但 Mockito 似乎每次都在调用存根版本。我的测试如下;
PluginResourceAdapter adapter = mock (PluginResourceAdapter.class);
PluginResourceAdapter other = mock (PluginResourceAdapter.class);
when(adapter.getNumberOfEndpointActivation()).thenReturn(1);
when(other.getNumberOfEndpointActivation()).thenReturn(0);
boolean result = adapter.equals(other);
assertFalse(result);
我知道我不能存根 equals 方法,这意味着 Mockito 应该调用我的真正实现,但它不是。
我也试过这个:
when (adapter.equals(any()).thenCallRealMethod()
但我得到了同样的结果。