To achieve the most of the fluent api with hasSameHashCodeAs the counterpart doesNotHaveSameHashCodeAs would be nice.
final Person spiderman = new Person("spiderman");
final Person otherSpiderman = new Person("spiderman");
final Person batman = new Person("batman");
assertThat(spiderman)
.hasSameHashCodeAs(otherSpiderman)
.doesNotHaveSameHashCodeAs(batman);
instead not we have to write
final Person spiderman = new Person("spiderman");
final Person otherSpiderman = new Person("spiderman");
final Person batman = new Person("batman");
assertThat(spiderman.hashCode())
.isEqualTo(otherSpiderman.hashCode())
.isNotEqualTo(batman.hashCode());
The combination of isNotEqualTo and .hashCode() with hasSameHashCodeAs is not possible.
fair enough is you rename it to doesNotHaveSameHashCodeAs ;-)
Hi, I'd like to implement this
Hi, I'd like to implement this
That is ok for me, otherwise I would implement it. But if you want, go for it :)
@mct10 up to you, let us know ;-)
@joel-costigliola @derTobsch Thanks. I will get started now :)
Sorry to bother you again, but I want to clarify my understanding of this issue. Please correct me if I misunderstand you.
I think your problem is, you cannot use assertThat(spiderman).hasSameHashCodeAs(otherSpiderman).isNotEqualTo(batman.hashCode()), so you want a doesNotHaveSameHashCodeAs implemented. However, there is already doesNotHaveSameHashCodeAs in AbstractAssert.java. And I also think you can use isNotEqualTo and .hashCode(), together with hasSameHashCodeAs.
Could you please correct my understanding? Is doesNotHaveSameHashCodeAs what you want to implement? Thanks a lot.
@mct10 good catch, I guess I don't know the AssertJ API that well :laughing:
Here's an example https://www.javadoc.io/doc/org.assertj/assertj-core/latest/org/assertj/core/api/AbstractAssert.html#doesNotHaveSameHashCodeAs(java.lang.Object).
@derTobsch I'm closing this issue since I believe this should address your issue, but I'll reopen it if you tell me it's not.
Hehe, sry. I am using 3.18.1 with the latest Spring Boot version 2.4.5 and therefore I could not see it in the IDE and I haven't checked newer versions. So therefore I am glad that it is there and will upgrade to the latest version. Thanks all! :)
Most helpful comment
@joel-costigliola @derTobsch Thanks. I will get started now :)