Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeremyk-91 opened this issue Jan 12, 2021 · 1 comment

Comments

@jeremyk-91
Copy link

jeremyk-91 commented Jan 12, 2021

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...)

@carterkozak
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants