在Fest中实现matcher的Groovy闭包

时间:2013-08-26 19:25:35

标签: swing groovy cucumber-jvm fest

我正在尝试使用Groovy(2.1.6)为Fest创建一个闭包匹配器:

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

GenericTypeMatcher是一个抽象类,只有一个方法可以实现(isMatching(T t))

但是我收到了这个错误:

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)

我想做的可能吗?

1 个答案:

答案 0 :(得分:9)

您的问题是GenericTypeMatcher类没有默认的零参数构造函数。将地图转换为ComponentMatcher等界面。如果你不能使用接口,另一个选择是子类GenericTypeMatcher并提供一个零参数构造函数。