I am writing some unit tests for an UI implementation. The problem that I came across is that I can't add a certain component to a container.

A quick example:

I have declared a JComboBox myComboBox.

The problem is when I call myComboBox.getParent() I get a null value. This causes further problems and my tests fail.

I have to specify that I'm using Mockito for testing and that the combo box was declared with the @Mock annotation before. My assumption is that because I use mocked objects I get this error.

So the question is: Does anyone have any ideas how to add my mocked component to a parent container, so that it won't be null? Or should I change the mocking framework and use JMock?