0
我有两个java.util.Scanner
对象。 Scanner
类实现Iterator<String>
。我想比较扫描仪,并且很容易看到哪些线条不同。如何比较单元测试中的迭代器内容?
目前我使用AssertJ软断言这样
@Rule
JUnitSoftAssertions softly = new JUnitSoftAssertions();
...
Scanner actual = ...
Scanner expected = ...
int i = 0;
while (actual.hasNext() && expected.hasNext()) {
softly.assertThat(actual.next()).as("line %s", i++).isEqualTo(expected.next());
}
此代码insn't完美的,但无论是在一个断言做这个能力AssertJ?
我在Assertions
类中看到静态IterableAssert<ELEMENT> assertThat(Iterator<? extends ELEMENT> actual)
方法,但在IterableAssert
中看不到适当的检查方法。
Ha-ha ...我看到了这个方法,但它不能作为'expected'扫描器实现'Iterator',但'containsExactlyElementsOf'方法需要'Iterable <?作为参数扩展ELEMENT>'。 –
啊,好点。查看我的更新。 – Jeremy
@Jeramy它与我预期的略有不同,但是......谢谢! –