我们正在尝试扩展UISpec4j测试框架以在运行测试时显示用户界面。所以我们有一个自定义工具包,它围绕相关平台的本机工具包。我们设法让一切在 Windows XP 上运行良好,但是在 OSX 上测试我们的更改时,我们的 createFrame 扩展似乎表现得很奇怪:
public FramePeer createFrame(Frame target) {
FramePeer resultc = new UISpecFramePeer(target);
//super.createFrame(target);
return resultc;
}
从本质上讲,我们想创建一个 UISpecFramePeer 作为拦截类......这样 UISpec4j 就可以询问 UI 中发生的事情。但是在我们的更改中,我们还希望显示 UI。因此,我们尝试通过使用本机工具包创建一个框架并将其包装在 UISpecFramePeer 中(上面的代码中未显示)。
当我们运行上面的代码时,测试运行(如我们所料)但显然没有显示任何内容。但是,当我们包含 super.createFrame(target) 时。我们得到以下异常:
SEVERE: Application class org.openshapa.OpenSHAPA failed to launch
java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:236)
at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at java.awt.Component.firePropertyChange(Component.java:7277)
at javax.swing.JComponent.addNotify(JComponent.java:4479)
at javax.swing.JRootPane.addNotify(JRootPane.java:680)
at java.awt.Container.addNotify(Container.java:2544)
at java.awt.Window.addNotify(Window.java:467)
at java.awt.Frame.addNotify(Frame.java:501)
at java.awt.Window.pack(Window.java:485)
at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
at org.jdesktop.application.Application$1.run(Application.java:171)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-2" java.lang.Error: Application class org.openshapa.OpenSHAPA failed to launch
at org.jdesktop.application.Application$1.run(Application.java:177)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:236)
at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at java.awt.Component.firePropertyChange(Component.java:7277)
at javax.swing.JComponent.addNotify(JComponent.java:4479)
at javax.swing.JRootPane.addNotify(JRootPane.java:680)
at java.awt.Container.addNotify(Container.java:2544)
at java.awt.Window.addNotify(Window.java:467)
at java.awt.Frame.addNotify(Frame.java:501)
at java.awt.Window.pack(Window.java:485)
at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
at org.jdesktop.application.Application$1.run(Application.java:171)
... 7 more
为什么简单地使用本机工具包创建一个框架(但不返回它)会创建一个异常,而当 super.createFrame 被注释时它会正常运行?