我如何断言两个HashMap与Javabean值相等? [英] How do I assert that two HashMap with Javabean values are equal?

查看:578
本文介绍了我如何断言两个HashMap与Javabean值相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 HashMap< Integer,Question> 地图,我想比较。 问题在这种情况下是我写的Javabean。



如何断言 HashMap 是否相等?在这种情况下,等于意味着 HashMap 包含完全相同的问题 bean?


解决方案

如果它在所有相关的,我正在使用JUnit写一个单元测试。解决方案我最终最终使用它完美地用于单元测试目的。

  for(Map.Entry< Integer,Question& questionMap.entrySet()){
assertReflectionEquals(entry.getValue(),expectedQuestionMap.get(entry.getKey()),ReflectionComparatorMode.LENIENT_ORDER);
}

这包括调用 assertReflectionEquals() unitils 包。

 < dependency> 
< groupId> org.unitils< / groupId>
< artifactId> unitils-core< / artifactId>
< version> 3.3< / version>
< scope> test< / scope>
< / dependency>


I have two HashMap<Integer, Question> maps that I would like to compare. Question in this case is a Javabean I have written.

How do I assert that both HashMap are equal? In this scenario, equal means that both HashMap contains exactly the same Question bean?

If it's at all relevant, I am writing a unit test using JUnit.

解决方案

Here is the solution I eventually ended up using which worked perfectly for unit testing purposes.

for(Map.Entry<Integer, Question> entry : questionMap.entrySet()) {
    assertReflectionEquals(entry.getValue(), expectedQuestionMap.get(entry.getKey()), ReflectionComparatorMode.LENIENT_ORDER);
}

This involves invoking assertReflectionEquals() from the unitils package.

<dependency>
    <groupId>org.unitils</groupId>
    <artifactId>unitils-core</artifactId>
    <version>3.3</version>
    <scope>test</scope>
</dependency>

这篇关于我如何断言两个HashMap与Javabean值相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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