Map equality using Hamcrest

后端 未结 8 2032
鱼传尺愫
鱼传尺愫 2021-02-06 20:25

I\'d like to use hamcrest to assert that two maps are equal, i.e. they have the same set of keys pointing to the same values.

My current best guess is:

a         


        
8条回答
  •  猫巷女王i
    2021-02-06 21:22

    A quite simple way is to use a utility method from Guava's com.google.common.collect.Maps class.

    assertThat(Maps.difference(map1,map2).areEqual(),is(true));
    

提交回复
热议问题