假设我有以下方法结构:
protected static void sub(Object obj, String filler) {
class cls = obj.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(cls);
// Other code...
}在这种结构的情况下,如何模拟BeanInfo类?
发布于 2015-08-03 14:22:52
将此逻辑移到单独的方法:
static BeanInfo beanInfo(Object obj) {
Class cls = obj.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(cls);
}然后模拟beanInfo方法。
发布于 2015-08-03 14:48:40
您应该考虑使用依赖注入编写代码。然后,可以将模拟作为测试中的一个参数传递。
protected static void sub(BeanInfo beanInfo, String filler) {
// code...
}https://stackoverflow.com/questions/31789623
复制相似问题