1

As the title mentions, I'm using PowerMockito to test a class that contains an inner private class. The inner class has a constructor that has an 'int[]' parameter. Below is the code.

final Class clazz = Whitebox.getInnerClassType(SomeClass.class, "InnerClass");
final Constructor constructor = Whitebox.getConstructor(clazz, int[].class);
final Object innerClass = constructor.newInstance(SORT_ORDER);

//This is the TARGET INNER CLASS' CONSTRUCTOR
public InnerClass(int[] sortOrder) {
    super(sortOrder);
}

The code throws

org.powermock.reflect.exceptions.ConstructorNotFoundException: Failed to lookup constructor with parameter types [ [I ] in class

Raedwald
  • 46,613
  • 43
  • 151
  • 237
user3050101
  • 51
  • 1
  • 9

1 Answers1

1
Class clazz = Whitebox.getInnerClassType(SomeClass.class, "InnerClass");
Constructor constructor = Whitebox.getConstructor(clazz, SomeClass.class);
InnerClassType innerClass = (InnerClassType) constructor.newInstance(new 
SomeClass());

Since my inner class was not static, it required a reference of the outer class.

user3050101
  • 51
  • 1
  • 9