0

假设我有以下方法结构:

protected static void sub(Object obj, String filler) {

    class cls = obj.getClass();
    BeanInfo beanInfo = Introspector.getBeanInfo(cls);

    // Other code...
}

给定这种结构,我如何模拟 BeanInfo 类?

4

2 回答 2

0

将此逻辑移动到单独的方法:

static BeanInfo beanInfo(Object obj) {
    Class cls = obj.getClass();
    BeanInfo beanInfo = Introspector.getBeanInfo(cls);
}

然后模拟beanInfo方法。

于 2015-08-03T14:22:52.887 回答
0

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...
}
于 2015-08-03T14:48:40.683 回答