Swing Groovy闭包在Fest中实现matcher

Swing Groovy闭包在Fest中实现matcher,swing,groovy,cucumber-jvm,fest,Swing,Groovy,Cucumber Jvm,Fest,我试图用Groovy(2.1.6)为Fest创建一个闭包匹配器,如下所示: def matcherLabel = [ isMatching: { JLabel label -> /* do something */ } ] as GenericTypeMatcher<JLabel> 有可能是我想做的吗?您的问题是GenericTypeMatcher类没有默认的零参数构造函数。将映射转换为类似于ComponentMatcher的接口。如果不能使用接口,另一种选择是子类Gener

我试图用Groovy(2.1.6)为Fest创建一个闭包匹配器,如下所示:

def matcherLabel = [ isMatching: { JLabel label -> /* do something */ } ] as GenericTypeMatcher<JLabel>

有可能是我想做的吗?

您的问题是
GenericTypeMatcher
类没有默认的零参数构造函数。将映射转换为类似于
ComponentMatcher
的接口。如果不能使用接口,另一种选择是子类
GenericTypeMatcher
,并提供一个零参数构造函数。

我想说这是可能的,因为我刚刚尝试过,并且成功了(不过创建了我自己的GenericTypeMatcher类)。你确定错误就在那一行吗?谢谢你的回复。是的,它有一个构造函数参数。在Groovy中使用构造函数参数进行强制是不可能的。所以我将使用普通类。
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Error casting map to org.fest.swing.core.GenericTypeMatcher, Reason: null
at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:7562)