Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 28, 2018
2 parents 29244b5 + 0b44ed0 commit a1e27f3
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 85 deletions.
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,31 @@ The MIT License (MIT)
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<version>2.5</version>
<configuration>
<!--
@todo #588: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. At the end the configuration property below should be
removed so that calls to forbidden APIs fail the build.
-->
<failOnViolation>false</failOnViolation>
<signaturesFiles>
<signaturesFile>./src/test/resources/forbidden-apis.txt</signaturesFile>
</signaturesFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>testCheck</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/ProcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.concurrent.atomic.AtomicInteger;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ public void okForNoNulls() throws Exception {
MatcherAssert.assertThat(
"Can't involve the \"Proc.exec(X input)\" method",
counter.get(),
Matchers.equalTo(1)
new IsEqual<>(1)
);
}
}
8 changes: 4 additions & 4 deletions src/test/java/org/cactoos/bytes/Base64BytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Base64;
import org.cactoos.io.BytesOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;

/**
Expand All @@ -48,7 +48,7 @@ public void checkDecodeBasicDecoder() throws Exception {
"SGVsbG8h"
)
).asBytes(),
Matchers.equalTo(
new IsEqual<>(
new BytesOf("Hello!").asBytes()
)
);
Expand All @@ -63,7 +63,7 @@ public void checkDecodeUrlDecoder() throws Exception {
"SGVsbG8h"
), Base64.getUrlDecoder()
).asBytes(),
Matchers.equalTo(
new IsEqual<>(
new BytesOf("Hello!").asBytes()
)
);
Expand All @@ -78,7 +78,7 @@ public void checkDecodeMimeDecoder() throws Exception {
"SGVsbG8h"
), Base64.getMimeDecoder()
).asBytes(),
Matchers.equalTo(
new IsEqual<>(
new BytesOf("Hello!").asBytes()
)
);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/cactoos/bytes/BytesBase64Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Base64;
import org.cactoos.io.BytesOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;

/**
Expand All @@ -47,7 +47,7 @@ public void checkEncodeBasic() throws Exception {
"Hello!"
)
).asBytes(),
Matchers.equalTo(
new IsEqual<>(
new BytesOf("SGVsbG8h").asBytes()
)
);
Expand All @@ -62,7 +62,7 @@ public void checkEncodeUrl() throws Exception {
"Hello!"
), Base64.getUrlEncoder()
).asBytes(),
Matchers.equalTo(
new IsEqual<>(
new BytesOf("SGVsbG8h").asBytes()
)
);
Expand All @@ -77,7 +77,7 @@ public void checkEncodeMime() throws Exception {
"Hello!"
), Base64.getMimeEncoder()
).asBytes(),
Matchers.equalTo(
new IsEqual<>(
new BytesOf("SGVsbG8h").asBytes()
)
);
Expand Down
24 changes: 17 additions & 7 deletions src/test/java/org/cactoos/collection/BehavesAsCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
import org.cactoos.list.ListOf;
import org.hamcrest.Description;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.collection.IsCollectionWithSize;
import org.hamcrest.collection.IsEmptyCollection;
import org.hamcrest.core.IsCollectionContaining;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.llorllale.cactoos.matchers.MatcherOf;

/**
* Matcher for collection.
Expand Down Expand Up @@ -56,22 +61,27 @@ public BehavesAsCollection(final E item) {
@Override
@SuppressWarnings({ "unchecked", "PMD.ClassCastExceptionWithToArray" })
public boolean matchesSafely(final Collection<E> col) {
MatcherAssert.assertThat(col, Matchers.hasItem(this.sample));
MatcherAssert.assertThat(col, Matchers.not(Matchers.emptyIterable()));
MatcherAssert.assertThat(
col, Matchers.hasSize(Matchers.greaterThan(0))
col, new IsCollectionContaining<>(new IsEqual<>(this.sample))
);
MatcherAssert.assertThat(
col, new IsNot<>(new IsEmptyCollection<>())
);
MatcherAssert.assertThat(
col, new IsCollectionWithSize<>(new MatcherOf<>(s -> s > 0))
);
MatcherAssert.assertThat(
new ListOf<>((E[]) col.toArray()),
Matchers.hasItem(this.sample)
new IsCollectionContaining<>(new IsEqual<>(this.sample))
);
final E[] array = (E[]) new Object[col.size()];
col.toArray(array);
MatcherAssert.assertThat(
new ListOf<>(array), Matchers.hasItem(this.sample)
new ListOf<>(array),
new IsCollectionContaining<>(new IsEqual<>(this.sample))
);
MatcherAssert.assertThat(
col.containsAll(new ListOf<>(this.sample)), Matchers.is(true)
col.containsAll(new ListOf<>(this.sample)), new IsEqual<>(true)
);
return true;
}
Expand Down
35 changes: 15 additions & 20 deletions src/test/java/org/cactoos/collection/CollectionOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@

import org.cactoos.list.ListOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Ignore;
import org.junit.Test;

/**
* Test Case for {@link CollectionOf}.
*
* @since 0.23
* @todo #588:30min The test buildsCollectionFromIterator was changed
* to use BehavesAsCollection instead of Matchers.hasItem
* and it seems that actually, a CollectionOf built from an Iterator
* does not behave as a collection. This should be fixed and the @Ignore
* tag on the buildsCollectionFromIterator method removed.
* @checkstyle JavadocMethodCheck (500 lines)
*/
public final class CollectionOfTest {
Expand All @@ -44,43 +51,31 @@ public void behavesAsCollection() throws Exception {
);
}

@Test
public void buildsCollection() throws Exception {
MatcherAssert.assertThat(
"Can't build a collection",
new CollectionOf<Integer>(1, 2, 0, -1),
Matchers.hasItem(-1)
);
}

@Ignore
@Test
public void buildsCollectionFromIterator() throws Exception {
MatcherAssert.assertThat(
"Can't build a collection from iterator",
new CollectionOf<Integer>(new ListOf<>(1, 2, 0, -1).iterator()),
Matchers.hasItem(-1)
new CollectionOf<>(new ListOf<>(1, 2, 0, -1).iterator()),
new BehavesAsCollection<>(-1)
);
}

@Test
public void testToString() throws Exception {
MatcherAssert.assertThat(
"Wrong toString output. Expected \"[1, 2, 0, -1]\".",
new CollectionOf<Integer>(
new ListOf<>(1, 2, 0, -1)
).toString(),
Matchers.equalTo("[1, 2, 0, -1]")
new CollectionOf<>(new ListOf<>(1, 2, 0, -1)).toString(),
new IsEqual<>("[1, 2, 0, -1]")
);
}

@Test
public void testToStringEmpty() throws Exception {
MatcherAssert.assertThat(
"Wrong toString output. Expected \"[]\".",
new CollectionOf<Integer>(
new ListOf<>()
).toString(),
Matchers.equalTo("[]")
new CollectionOf<>(new ListOf<>()).toString(),
new IsEqual<>("[]")
);
}

Expand Down
23 changes: 13 additions & 10 deletions src/test/java/org/cactoos/collection/FilteredTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
*/
package org.cactoos.collection;

import java.util.Collections;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.LengthOf;
import org.cactoos.list.ListOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.collection.IsEmptyCollection;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.Test;

/**
Expand All @@ -36,6 +38,7 @@
* @since 0.16
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumber (500 line)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class FilteredTest {

Expand All @@ -57,7 +60,7 @@ public void filterList() {
new IterableOf<>("hello", "world", "друг")
)
).intValue(),
Matchers.equalTo(2)
new IsEqual<>(2)
);
}

Expand All @@ -66,9 +69,9 @@ public void filterEmptyList() {
MatcherAssert.assertThat(
new Filtered<String>(
input -> input.length() > 4,
Collections.emptyList()
new ListOf<>()
),
Matchers.emptyIterable()
new IsEmptyCollection<>()
);
}

Expand All @@ -79,7 +82,7 @@ public void size() throws Exception {
input -> input.length() >= 4,
new IterableOf<>("some", "text", "yes")
).size(),
Matchers.equalTo(2)
new IsEqual<>(2)
);
}

Expand All @@ -89,8 +92,8 @@ public void withItemsNotEmpty() throws Exception {
new Filtered<String>(
input -> input.length() > 4,
new IterableOf<>("first", "second")
).isEmpty(),
Matchers.equalTo(false)
),
new IsNot<>(new IsEmptyCollection<>())
);
}

Expand All @@ -100,8 +103,8 @@ public void withoutItemsIsEmpty() throws Exception {
new Filtered<String>(
input -> input.length() > 16,
new IterableOf<>("third", "fourth")
).isEmpty(),
Matchers.equalTo(true)
),
new IsEmptyCollection<>()
);
}
}
22 changes: 13 additions & 9 deletions src/test/java/org/cactoos/collection/JoinedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import org.cactoos.iterable.IterableOf;
import org.cactoos.list.ListOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.collection.IsCollectionWithSize;
import org.hamcrest.collection.IsEmptyCollection;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.Test;

/**
Expand All @@ -36,6 +39,7 @@
* @since 0.16
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumber (500 line)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
@SuppressWarnings("PMD.TooManyMethods")
public final class JoinedTest {
Expand All @@ -60,8 +64,8 @@ public void size() {
new IterableOf<>("hello", "world", "друг"),
new IterableOf<>("how", "are", "you"),
new IterableOf<>("what's", "up")
).size(),
Matchers.equalTo(8)
),
new IsCollectionWithSize<>(new IsEqual<>(8))
);
}

Expand All @@ -70,8 +74,8 @@ public void sizeEmptyReturnZero() {
MatcherAssert.assertThat(
new Joined<String>(
Collections.emptyList()
).size(),
Matchers.equalTo(0)
),
new IsCollectionWithSize<>(new IsEqual<>(0))
);
}

Expand All @@ -81,8 +85,8 @@ public void withItemsNotEmpty() throws Exception {
new Joined<String>(
new IterableOf<>("1", "2"),
new IterableOf<>("3", "4")
).isEmpty(),
Matchers.equalTo(false)
),
new IsNot<>(new IsEmptyCollection<>())
);
}

Expand All @@ -91,8 +95,8 @@ public void withoutItemsIsEmpty() throws Exception {
MatcherAssert.assertThat(
new Joined<String>(
Collections.emptyList()
).isEmpty(),
Matchers.equalTo(true)
),
new IsEmptyCollection<>()
);
}

Expand Down
Loading

2 comments on commit a1e27f3

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a1e27f3 May 28, 2018

Choose a reason for hiding this comment

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

Puzzle 588-33083ad6 discovered in src/test/java/org/cactoos/collection/CollectionOfTest.java and submitted as #902. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a1e27f3 May 28, 2018

Choose a reason for hiding this comment

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

Puzzle 588-3a40a452 discovered in pom.xml and submitted as #903. 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.