Groovy封闭以在Fest中实现匹配器 [英] Groovy closure to implement matcher in Fest

查看:90
本文介绍了Groovy封闭以在Fest中实现匹配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a closure matcher for Fest with Groovy (2.1.6) like this:

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

GenericTypeMatcher是一个抽象类,仅具有一种实现方法(isMatching(T t))

GenericTypeMatcher is an abstract class with one method only to implement (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)

是否可能要尝试?

推荐答案

您的问题是 GenericTypeMatcher 类没有默认的零参数构造函数。将地图强制转换为 ComponentMatcher 之类的接口。如果您不能使用接口,则另一种方法是将 GenericTypeMatcher 子类化并提供零参数构造函数。

Your problem is that the GenericTypeMatcher class doesn't have a default, zero-parameter constructor. Cast the map to an interface like ComponentMatcher instead. If you can't use an interface, another alternative is to subclass GenericTypeMatcher and provide a zero-parameter constructor.

这篇关于Groovy封闭以在Fest中实现匹配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆