Can PowerMock instantiate an inner class for test cases?

You should be able to move past your ConstructorNotFoundExeception via the following mods to your first effort:

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

Since your inner class is not static, it implicitly expects a "this" reference from the outer class. Using this method, looks like you have to get explicit with it.

Tags:

Java

Powermock