首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >列表中的fest断言顺序

列表中的fest断言顺序
EN

Stack Overflow用户
提问于 2014-10-26 18:29:12
回答 1查看 525关注 0票数 0

我想测试列表中的元素是否按特定顺序排列。具体地说,我想测试元素中的一个成员。所以就像这样:

代码语言:javascript
复制
assertThat(listOfObjects).hasProperty(name).inOrder("one", "two", "three");

有没有可能做这样的事情?现在,我手动迭代元素,并对每个元素都有一个断言。

EN

回答 1

Stack Overflow用户

发布于 2014-10-26 18:35:22

快速浏览一下版本1的源代码(link here)后,我发现了这个方法,它声称可以做您想做的事情:

代码语言:javascript
复制
/**
 * Verifies that the actual {@code List} contains the given objects, in the same order. This method works just like
 * {@code isEqualTo(List)}, with the difference that internally the given array is converted to a {@code List}.
 *
 * @param objects the objects to look for.
 * @return this assertion object.
 * @throws AssertionError       if the actual {@code List} is {@code null}.
 * @throws NullPointerException if the given array is {@code null}.
 * @throws AssertionError       if the actual {@code List} does not contain the given objects.
 */
public @Nonnull ListAssert containsExactly(@Nonnull Object... objects) {
  checkNotNull(objects);
  return isNotNull().isEqualTo(newArrayList(objects));
}

如果我对Javadoc的理解是正确的,您应该这样做:

代码语言:javascript
复制
assertThat(listOfObjects).containsExactly(object1, object2, object3);

但请注意,此方法在2.0-M8版本中存在一些问题。As detailed here!在版本2.0-M9中解决了这些问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26572023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档