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

2
  • can you post the entire code that you are using Commented Oct 19, 2018 at 8:02
  • @hellWarrior I cannot, I apologize. But isnt this all we need to solve this? Commented Oct 19, 2018 at 8:05

1 Answer 1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.