0

Suppose I have the following method structure:

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

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

    // Other code...
}

How do I mock the BeanInfo class given this structure?

Miles Peterson
  • 265
  • 1
  • 4
  • 12

2 Answers2

0

Move this logic to separate method:

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

and then mock beanInfo method.

ka4eli
  • 5,294
  • 3
  • 23
  • 43
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...
}
ghdalum
  • 891
  • 5
  • 17