junit.extensions.abbot
Class ComponentTestFixture

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byjunit.extensions.abbot.ResolverFixture
              extended byjunit.extensions.abbot.ComponentTestFixture
All Implemented Interfaces:
Test
Direct Known Subclasses:
ArrowButtonTest, LabeledListTest, ScriptFixture

public class ComponentTestFixture
extends ResolverFixture

Simple wrapper for testing components under JUnit. Ensures proper setup and cleanup for a GUI environment. Provides methods for automatically placing a GUI component within a frame and properly handling Window showing/hiding (including modal dialogs). Catches exceptions thrown on the event dispatch thread and rethrows them as test failures.

Use showFrame(Component) when testing individual components, or showWindow(Window) when testing a Frame, Dialog, or Window.


Nested Class Summary
static class ComponentTestFixture.ExceptionCatcher
          Provide access to the most recent exception caught on the dispatch thread.
 
Nested classes inherited from class junit.extensions.abbot.ResolverFixture
ResolverFixture.ComponentMatcher
 
Field Summary
static int EVENT_GENERATION_DELAY
          Typical delay to wait for a robot event to be translated into a Java event.
static int POPUP_DELAY
           
static int WINDOW_DELAY
           
 
Constructor Summary
ComponentTestFixture(String name)
          Construct a test case with the given name.
 
Method Summary
protected  void fixtureSetUp()
          Ensure proper test harness setup and teardown that won't be inadvertently overridden by a derived class.
protected  void fixtureTearDown()
          Handles restoration of system state.
protected  Robot getRobot()
          Return an Abbot robot for basic event generation.
protected  WindowTracker getWindowTracker()
          Return a WindowTracker instance.
protected  void hideWindow(Window w)
          Synchronous, safe hide of a window.
protected  void installPopup(Component invoker, JPopupMenu popup)
          Install the given popup on the given component.
protected  boolean isShowing(String id)
          Returns whether a Component is showing.
 void runBare()
          If any exceptions are thrown on the event dispatch thread, they count as errors.
protected  Frame showFrame(Component comp)
          This method should be invoked to display the component under test.
protected  Frame showFrame(Component comp, Dimension size)
          This method should be invoked to display the component under test, when a specific size of frame is desired.
protected  Dialog showModalDialog(Runnable showAction, Component contents)
          Display a modal dialog and wait for it to show.
protected  void showPopup(JPopupMenu popup, Component invoker)
          Safely install and display a popup in the center of the given component, returning when it is visible.
protected  void showPopup(JPopupMenu popup, Component invoker, int x, int y)
          Safely install and display a popup, returning when it is visible.
protected  void showWindow(Window w)
          Safely display a window, avoiding deadlock.
protected  void showWindow(Window w, Dimension size)
          Safely display a window, avoiding deadlock.
protected  void showWindow(Window w, Dimension size, boolean pack)
          Safely display a window, avoiding deadlock.
 
Methods inherited from class junit.extensions.abbot.ResolverFixture
getFinder, getHierarchy, getResolver
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EVENT_GENERATION_DELAY

public static final int EVENT_GENERATION_DELAY
Typical delay to wait for a robot event to be translated into a Java event.

See Also:
Constant Field Values

WINDOW_DELAY

public static final int WINDOW_DELAY
See Also:
Constant Field Values

POPUP_DELAY

public static final int POPUP_DELAY
See Also:
Constant Field Values
Constructor Detail

ComponentTestFixture

public ComponentTestFixture(String name)
Construct a test case with the given name.

Method Detail

getRobot

protected Robot getRobot()
Return an Abbot robot for basic event generation.


getWindowTracker

protected WindowTracker getWindowTracker()
Return a WindowTracker instance.


showFrame

protected Frame showFrame(Component comp)
This method should be invoked to display the component under test. The frame's size will be its preferred size.


showFrame

protected Frame showFrame(Component comp,
                          Dimension size)
This method should be invoked to display the component under test, when a specific size of frame is desired.


showWindow

protected void showWindow(Window w)
Safely display a window, avoiding deadlock.


showWindow

protected void showWindow(Window w,
                          Dimension size)
Safely display a window, avoiding deadlock.


showWindow

protected void showWindow(Window w,
                          Dimension size,
                          boolean pack)
Safely display a window, avoiding deadlock. This also works with modal dialogs, since the "show" is called on the event dispatch thread.


hideWindow

protected void hideWindow(Window w)
Synchronous, safe hide of a window.


installPopup

protected void installPopup(Component invoker,
                            JPopupMenu popup)
Install the given popup on the given component. Takes care of installing the appropriate mouse handler to activate the popup.


showPopup

protected void showPopup(JPopupMenu popup,
                         Component invoker)
Safely install and display a popup in the center of the given component, returning when it is visible. Does not install any mouse handlers not generate any mouse events.


showPopup

protected void showPopup(JPopupMenu popup,
                         Component invoker,
                         int x,
                         int y)
Safely install and display a popup, returning when it is visible. Does not install any mouse handlers not generate any mouse events.


showModalDialog

protected Dialog showModalDialog(Runnable showAction,
                                 Component contents)
                          throws Exception
Display a modal dialog and wait for it to show. Useful for things like JFileChooser.showOpenDialog or JOptionPane.showInputDialog.

Throws:
Exception

isShowing

protected boolean isShowing(String id)
Returns whether a Component is showing. The ID may be the component name or, in the case of a Frame or Dialog, the title. Regular expressions may be used, but must be delimited by slashes, e.g. /expr/. Returns if one or more matches is found.


fixtureSetUp

protected void fixtureSetUp()
                     throws Throwable
Ensure proper test harness setup and teardown that won't be inadvertently overridden by a derived class.

Overrides:
fixtureSetUp in class ResolverFixture
Throws:
Throwable

fixtureTearDown

protected void fixtureTearDown()
                        throws Throwable
Handles restoration of system state. Automatically disposes of any Components used in the test.

Overrides:
fixtureTearDown in class ResolverFixture
Throws:
Throwable

runBare

public void runBare()
             throws Throwable
If any exceptions are thrown on the event dispatch thread, they count as errors.

Overrides:
runBare in class ResolverFixture
Throws:
Throwable


Copyright © 2002-2004 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge