实际上,我的问题是在标题中定义的。我正在用 Junit、PowerMock 和 Mockito 编写单元测试。我在嘲笑这样的班级,
class User{
public final synchronized String enter(AbstractClass ac){
//.....
}
}
// In test function
User mockUser = PowerMockito.mock(User.class);
PowerMockito.when(mockUser.enter( Mockito.any(Class1ImplementsSameAbstract.class)))
.thenReturn("Some Str 1");
PowerMockito.when(mockUser.enter( Mockito.any(Class2ImplementsSameAbstract.class)))
.thenReturn("Some Str 2");
System.out.println(mockUser.enter(new Class1ImplementsSameAbstract()));
System.out.println(mockUser.enter(new Class2ImplementsSameAbstract()));
如何区分这两个“何时”条件?当我运行这个测试时,两条“System.out..”行都打印“Some Str 2”。