我想测试一下,是否Collection.sort(...)
用JMockit调用:
final List<Employee> employees = new ArrayList<>();
new Expectations() {
{
Collections.sort((List<Employee>) any);
result = employees;
}
};
assertThat(EmployeeRepository.getAllOrderedByName()).isSameAs(employees);
这是我正在测试的示例存储库的实现:
public class EmployeeRepository {
private static List<Employee> employees = new ArrayList<>();
public static List<Employee> getAllOrderedByName() {
Collections.sort(employees);
return employees;
}
}
当我运行单元测试时,我在Collections.sort
. 由于调试器永远不会到达方法中的断点,因此它似乎是自我模拟的问题getAllOrderedByName
。
如何使用any
JMockit 存根静态方法?