File tree Expand file tree Collapse file tree
main/java/org/cactoos/collection
test/java/org/cactoos/collection Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -120,6 +120,8 @@ public int hashCode() {
120120
121121 @ Override
122122 public boolean equals (final Object obj ) {
123- return this .col .equals (obj );
123+ return this == obj
124+ || obj instanceof Immutable
125+ && this .col .equals (((Immutable <?>) obj ).col );
124126 }
125127}
Original file line number Diff line number Diff line change 44 */
55package org .cactoos .collection ;
66
7+ import java .util .Collection ;
78import java .util .List ;
89import org .cactoos .list .ListOf ;
910import org .hamcrest .MatcherAssert ;
@@ -234,4 +235,17 @@ void testEquals() {
234235 )
235236 );
236237 }
238+
239+ @ Test
240+ void equalsIsSymmetricWithPlainList () {
241+ final List <Integer > plain = new ListOf <>(1 , 2 , 3 );
242+ final Collection <Integer > wrapper = new Immutable <>(
243+ new ListOf <>(1 , 2 , 3 )
244+ );
245+ MatcherAssert .assertThat (
246+ "equals() must be symmetric between wrapper and plain list" ,
247+ wrapper .equals (plain ),
248+ new IsEqual <>(plain .equals (wrapper ))
249+ );
250+ }
237251}
You can’t perform that action at this time.
0 commit comments