-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid a potentially expensive reflection-based loop in assertArrayEqu…
…als, in the usual case where the arrays are in fact exactly equal.
- Loading branch information
1 parent
950702c
commit 8f59230
Showing
1 changed file
with
6 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8f59230
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is for good, but I think it breaks the philosophy of
ComparisonCriteria
class, that should delegate the comparison of each element array toassertElementsEqual()
. Consider the following example:I have array elements that implement
Object.equals(Object)
and another specific methodisEqualTo(Object)
. Assume thatelmt1.equals(elmt2) == true
butelmt1.isEqualTo(elmt2) == false
. Now I cannot implement this strategy that utilizesisEqualTo()
based onComparisonCriteria
class:I also think that this optimization is preliminary. The user of
ComparisonCriteria
should better perform this check, in this case,Assert.internalArrayEquals(String message, Object expecteds, Object actuals)
:8f59230
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComparisonCriteria is an internal class. If you want to implement your own comparison code, use Hamcrest or Truth.
8f59230
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, it's absolutely fine that
ComparisonCriteria
is implemented that way. I just wanted to underline that from my point of view the API contract is a bit vague as it assumes thatassertElementsEqual()
will be called to compare elements of the array, but due to the optimization it will not. Treat my message as a general comment, not as issue.Actually, taboo to use internal classes is generally OK, unless somebody implements the extension for jUnit to build more powerful framework.