Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 27, 2019
2 parents a834cb7 + 4afb64b commit 2ad7a56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/main/java/org/cactoos/collection/CollectionEnvelope.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/cactoos/collection/CollectionEnvelopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
Expand Down Expand Up @@ -144,6 +148,29 @@ public void differentHashCode() {
);
}

@Test
public void emptyCollectionEnvelopeShouldBeEqualToEmptyCollection() {
final CollectionEnvelope<String> envelope = new CollectionOf<>();
final Collection<String> collection = Collections.emptyList();
new Assertion<>(
"Empty envelope and collection should be equal",
() -> envelope,
new IsEqual<>(collection)
).affirm();
}

@Test
public void collectionEnvelopeShouldBeEqualToCollection() {
final CollectionEnvelope<String> envelope = new CollectionOf<>("a");
final Collection<String> collection = new ArrayList<>(1);
collection.add("a");
new Assertion<>(
"Envelope and collection should be equal",
() -> envelope,
new IsEqual<>(collection)
).affirm();
}

/**
* Custom collection.
*/
Expand Down

0 comments on commit 2ad7a56

Please sign in to comment.