-
-
Notifications
You must be signed in to change notification settings - Fork 683
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
Unable to compare some timestamp types #3359
Comments
Thanks for reporting it, @IUSR. The root cause is the usage of As a workaround, you can rely on assertThat(ts).isEqualTo(Timestamp.from(instant));
assertThat(ts).isAfterOrEqualTo(Timestamp.from(instant)); |
Thanks for confirming, Stefano! Yes, I am currently converting the timestamp/temporal objects into the same type and comparing them as a workaround. It'd be good when things "just work", as my experience with assertj has been :) |
I'm afraid we didn't fully solve the issue. Although the original example now works, a case with non-zero nanoseconds fails: Instant instant = Instant.ofEpochSecond(0, 1); // 1970-01-01T00:00:00.000000001Z
Timestamp timestamp = Timestamp.from(instant);
assertThat(timestamp).isEqualTo(instant); // fails I'll reopen it and have a look. |
Describe the bug
A clear and concise description of what the bug is.
Test case reproducing the bug
Some timestamp types, for example,
java.sql.Timestamp
, are not specifically handled when comparing with other temporal types, and as a result, though there are no compile-time errors caused by types, they are not effectively compared as temporals.I can see there are javadocs mentioning that comparisons are done by converting these timestamp types to
java.util.Date
, but is there a way to make this less surprising, otherwise make it a compilation error, so the user can take care of nanoseconds?Updated: I thought it was caused by nano-second precision being dropped along the assertion classes, but it turns out that there is no special handling of such types, and they end up calling
Object.equals()
.The text was updated successfully, but these errors were encountered: