java – Hamcrest泛型地狱#2:iterableWithSize给出错误“不适用于参数”
|
在hamcrest(1.3.RC2,没有JUnit依赖)
我有一个(扩展)Iterator参数化了这样的内容 现在,我认为这会奏效 但它给了我错误: 方法断言(T,Matcher) 我也试过这些失败: assertThat(contents,iterableWithSize(equalTo(1)); assertThat(contents,IsIterableWithSize.< EndResult< Content>> .iterableWithSize(1)); 这些是我的进口:
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.hamcrest.collection.IsIterableWithSize;
集合的hasSize按预期工作,但对于迭代器我甚至找不到一个有效的例子…… 解决方法它应该是assertThat(contents,IsIterableWithSize.<Content>iterableWithSize(1)); iterableWithSize是在Iterable的组件类型上键入的,而不是迭代本身的具体类型. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
