假设我有以下方法结构:
protected static void sub(Object obj, String filler) {
class cls = obj.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(cls);
// Other code...
}
给定这种结构,我如何模拟 BeanInfo 类?
假设我有以下方法结构:
protected static void sub(Object obj, String filler) {
class cls = obj.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(cls);
// Other code...
}
给定这种结构,我如何模拟 BeanInfo 类?
将此逻辑移动到单独的方法:
static BeanInfo beanInfo(Object obj) {
Class cls = obj.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(cls);
}
然后模拟beanInfo
方法。
You should code with dependency injection in mind. Then you can pass the mock as a parameter in your test.
protected static void sub(BeanInfo beanInfo, String filler) {
// code...
}