diff --git a/src/main/java/org/cactoos/collection/CollectionEnvelope.java b/src/main/java/org/cactoos/collection/CollectionEnvelope.java index 2052c53a0c..4c1a960299 100644 --- a/src/main/java/org/cactoos/collection/CollectionEnvelope.java +++ b/src/main/java/org/cactoos/collection/CollectionEnvelope.java @@ -29,7 +29,6 @@ import org.cactoos.iterator.Immutable; import org.cactoos.scalar.And; import org.cactoos.scalar.Folded; -import org.cactoos.scalar.InheritanceLevel; import org.cactoos.scalar.SumOfIntScalar; import org.cactoos.scalar.UncheckedScalar; @@ -158,9 +157,7 @@ public final boolean equals(final Object other) { return new UncheckedScalar<>( new And( () -> other != null, - () -> new InheritanceLevel( - other.getClass(), CollectionEnvelope.class - ).value() > -1, + () -> Collection.class.isAssignableFrom(other.getClass()), () -> { final Collection compared = (Collection) other; return this.size() == compared.size(); diff --git a/src/test/java/org/cactoos/collection/CollectionEnvelopeTest.java b/src/test/java/org/cactoos/collection/CollectionEnvelopeTest.java index 1fe3369940..d8a5b5f8f9 100644 --- a/src/test/java/org/cactoos/collection/CollectionEnvelopeTest.java +++ b/src/test/java/org/cactoos/collection/CollectionEnvelopeTest.java @@ -23,6 +23,9 @@ */ package org.cactoos.collection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -31,6 +34,7 @@ import org.hamcrest.core.IsEqual; import org.hamcrest.core.IsNot; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; /** * Test case for {@link CollectionEnvelope}. @@ -144,6 +148,29 @@ public void differentHashCode() { ); } + @Test + public void emptyCollectionEnvelopeShouldBeEqualToEmptyCollection() { + final CollectionEnvelope envelope = new CollectionOf<>(); + final Collection collection = Collections.emptyList(); + new Assertion<>( + "Empty envelope and collection should be equal", + () -> envelope, + new IsEqual<>(collection) + ).affirm(); + } + + @Test + public void collectionEnvelopeShouldBeEqualToCollection() { + final CollectionEnvelope envelope = new CollectionOf<>("a"); + final Collection collection = new ArrayList<>(1); + collection.add("a"); + new Assertion<>( + "Envelope and collection should be equal", + () -> envelope, + new IsEqual<>(collection) + ).affirm(); + } + /** * Custom collection. */