尝试通过预先将两个映射转换为列表来测试它们的相等性(包括顺序)。可能有更好的方法来做到这一点,但我想知道为什么会出现这个错误。这是测试:
@Test
public void sortedEntriesTest() {
List<Map.Entry<String, AtomicInteger>> actualList = stream.sortedEntries(stream.getMap());
List<Map.Entry<String, AtomicInteger>> expectedList =
expectedMap.entrySet()
.stream()
.sorted(Comparator.comparingInt(e -> -e.getValue().get()))
.collect(Collectors.toList());
Assert.assertThat(expectedList, is(actualList));
}
这是错误:
java.lang.AssertionError:
Expected: is <[file=1, for=1, project=1, is=1, an=1, just=1, example=1, this=2]>
but: was <[file=1, for=1, project=1, is=1, an=1, just=1, example=1, this=2]>
Expected :is <[file=1, for=1, project=1, is=1, an=1, just=1, example=1, this=2]>
Actual :<[file=1, for=1, project=1, is=1, an=1, just=1, example=1, this=2]>
最佳答案
尝试
Assert.assertThat(expectedList, is(equalTo(actualList)));
相反。
关于java - 无法理解的 JUnit 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49807017/