I am getting a NullPointerException when I try to unit test some methods in a JDialog object. I have to initialize a mock version of the parent of the dialog as well as another class that will be used (in addition to calling a static method. The code is as follows:
@RunWith( PowerMockRunner.class )
@PrepareForTest( ControlFileUtilities.class )
public class StructCompDlgTest
{
@Before
public void setUp() throws Exception
{
controlFrame = org.mockito.Mockito.mock( ControlFrame.class );
structCmpDlg = new StructureCompareDialog( controlFrame );
serverPipeline = org.mockito.Mockito.mock( ServerPipeline.class );
}
...
}
The code that is called for constructing the dialog is here:
StructureCompareDialog( IControlFrame controlFrame )
{
super( (Frame) controlFrame, "title", true );
...
}
when the super constructor is called I will eventually get an NullPointerError at java.awt.Window.addOwnerWindow(Window.java:2525)"
void addOwnedWindow(WeakReference weakWindow) {
if (weakWindow != null) {
synchronized(ownedWindowList) { ***<<------ offending line***
// this if statement should really be an assert, but we don't
// have asserts...
if (!ownedWindowList.contains(weakWindow)) {
ownedWindowList.addElement(weakWindow);
}
}
}
}
I know I am mixing up statics and swing gui in a toxic swirl but I have no choice. I was given the instruction to throw together some unit tests with existing code. I have no idea what is going wrong.
Thanks