Map equality using Hamcrest

后端 未结 8 2023
鱼传尺愫
鱼传尺愫 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条回答
  • 2021-02-06 21:18

    Hamcrest now has a Matcher for size collection.

    org.hamcrest.collection.IsCollectionWithSize

    0 讨论(0)
  • 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));
    
    0 讨论(0)
提交回复
热议问题