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

Unexpected Behaviour: assertEquals for Iterable #543

Open
ScheintodX opened this issue Aug 10, 2014 · 0 comments
Open

Unexpected Behaviour: assertEquals for Iterable #543

ScheintodX opened this issue Aug 10, 2014 · 0 comments

Comments

@ScheintodX
Copy link

assertEquals( Iterable a, Iterable b ) usses it's own equals implementation and ignores existing equals methods.

Consider something like: (no real java code, I know)

class MyClass implements Iterable<MyPart> {
    private int myValue;
    public boolean equals( Object o ){
        return myValue == o.myValue && super.equals( o );
    }
}

assertEquals( myClass1, myClass2 ) now doesn't take myValue into account because it doesn't use the equals method but it's own implementation of that so it will report some objects as equal even if they aren't.

So in order to compare some objects which implement Iterable you have to use assertTrue( myClass1.equals( myClass2 ) ) (which will fail misserably if myClass1 is null) or assertEquals( (Object) myClass1, (Object) myClass2 )

I think this is neither obvious nor does the documentation help much because I think nearly noone will read every single documentation for assertEquals in case it does something unexpected.

In contrast e.g. AssertJ's assertThat( myClass1 ).isEqualTo( myClass2 ) uses equals method on Iterable, too.

The sensible thing to do would be to use the objects equals method even for Iterable (which does compare the content in the right way, anyway) and only if this fails use some means of inspection to report which part did fail.

lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 9, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 9, 2017
Extract parameterized test methods in AbstractTestQueries
to address differences between cassandra and other connectors.

See testng-team/testng#543.
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 9, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 9, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 9, 2017
This prevents false positive test results when comparing
iterables (most notably: MaterializedResult instances) due to
TestNG bug (testng-team/testng#543).

False-positive results were found in ~20 tests and are fixed
in the following commits.
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
Extract parameterized test methods in AbstractTestQueries
to address differences between cassandra and other connectors.

See testng-team/testng#543.
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
This prevents false positive test results when comparing
iterables (most notably: MaterializedResult instances) due to
TestNG bug (testng-team/testng#543).

False-positive results were found in ~20 tests and are fixed
in the following commits.
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
Extract parameterized test methods in AbstractTestQueries
to address differences between cassandra and other connectors.

See testng-team/testng#543.
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
lucesape pushed a commit to repairnator/repairnator-experiments that referenced this issue Apr 13, 2017
This prevents false positive test results when comparing
iterables (most notably: MaterializedResult instances) due to
TestNG bug (testng-team/testng#543).

False-positive results were found in ~20 tests and are fixed
in the following commits.
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
Extract parameterized test methods in AbstractTestQueries
to address differences between cassandra and other connectors.

See testng-team/testng#543.
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
This prevents false positive test results when comparing
iterables (most notably: MaterializedResult instances) due to
TestNG bug (testng-team/testng#543).

False-positive results were found in ~20 tests and are fixed
in the following commits.
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
Extract parameterized test methods in AbstractTestQueries
to address differences between cassandra and other connectors.

See testng-team/testng#543.
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
lucesape pushed a commit to surli/librepair-XP that referenced this issue Apr 16, 2017
This prevents false positive test results when comparing
iterables (most notably: MaterializedResult instances) due to
TestNG bug (testng-team/testng#543).

False-positive results were found in ~20 tests and are fixed
in the following commits.
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

1 participant