diff --git a/src/main/java/org/cactoos/collection/CollectionEnvelope.java b/src/main/java/org/cactoos/collection/CollectionEnvelope.java index 3cdca5ca51..3561e0fe34 100644 --- a/src/main/java/org/cactoos/collection/CollectionEnvelope.java +++ b/src/main/java/org/cactoos/collection/CollectionEnvelope.java @@ -30,7 +30,6 @@ import org.cactoos.scalar.And; import org.cactoos.scalar.Folded; import org.cactoos.scalar.InheritanceLevel; -import org.cactoos.scalar.Or; import org.cactoos.scalar.SumOfIntScalar; import org.cactoos.scalar.UncheckedScalar; @@ -151,14 +150,10 @@ public String toString() { public final boolean equals(final Object other) { return new UncheckedScalar<>( new And( - new Or( - () -> new InheritanceLevel( - other.getClass(), Collection.class - ).value() > -1, - () -> new InheritanceLevel( - other.getClass(), CollectionEnvelope.class - ).value() > -1 - ), + () -> other != null, + () -> new InheritanceLevel( + other.getClass(), CollectionEnvelope.class + ).value() > -1, () -> { 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 fa17779ff4..37287e9932 100644 --- a/src/test/java/org/cactoos/collection/CollectionEnvelopeTest.java +++ b/src/test/java/org/cactoos/collection/CollectionEnvelopeTest.java @@ -41,7 +41,7 @@ * Iterator for IterableEnvelope `iterator()` method. * @checkstyle JavadocMethodCheck (500 lines) */ -@SuppressWarnings("PMD.AvoidDuplicateLiterals") +@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"}) public final class CollectionEnvelopeTest { @Test(expected = UnsupportedOperationException.class) public void returnsIteratorWithUnsupportedRemove() { @@ -120,6 +120,15 @@ public void equalToEmptyCollection() { ); } + @Test + public void notEqualToNull() { + MatcherAssert.assertThat( + "Empty collection equal to null", + new CollectionOf<>(), + new IsNot<>(new IsEqual<>(null)) + ); + } + @Test public void hashCodeEqual() { MatcherAssert.assertThat(