How to fail on Exceptions on EDT

15 views
Skip to first unread message

christian

unread,
Jan 13, 2011, 5:40:31 AM1/13/11
to easytesting
Hi,

there is another issue with testing our companies software. There
occurs an exception, but the test doesn't fail.

I would be very pleased if someone can tell me how to make this test
fail when an exception on the EDT is thrown.

The exception is thrown after inserting an empty row in our table and
editing one of the rows below this empty row. We know this issue but
it would be very nice to have a test for this bug. I tried to write a
test and it worked, the exception was thrown (occured on console) and
the test passed.

Maybe the stack trace helps, here it is:
Exception in thread "AWT-EventQueue-1"
java.lang.ArrayIndexOutOfBoundsException: 2 > 1
at java.util.Vector.insertElementAt(Vector.java:551)
at
javax.swing.tree.DefaultMutableTreeNode.insert(DefaultMutableTreeNode.java:
177)
*at
de.icongmbh.dope.appserv.AbsDOPEDocComposite.insert(AbsDOPEDocComposite.java:
1132)
*at
de.icongmbh.dope.appserv.DOPEParagraph.insertVar(DOPEParagraph.java:
1573)
*at
de.icongmbh.dope.admin.DopeViewListModel.insertElementInObject(DopeViewListModel.java:
753)
*at
de.icongmbh.dope.admin.DopeTableListener.updateTableRow(DopeTableListener.java:
1450)
*at
de.icongmbh.dope.admin.DopeTableListener.updateParameterId(DopeTableListener.java:
1270)
*at
de.icongmbh.dope.admin.DopeTableListener.updateParameter(DopeTableListener.java:
1484)
*at
de.icongmbh.dope.admin.DopeTableListener.updateTableData(DopeTableListener.java:
2188)
*at
de.icongmbh.dope.admin.DopeTableListener.performTableDataUpdate(DopeTableListener.java:
470)
*at
de.icongmbh.dope.admin.DopeTableListener.tableChanged(DopeTableListener.java:
798)
at
javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:
280)
at
javax.swing.table.AbstractTableModel.fireTableCellUpdated(AbstractTableModel.java:
259)
*at
de.icongmbh.dope.admin.SortTableModel.setValueAt(SortTableModel.java:
1128)
at javax.swing.JTable.setValueAt(JTable.java:2719)
at javax.swing.JTable.editingStopped(JTable.java:4721)
at
javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:
125)
*at
de.icongmbh.dope.admin.ValidatedEditor.fireEditingStopped(ValidatedEditor.java:
123)
at javax.swing.DefaultCellEditor
$EditorDelegate.stopCellEditing(DefaultCellEditor.java:350)
at
javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:
215)
at javax.swing.DefaultCellEditor
$EditorDelegate.actionPerformed(DefaultCellEditor.java:367)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
at javax.swing.JTextField.postActionEvent(JTextField.java:705)
at javax.swing.JTextField
$NotifyAction.actionPerformed(JTextField.java:820)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1633)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2839)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2874)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2802)
at java.awt.Component.processEvent(Component.java:6040)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at
java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:
1850)
at
java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:
712)
at
java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:
990)
at
java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:
855)
at
java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:
676)
at java.awt.Component.dispatchEventImpl(Component.java:4502)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
*at
de.icongmbh.commons.swing.GlobalHotkeyManager.dispatchEvent(GlobalHotkeyManager.java:
260)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:
269)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:
184)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:
174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:
169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:
161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Thanks,
Christian

Alex Ruiz

unread,
Jan 13, 2011, 8:50:34 AM1/13/11
to easyt...@googlegroups.com
Hi Christian,

At the moment, I have no idea how to do this. Can you please file a ticket? We might be able to add something to FEST for checking exceptions thrown in the EDT.

Thanks,
-Alex
> --
> You received this message because you are subscribed to the Google Groups "easytesting" group.
> To post to this group, send email to easyt...@googlegroups.com.
> To unsubscribe from this group, send email to easytesting...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/easytesting?hl=en.
>
>

Hayden Shorter

unread,
Jan 13, 2011, 3:40:08 PM1/13/11
to easyt...@googlegroups.com
Hi,

We came across this problem too. You can plug in an Exception handler, and then report back to the test and/or fail the test when any exception occurs in the EDT.

It would be good to have this included by default when extending the Fest JUnit test class, as this is all generic code which could default to failing the test.

I've included the code below.

Cheers,
H

Handler:

public class AWTExceptionHandler {
    private static ITestExceptionListener currentListener;

    public AWTExceptionHandler(){
    }

    public void handle(final Throwable t) {
        currentListener.handleException(t);
    }
   
    public static void setExceptionListener(final ITestExceptionListener listener){
        currentListener = listener;
    }

    public static void registerExceptionHandler() {
        System.setProperty("sun.awt.exception.handler", AWTExceptionHandler.class.getName());
    }
}

The listener interface, implemented by the test:
Interface:

public interface ITestExceptionListener {
    void handleException(Throwable t);
}


Test:

@Override
    public void handleException(final Throwable t) {
        this.awtException = throwable;
    }



Then in the test @Before:

AWTExceptionHandler.registerExceptionHandler();
AWTExceptionHandler.setExceptionListener(this);

And finally in the @After method:

Assert.assertNull("Exception caught in AWT Thread during test!", awtException);

Alex Ruiz

unread,
Jan 13, 2011, 3:55:29 PM1/13/11
to easyt...@googlegroups.com
Thanks Hayden! You just reminded me that we already support this functionality in FEST. Please take a look at http://fest.easytesting.org/swing/apidocs/org/fest/swing/util/AWTExceptionHandlerInstaller.html

Cheers,
-Alex

christian

unread,
Jan 14, 2011, 4:31:47 AM1/14/11
to easytesting
Thanks a lot for your answers!

On my first try I tried to install the test class as exception
handler .. that didn't work.
So I used Haydens and I think this is good enough.

Christian


On 13 Jan., 21:55, Alex Ruiz <alex.ruiz...@gmail.com> wrote:
> Thanks Hayden! You just reminded me that we already support this
> functionality in FEST. Please take a look athttp://fest.easytesting.org/swing/apidocs/org/fest/swing/util/AWTExce...
> > On Thu, Jan 13, 2011 at 1:50 PM, Alex Ruiz <alex.ruiz...@gmail.com> wrote:
>
> >> Hi Christian,
>
> >> At the moment, I have no idea how to do this. Can you please file a
> >> ticket? We might be able to add something to FEST for checking exceptions
> >> thrown in the EDT.
>
> >> Thanks,
> >> -Alex
>
> >> On Thu, Jan 13, 2011 at 2:40 AM, christian <christian.roe...@icongmbh.de>
> >> easytesting...@googlegroups.com<easytesting%2Bunsu...@googlegroups.com>
> >> .
> >> > For more options, visit this group at
> >>http://groups.google.com/group/easytesting?hl=en.
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "easytesting" group.
> >> To post to this group, send email to easyt...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> easytesting...@googlegroups.com<easytesting%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/easytesting?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "easytesting" group.
> > To post to this group, send email to easyt...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > easytesting...@googlegroups.com<easytesting%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages