Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 20, 2019
2 parents d79a80c + 498d1dd commit a17252e
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 66 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ The MIT License (MIT)
<signaturesFile>./src/test/resources/forbidden-apis.txt</signaturesFile>
</signaturesFiles>
<!--
@todo #1082:30min In the continuation of #588, all the calls
@todo #1119:30min In the continuation of #588, all the calls
to Matchers should be replaced with their OO counterparts.
This todo should be updated with a new one until everything is
done. The newly covered classes should be added to the include
Expand All @@ -198,6 +198,7 @@ The MIT License (MIT)
<include>org/cactoos/map/*.class</include>
<include>org/cactoos/time/*.class</include>
<include>org/cactoos/collection/*.class</include>
<include>org/cactoos/experimental/*.class</include>
</includes>
</configuration>
<executions>
Expand Down
41 changes: 26 additions & 15 deletions src/test/java/org/cactoos/list/BehavesAsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import java.util.List;
import org.cactoos.collection.BehavesAsCollection;
import org.hamcrest.Description;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsNot;
import org.hamcrest.core.IsNull;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.IsTrue;
import org.llorllale.cactoos.matchers.MatcherOf;

/**
* Matcher for collection.
Expand All @@ -54,23 +57,31 @@ public BehavesAsList(final E item) {

@Override
public boolean matchesSafely(final List<E> list) {
MatcherAssert.assertThat(list.get(0), Matchers.notNullValue());
MatcherAssert.assertThat(
new Assertion<>(
"must contain at least one non-null element",
list.get(0),
new IsNot<>(new IsNull<>())
).affirm();
new Assertion<>(
"must have an index for the sample item",
list.indexOf(this.sample),
Matchers.greaterThanOrEqualTo(0)
);
MatcherAssert.assertThat(
new MatcherOf<>(i -> i >= 0)
).affirm();
new Assertion<>(
"must have a last index for the sample item",
list.lastIndexOf(this.sample),
Matchers.greaterThanOrEqualTo(0)
);
MatcherAssert.assertThat(
new MatcherOf<>(i -> i >= 0)
).affirm();
new Assertion<>(
"must have at least one element in list iterator",
list.listIterator().hasNext(),
Matchers.is(true)
);
MatcherAssert.assertThat(
new IsTrue()
).affirm();
new Assertion<>(
"must have at least one element in sublist iterator",
list.subList(0, 1).iterator().hasNext(),
Matchers.is(true)
);
new IsTrue()
).affirm();
return new BehavesAsCollection<E>(this.sample).matchesSafely(list);
}

Expand Down
21 changes: 11 additions & 10 deletions src/test/java/org/cactoos/list/JoinedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
package org.cactoos.list;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.IsTrue;

/**
* Test case for {@link org.cactoos.collection.Joined}.
Expand Down Expand Up @@ -56,7 +57,7 @@ public void size() throws Exception {
new ListOf<>(1, 2),
new ListOf<>(3, 4)
).size(),
Matchers.equalTo(4)
new IsEqual<>(4)
);
}

Expand All @@ -66,7 +67,7 @@ public void isEmpty() throws Exception {
new Joined<Integer>(
new ListOf<Integer>(5, 6)
).isEmpty(),
Matchers.equalTo(false)
new IsEqual<>(false)
);
}

Expand All @@ -78,7 +79,7 @@ public void contains() throws Exception {
new ListOf<>(7, 8),
new ListOf<>(9, element)
).contains(element),
Matchers.equalTo(true)
new IsTrue()
);
}

Expand All @@ -90,7 +91,7 @@ public void iterator() throws Exception {
new ListOf<>(element, "first"),
new ListOf<>("second", "third")
).iterator().next(),
Matchers.equalTo(element)
new IsEqual<>(element)
);
}

Expand All @@ -101,7 +102,7 @@ public void toArray() throws Exception {
new ListOf<>(11, 12),
new ListOf<>(13, 14)
).toArray(),
Matchers.equalTo(new ListOf<>(11, 12, 13, 14).toArray())
new IsEqual<>(new ListOf<>(11, 12, 13, 14).toArray())
);
}

Expand All @@ -124,7 +125,7 @@ public void containsAll() throws Exception {
new ListOf<>(first, "item3"),
new ListOf<>(second, "item4")
).containsAll(new ListOf<>(first, second)),
Matchers.equalTo(true)
new IsEqual<>(true)
);
}

Expand Down Expand Up @@ -167,7 +168,7 @@ public void get() throws Exception {
new ListOf<>("element1"),
new ListOf<>(element, "element3")
).get(1),
Matchers.equalTo(element)
new IsEqual<>(element)
);
}

Expand Down Expand Up @@ -199,7 +200,7 @@ public void subList() throws Exception {
new ListOf<>("elem1", element),
new ListOf<>("elem3", "elem4")
).subList(1, 3).iterator().next(),
Matchers.equalTo(element)
new IsEqual<>(element)
);
}

Expand All @@ -210,7 +211,7 @@ public void itemAndList() {
0,
new ListOf<>(1, 2, 3)
),
Matchers.contains(0, 1, 2, 3)
new IsEqual<>(new ListOf<>(0, 1, 2, 3))
);
}
}
22 changes: 13 additions & 9 deletions src/test/java/org/cactoos/list/ListOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.cactoos.iterable.IterableOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.Test;
import org.llorllale.cactoos.matchers.HasSize;

/**
* Test case for {@link ListOf}.
*
* @since 0.1
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumberCheck (500 lines)
*/
Expand All @@ -61,7 +63,7 @@ public void elementAtIndexTest() throws Exception {
MatcherAssert.assertThat(
"Can't convert an iterable to a list",
new ListOf<>(-1, num, 0, 1).get(1),
Matchers.equalTo(num)
new IsEqual<>(num)
);
}

Expand All @@ -73,7 +75,7 @@ public void sizeTest() throws Exception {
new ListOf<>(
Collections.nCopies(size, 0)
),
Matchers.hasSize(size)
new HasSize(size)
);
}

Expand All @@ -82,9 +84,9 @@ public void emptyTest() throws Exception {
MatcherAssert.assertThat(
"Can't convert an empty iterable to an empty list",
new ListOf<>(
Collections.emptyList()
).size(),
Matchers.equalTo(0)
new IterableOf<>()
),
new HasSize(0)
);
}

Expand All @@ -109,7 +111,7 @@ public void sensesChangesInIterable() throws Exception {
MatcherAssert.assertThat(
"Can't sense the changes in the underlying iterable",
list.size(),
Matchers.not(Matchers.equalTo(list.size()))
new IsNot<>(new IsEqual<>(list.size()))
);
}

Expand All @@ -123,11 +125,13 @@ public void makesListFromMappedIterable() throws Exception {
);
MatcherAssert.assertThat(
"Can't turn a mapped iterable into a list",
list, Matchers.iterableWithSize(4)
list,
new HasSize(4)
);
MatcherAssert.assertThat(
"Can't turn a mapped iterable into a list, again",
list, Matchers.iterableWithSize(4)
list,
new HasSize(4)
);
}

Expand Down
13 changes: 7 additions & 6 deletions src/test/java/org/cactoos/list/MappedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@
*/
package org.cactoos.list;

import java.util.Collections;
import org.cactoos.Text;
import org.cactoos.iterable.IterableOf;
import org.cactoos.text.TextOf;
import org.cactoos.text.Upper;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.HasSize;

/**
* Test case for {@link Mapped}.
* @since 0.14
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumberCheck (500 lines)
*/
Expand All @@ -60,7 +61,7 @@ public void transformsList() throws Exception {
input -> new Upper(new TextOf(input)),
new IterableOf<>("hello", "world", "друг")
).iterator().next().asString(),
Matchers.equalTo("HELLO")
new IsEqual<>("HELLO")
);
}

Expand All @@ -70,9 +71,9 @@ public void transformsEmptyList() {
"Can't transform an empty iterable",
new Mapped<String, Text>(
input -> new Upper(new TextOf(input)),
Collections.emptyList()
new IterableOf<>()
),
Matchers.emptyIterable()
new HasSize(0)
);
}

Expand All @@ -84,7 +85,7 @@ public void string() {
x -> x * 2,
new ListOf<>(1, 2, 3)
).toString(),
Matchers.equalTo("[2, 4, 6]")
new IsEqual<>("[2, 4, 6]")
);
}
}
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/list/ShuffledTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.cactoos.list;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.HasValues;

/**
* Test Case for {@link Shuffled}.
Expand Down Expand Up @@ -55,7 +55,7 @@ public void shufflesList() throws Exception {
new Shuffled<>(
new ListOf<>(1, 0, -1, -1, 2)
),
Matchers.hasItem(-1)
new HasValues<>(-1)
);
}
}
12 changes: 8 additions & 4 deletions src/test/java/org/cactoos/list/SolidTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import org.cactoos.Scalar;
import org.cactoos.iterable.IterableOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.HasSize;
import org.llorllale.cactoos.matchers.RunsInThreads;

/**
Expand Down Expand Up @@ -74,11 +75,13 @@ public void makesListFromMappedIterable() throws Exception {
);
MatcherAssert.assertThat(
"Can't turn a mapped iterable into a list",
list, Matchers.iterableWithSize(4)
list,
new HasSize(4)
);
MatcherAssert.assertThat(
"Can't turn a mapped iterable into a list, again",
list, Matchers.iterableWithSize(4)
list,
new HasSize(4)
);
}

Expand All @@ -92,7 +95,8 @@ public void mapsToSameObjects() throws Exception {
);
MatcherAssert.assertThat(
"Can't map only once",
list.get(0), Matchers.equalTo(list.get(0))
list.get(0),
new IsEqual<>(list.get(0))
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/cactoos/list/SortedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.Comparator;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;

/**
Expand Down Expand Up @@ -56,8 +56,8 @@ public void sortsCollection() throws Exception {
"one", "two", "three", "four"
)
),
Matchers.contains(
"four", "one", "three", "two"
new IsEqual<>(
new ListOf<>("four", "one", "three", "two")
)
);
}
Expand All @@ -70,7 +70,7 @@ public void takesItemFromSortedList() throws Exception {
Comparator.reverseOrder(),
"alpha", "beta", "gamma", "delta"
).get(1),
Matchers.equalTo("delta")
new IsEqual<>("delta")
);
}

Expand Down
Loading

2 comments on commit a17252e

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a17252e Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1082-fd48e847 disappeared from pom.xml, that's why I closed #1119. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a17252e Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1119-fd48e847 discovered in pom.xml and submitted as #1166. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.