assertj-automation icon indicating copy to clipboard operation
assertj-automation copied to clipboard

Integer type conversions at least for assert(Not)Equals aren't implemented

Open jeremyk-91 opened this issue 4 years ago • 1 comments

What happened?

Code of the form

byte b = (byte) 0;
assertEquals(b, 0);

passes under JUnit assertions. However, this is re-written as

byte b = (byte) 0;
assertThat(b).isEqualTo(0);

and this fails in AssertJ assertions, because the 0 there is an int, not a byte.

What did you want to happen?

The check notes that the variable being asserted on is a byte, and thus casts the integer to a byte

byte b = (byte) 0;
assertThat(b).isEqualTo((byte) 0);

There is a related case I don't know how/if you want to deal with something like

byte b = (byte) 0;
assertNotEquals(b, 88888888); // wat

since the naïve impl will not compile. Maybe just remove the line since it's always going to be true? (Someone somewhere who uses that kind of code to throw an AssertionError is screaming at me...)

jeremyk-91 avatar Jan 12 '21 20:01 jeremyk-91

It looks like this impacts conversion between most primitives, however long may be accepted as an int due to special casing in AbstractIntegerAssert.

carterkozak avatar Jan 12 '21 21:01 carterkozak