Fix assertSame to match semantics of == for primitive types #1523
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to address some potentially unexpected behaviour of assertSame() when passed primitive expected and actual arguments.
Currently:
Although some might argue that developers simply avoid using assertSame() with primitive types, plenty of API returns primitive values, and if assertSame() is used then the principle of "least surprise" should apply.
The solution implemented in this PR follows the rationale that:
I initially considered whether assertSame(a, b) might correspond to the (JavaScript / ECMA) semantics of a === b, (i.e. both type and value the same) however that would be quite laborious to implement due to implicit Method Invocation Conversions.
I have implemented new assertSame() functions with signatures taking boolean, long, and double primitive arguments. The aforementioned implicit Method Invocation Conversions take care of the remaining primitive types.
I realize the new assertSame(boolean, boolean) is redundant owing to the fact that assertSame(Object, Object) happens to work as expected for boxed boolean values, however it is there for consistency. If all other primitive types are spared auto-boxing when passed to assertSame() why should boolean be left out?