Map equality using Hamcrest

后端 未结 8 2030
鱼传尺愫
鱼传尺愫 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

    This works like a charm and doesn't require two assertions like the accepted answer.

    assertThat( actualData.entrySet().toArray(), 
        arrayContainingInAnyOrder(expectedData.entrySet().toArray()) );
    

提交回复
热议问题