-1

I try to test my application with FEST. Like in most other applications I have a System.exit() command in there. When I do nothing and run all tests, the test run is aborted when the System.exit() method is called for the first time.

I searched and found something here. It seemed to be what I was looking for, but it leads to an unexpected behavior. When I call System.exit() I get an infinite loop in System.exit() which every time throws the org.fest.swing.security.ExitException. If I catch the exception the application is not closed and the test never ends.

Does anyone have already used FEST like this?

For additional information here the complete stacktrace:

Exception in thread "AWT-EventQueue-0" org.fest.swing.security.ExitException: Application tried to terminate current JVM with status 0
at org.fest.swing.security.NoExitSecurityManager.checkExit(NoExitSecurityManager.java:84)
at java.lang.Runtime.exit(Unknown Source)
at java.lang.System.exit(Unknown Source)
at org.luciferius.banking.swingUi.internal.SwingUiBuilder$1.windowClosed(SwingUiBuilder.java:81)
at java.awt.AWTEventMulticaster.windowClosed(Unknown Source)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JFrame.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Regards, Yggdrasil

mabako
  • 1,213
  • 11
  • 19
Yggdrasil
  • 1,377
  • 2
  • 13
  • 27

1 Answers1

2

Yes, the NoExitSecurityManager can be used to prevent tests being interrupted because the application under test calls System.exit.

The ExitException is thrown in such case and its stack trace is written to console, but unless you catch the exception, it does not prevent the test from continuing and succeeding because it runs on a different thread.

The catch might be in an uncaught exception handler. If you have something like Thread.setDefaultUncaughtExceptionHandler(...) in your code, you will get the infinite loop. Such exception handler needs to be disabled during the tests.

Mareen
  • 425
  • 3
  • 5
  • I have nowhere used Thread.setDefaultUncaughtExceptionHandler(...) I did not even know that something like this exists. Are there other possible causes? – Yggdrasil Oct 10 '13 at 18:10
  • Please enhance your question with code snippets - initialization of the NoExistSecurityManager, code of the test that causes trouble etc. – Mareen Oct 10 '13 at 20:12