I am writing a TotalCommander application. I have a separate component for a list of files and a model for it. The model supports listeners and issues a notification of events such as CurrentDirChanged , etc. In the following way:
private void fireCurrentDirectoryChanged (final IFile dir) {
if (SwingUtilities.isEventDispatchThread ())
for (FileTableEventsListener listener: tableListeners)
listener.currentDirectoryChanged (dir);
else {
SwingUtilities.invokeLater (new Runnable () {
public void run () {
for (FileTableEventsListener listener: tableListeners)
listener.currentDirectoryChanged (dir);
}
});
}
}
I wrote a simple test for this:
@Test
public void testEvents () throws IOException {
IFile testDir = mockDirectoryStructure ();
final FileSystemEventsListener listener =
context.mock (FileSystemEventsListener.class);
context.checking (new Expectations () {{
oneOf (listener) .currentDirectoryChanged (with (any (IFile.class)));
}});
FileTableModel model = new FileTableModel (testDir);
model.switchToInnerDirectory (1);
}
This does not work because there is no EventDispatchThread . Is there a unit test way to do this inside a headless assembly?
unit-testing java swing jmock
java unit-testing swing jmock
Ula Krukar
source share