用于类数据类型的EasyMock匹配器 [英] EasyMock matcher for class data type

查看:89
本文介绍了用于类数据类型的EasyMock匹配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为此和easymock作恶梦:

I am having nightmares with the syntax for this and easymock:

public void foo(Class<?> clazz);

EasyMock.expects(object.foo(EasyMock.isA(???)));

如果我的参数是String.class,我应该放什么?我最初以为:

What should I be putting if my argument is String.class? I initially thought:

EasyMock.isA((((Class<?>)(String.class))。getClass())

但是当我拨打电话foo(String.class)时,我得到了:

Yet when I make the call foo(String.class) I get:

java.lang.IllegalStateException:缺少上述方法调用的行为定义:

推荐答案

您正在尝试验证无论如何都会在运行时删除的通用类型。

You're attempting to verify a generic type that will be erased at runtime anyway.

请使用捕获对象:

Capture<Class<?>> classCapture = new Capture<Class<?>>();
EasyMock.expect(object.foo(EasyMock.capture(classCapture)));

// ... other test setup ...

Assert.assertEquals(classCapture.getValue(), String.class);

这篇关于用于类数据类型的EasyMock匹配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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