Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Doing method calls on a mock Stage object (using Mockito)

981131Jun 2 2013 — edited Jun 2 2013
Greetings Java people,

I have been using Mockito to create mock objects in order to build an application using the MVP paradigm, and so far I have been having reasonable success. However, when I create a mock Stage object to check method calls against it, it tells me that it's not running in the FX thread. Now, I could understand this happening if I were using a real stage object, but I can't understand why this is happening with a mock object.

Here is a code example of what I'm doing:
import static org.mockito.Mockito.*;

@Test
public void testCallsOnMockStageObject(){
	Stage dummyStage = mock(Stage.class);
	dummyStage.show();
	verify(dummyStage).show();
}
The "dummyStage.show()" line would be in a method of the Presenter class that I am building using TDD. When this line is executed, it throws the above mentioned exception. i.e. not on FX Thread. When it is commented out, the exception is not thrown. This tells me that it's not the verify statement throwing the exception.

Is there some way to run a test like this? Is there some way around it?

It is interesting that TreeView and TreeItem objects that are mocked are fine with method calls. I have yet to test other FX objects such as TableView.

I would appreciate any help.

Thanks in advance.

David Nicholson.

Edited by: 978128 on Jun 2, 2013 2:34 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 30 2013
Added on Jun 2 2013
0 comments
421 views