Hi,

I've got a problem when I try to use UISpec4J for unit testing Swing based
applications.
Iv'e got a test class that extends UISpecTestCase. In IntelliJ, my test
works witout any problem. But, when I try to run my test by using Maven2, it
throws an exception.


###################################################################################################################
[INFO] [surefire:test]
[INFO] Surefire report directory:
C:\DEV\projects\migration\agf-agent-bootstrap\target\surefire-reports
org.apache.maven.surefire.booter.SurefireExecutionException:
com.agf.workflow.gui.wizard.WizardWindowTest; nested exception is jav
a.awt.AWTError: Toolkit not found:
org.uispec4j.interception.toolkit.UISpecToolkit; nested exception is
org.apache.maven.surefire.
testset.TestSetFailedException: com.agf.workflow.gui.wizard.WizardWindowTest;
nested exception is java.awt.AWTError: Toolkit not f
ound: org.uispec4j.interception.toolkit.UISpecToolkit
org.apache.maven.surefire.testset.TestSetFailedException:
com.agf.workflow.gui.wizard.WizardWindowTest; nested exception is java.a
wt.AWTError: Toolkit not found:
org.uispec4j.interception.toolkit.UISpecToolkit
java.awt.AWTError: Toolkit not found:
org.uispec4j.interception.toolkit.UISpecToolkit
       at java.awt.Toolkit$2.run(Toolkit.java:828)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:804)
       at javax.swing.UIManager.<clinit>(UIManager.java:313)
       at org.uispec4j.interception.ui.UISpecLF.init(UISpecLF.java:11)
       at org.uispec4j.UISpec4J.init(UISpec4J.java:21)
       at org.uispec4j.UISpecTestCase.<clinit>(UISpecTestCase.java:31)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(
NativeConstructorAccessorImpl.java:39)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
DelegatingConstructorAccessorImpl.java:27)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
       at junit.framework.TestSuite.createTest(TestSuite.java:131)
       at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
       at junit.framework.TestSuite.<init>(TestSuite.java:75)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(
NativeConstructorAccessorImpl.java:39)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
DelegatingConstructorAccessorImpl.java:27)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
       at org.apache.maven.surefire.junit.JUnitTestSet.constructTestObject(
JUnitTestSet.java:148)
       at org.apache.maven.surefire.junit.JUnitTestSet.getTestCount(
JUnitTestSet.java:244)
       at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(
AbstractDirectoryTestSuite.java:101)
       at org.apache.maven.surefire.Surefire.createSuiteFromDefinition(
Surefire.java:147)
       at org.apache.maven.surefire.Surefire.run(Surefire.java:108)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(
SurefireBooter.java:225)
       at org.apache.maven.surefire.booter.SurefireBooter.main(
SurefireBooter.java:747)
###################################################################################################################


It seems to be a problem of classloader that comes from UISpec4J. I don't
know how it is managed by surefire. Perhaps it comes from this piece of code
:

##############################################################
 private static void setAwtToolkitProperty() {
   try {
     Class.forName(WINDOWS_SYSTEM_DEFAULT_VALUE);
     awtToolkit = WINDOWS_SYSTEM_DEFAULT_VALUE;
   }
   catch (ClassNotFoundException e) {
     try {
       Class.forName(UNIX_SYSTEM_DEFAULT_VALUE);
       awtToolkit = UNIX_SYSTEM_DEFAULT_VALUE;
     }
     catch (ClassNotFoundException e1) {
       throw new AWTError("Unable to locate AWT Toolkit");
     }
   }
 }
##############################################################


Has anyone have any idea about the source of my problem ? and how to resolve
this problem ? Or can anyone explain how surfire manage classloader ?

Thanks.
Olivier

Reply via email to