title: Unit testing a Swing component
body: <p>I am writing a TotalCommander-like application. I have a separate component for file list, and a model for it. Model support listeners and issues a notification for events like <code>CurrentDirChanged</code> etc. in following manner:</p>
  
  <pre>
  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);
              }
          });
      }
  }
  </pre>
  
  <p>I've written a simple test for this:</p>
  
  <pre>
  @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);
  }
  </pre>
  
  <p>This does not work, because there is no <code>EventDispatchThread</code>. Is there any way to unit test this inside the headless build? </p>
  
  <p>unit-testing java swing jmock</p>