Using List.containsAll()
and Truth.assertThat(list).contains(originalList)
behaves differently.
Working as expected
assertThat(getItemsByChannelId.containsAll(entitiesChannelAPage2)).isTrue()
Not working as expected
assertThat(getItemsByChannelId).contains(entitiesChannelAPage2)
I am trying to verify whether the list of data class returned from query on local db are the same set of items from what was previously inserted after performing some deletion. Is there something I am missing here or the first approach is the ideal solution for such validation? I was hoping to utilize Truth's API to the utmost specially to get a meaningful error message rather than the obscure expected to be true
.
Since you want an assertion that behaves similarly to List.containsAll
, it sounds like you probably want...
assertThat(getItemsByChannelId).containsAtLeastElementsIn(entitiesChannelAPage2)
...rather than...
assertThat(getItemsByChannelId).contains(entitiesChannelAPage2)