joel-costigliola / assertj

AssertJ documentation
60 stars 30 forks source link

Better support comparing lists / iterable objects #46

Closed sta-szek closed 8 years ago

sta-szek commented 8 years ago

There is new feature in 3.4.0 version: assertThat(...).isEqualToComparingFieldByFieldRecursively(...)

but comparing lists is still poor, because we have to use equals(...) method when comparing two objects - it is used by default?

We would like to have methods like:

assertThat(<some iterable>).containsExactlyElementsOf(<some iterable>) - already provided. assertThat(<some iterable>).containsExactlyElementsOfComparingFieldByField(<some iterable>) - really missing :+1: assertThat(<some iterable>).containsExactlyElementsOfComparingFieldByFieldRecursively(<some iterable>) - missing too :+1: :+1: :)

BTW, if possible, I could do this.

sta-szek commented 8 years ago

Oww this is wrong project :)) I think i can do this by contributing https://github.com/joel-costigliola/assertj-core :+1:

PascalSchumacher commented 8 years ago

Hi sta-szek,

I think the underlying code already allows this, but getting access to the code is ugly:

assertThat((Object) Arrays.asList("a", "c")).isEqualToComparingFieldByFieldRecursively(Arrays.asList("a", "c"));
assertThat((Object) Arrays.asList("a", "c")).isEqualToComparingFieldByField(Arrays.asList("a", "c"));
sta-szek commented 8 years ago

Hi, that's right, the invocation is really ugly, but what if you have ArrayList and for example Iterable or some other type of List. It compares also Lists internal state instead of only objects on the list. When I got some time, and nobody do this, i try to implement that.

PascalSchumacher commented 8 years ago

Yes, it does not work with different types of lists.

By the way, it would be nice if you could create an issue at https://github.com/joel-costigliola/assertj-core/issues

Thanks, Pascal

sta-szek commented 8 years ago

Here it is https://github.com/joel-costigliola/assertj-core/issues/636