Skip to content

Commit

Permalink
Replace calls to Matchers with their OO counterparts yegor256#1434
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier B. OURA committed Apr 5, 2021
1 parent 3e37919 commit f3d3400
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 85 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ The MIT License (MIT)
<signaturesFile>./src/test/resources/forbidden-apis.txt</signaturesFile>
</signaturesFiles>
<!--
@todo #1223:30min In the continuation of #588, all the calls
@todo #1434: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 @@ -270,6 +270,7 @@ The MIT License (MIT)
<include>org/cactoos/collection/*.class</include>
<include>org/cactoos/experimental/*.class</include>
<include>org/cactoos/func/*.class</include>
<include>org/cactoos/io/*.class</include>
</includes>
</configuration>
<executions>
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/io/DeadOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.cactoos.io;

import org.hamcrest.Matchers;
import org.hamcrest.core.StringEndsWith;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.HasContent;
Expand All @@ -45,7 +45,7 @@ void readsEmptyContent() {
new InputOf("How are you, мой друг?"),
new DeadOutput()
),
new HasContent(Matchers.endsWith("друг?"))
new HasContent(new StringEndsWith("друг?"))
).affirm();
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/io/InputStreamOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import org.cactoos.bytes.BytesOf;
import org.cactoos.scalar.LengthOf;
import org.cactoos.text.TextOf;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.HasContent;
import org.llorllale.cactoos.matchers.Verifies;

/**
* Test case for {@link InputStreamOf}.
Expand Down Expand Up @@ -94,7 +94,7 @@ public void makesDataAvailable() throws IOException {
new Assertion<>(
"Must show that data is available",
new InputStreamOf(content).available(),
Matchers.greaterThan(0)
new Verifies<>(x -> x > 0)
).affirm();
}

Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/cactoos/io/LSInputOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/
package org.cactoos.io;

import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.StringContains;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;

Expand All @@ -43,7 +44,7 @@ void readsSimpleInput() {
new LSInputOf(
new InputOf("hello, world!")
).getStringData(),
Matchers.endsWith("world!")
new StringContains("world!")
).affirm();
}

Expand All @@ -57,7 +58,7 @@ void readsBiggerInput() {
new SlowInputStream(size)
)
).getStringData().length(),
Matchers.equalTo(size)
new IsEqual<>(size)
).affirm();
}

Expand All @@ -71,7 +72,7 @@ void countsBytesInBiggerInput() {
new SlowInputStream(size)
)
).getStringData().length(),
Matchers.equalTo(size)
new IsEqual<>(size)
).affirm();
}

Expand Down
73 changes: 40 additions & 33 deletions src/test/java/org/cactoos/io/LoggingInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.cactoos.Text;
import org.cactoos.scalar.LengthOf;
import org.hamcrest.Matchers;
import org.cactoos.text.TextOf;
import org.hamcrest.core.AllOf;
import org.hamcrest.core.IsNot;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.HasString;

/**
* Test case for {@link LoggingInput}.
Expand Down Expand Up @@ -58,8 +62,8 @@ void logReadFromDeadInput() throws Exception {
).value();
new Assertion<>(
"Can't log zero byte read from dead input",
logger.toString(),
Matchers.containsString("Read 0 byte(s) from dead input in")
new TextOf(logger.toString()),
new HasString("Read 0 byte(s) from dead input in")
).affirm();
}

Expand All @@ -75,8 +79,8 @@ void logReadFromOneByte() throws Exception {
).value();
new Assertion<>(
"Can't log one byte read from memory",
logger.toString(),
Matchers.containsString("Read 1 byte(s) from memory in")
new TextOf(logger.toString()),
new HasString("Read 1 byte(s) from memory in")
).affirm();
}

Expand All @@ -92,12 +96,13 @@ void logReadFromText() throws Exception {
).value();
new Assertion<>(
"Can't log 22 bytes read from memory",
logger.toString(),
Matchers.containsString("Read 22 byte(s) from memory in")
new TextOf(logger.toString()),
new HasString("Read 22 byte(s) from memory in")
).affirm();
}

@Test
@SuppressWarnings("unchecked")
void logReadFromLargeTextFile() throws Exception {
final Logger logger = new FakeLogger();
new LengthOf(
Expand All @@ -109,18 +114,19 @@ void logReadFromLargeTextFile() throws Exception {
).value();
new Assertion<>(
"Can't log 74536 bytes read from text file",
logger.toString(),
Matchers.allOf(
Matchers.not(
Matchers.containsString("Read 16384 byte(s) from text file")
new TextOf(logger.toString()),
new AllOf<>(
new IsNot<Text>(
new HasString("Read 16384 byte(s) from text file")
),
Matchers.containsString("Read 74536 byte(s) from text file in"),
Matchers.containsString("Closed input stream from text file")
new HasString("Read 74536 byte(s) from text file in"),
new HasString("Closed input stream from text file")
)
).affirm();
}

@Test
@SuppressWarnings("unchecked")
void logAllFromLargeTextFile() throws Exception {
final Logger logger = new FakeLogger(Level.WARNING);
new LengthOf(
Expand All @@ -132,14 +138,14 @@ void logAllFromLargeTextFile() throws Exception {
).value();
new Assertion<>(
"Can't log all read and close operations from text file",
logger.toString(),
Matchers.allOf(
Matchers.containsString("Read 16384 byte(s) from text file"),
Matchers.containsString("Read 32768 byte(s) from text file"),
Matchers.containsString("Read 49152 byte(s) from text file"),
Matchers.containsString("Read 65536 byte(s) from text file"),
Matchers.containsString("Read 74536 byte(s) from text file"),
Matchers.containsString("Closed input stream from text file")
new TextOf(logger.toString()),
new AllOf<>(
new HasString("Read 16384 byte(s) from text file"),
new HasString("Read 32768 byte(s) from text file"),
new HasString("Read 49152 byte(s) from text file"),
new HasString("Read 65536 byte(s) from text file"),
new HasString("Read 74536 byte(s) from text file"),
new HasString("Closed input stream from text file")
)
).affirm();
}
Expand All @@ -155,8 +161,8 @@ void logSkipFromLargeTextFile() throws Exception {
).stream().skip(100);
new Assertion<>(
"Can't log skip from text file",
logger.toString(),
Matchers.containsString("Skipped 100 byte(s) from text file.")
new TextOf(logger.toString()),
new HasString("Skipped 100 byte(s) from text file.")
).affirm();
}

Expand All @@ -170,14 +176,15 @@ void logAvailableFromLargeTextFile() throws Exception {
).stream().available();
new Assertion<>(
"Can't log avaliable byte(s) from text file",
logger.toString(),
Matchers.containsString(
new TextOf(logger.toString()),
new HasString(
"There is(are) 74536 byte(s) available from text file"
)
).affirm();
}

@Test
@SuppressWarnings("unchecked")
void logResetFromLargeTextFile() throws Exception {
final Logger logger = new FakeLogger();
final InputStream input = new LoggingInput(
Expand All @@ -190,10 +197,10 @@ void logResetFromLargeTextFile() throws Exception {
input.reset();
new Assertion<>(
"Can't log mark and reset from text file",
logger.toString(),
Matchers.allOf(
Matchers.containsString("Marked position 150 from text file"),
Matchers.containsString("Reset input stream from text file")
new TextOf(logger.toString()),
new AllOf<>(
new HasString("Marked position 150 from text file"),
new HasString("Reset input stream from text file")
)
).affirm();
}
Expand All @@ -208,8 +215,8 @@ void logMarkSupportedFromLargeTextFile() throws Exception {
).stream().markSupported();
new Assertion<>(
"Can't log mark and reset are not supported from text file",
logger.toString(),
Matchers.containsString(
new TextOf(logger.toString()),
new HasString(
"Mark and reset are supported from text file"
)
).affirm();
Expand All @@ -230,8 +237,8 @@ void logIntoCreatedLogger() throws Exception {
).value();
new Assertion<>(
"",
handler.toString(),
Matchers.containsString("Read 8 byte(s)")
new TextOf(handler.toString()),
new HasString("Read 8 byte(s)")
).affirm();
} finally {
logger.removeHandler(handler);
Expand Down
36 changes: 20 additions & 16 deletions src/test/java/org/cactoos/io/LoggingOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import java.util.logging.Logger;
import org.cactoos.bytes.BytesOf;
import org.cactoos.scalar.LengthOf;
import org.hamcrest.Matchers;
import org.hamcrest.core.AllOf;
import org.hamcrest.core.IsNot;
import org.hamcrest.core.StringContains;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -72,7 +74,7 @@ public void logWriteZero() throws Exception {
new Assertion<>(
"Can't log zero byte written to memory",
logger.toString(),
Matchers.containsString("Written 0 byte(s) to memory in ")
new StringContains("Written 0 byte(s) to memory in ")
).affirm();
}

Expand All @@ -91,7 +93,7 @@ public void logWriteOneByte() throws Exception {
new Assertion<>(
"Can't log one byte written to memory",
logger.toString(),
Matchers.containsString("Written 1 byte(s) to memory in")
new StringContains("Written 1 byte(s) to memory in")
).affirm();
}

Expand All @@ -110,11 +112,12 @@ public void logWriteText() throws Exception {
new Assertion<>(
"Can't log 22 bytes written to memory",
logger.toString(),
Matchers.containsString("Written 22 byte(s) to memory in")
new StringContains("Written 22 byte(s) to memory in")
).affirm();
}

@Test
@SuppressWarnings("unchecked")
public void logWriteToLargeTextFile() throws Exception {
final Logger logger = new FakeLogger();
final Path temp = this.folder.newFolder("ccts-1").toPath();
Expand All @@ -135,19 +138,20 @@ public void logWriteToLargeTextFile() throws Exception {
new Assertion<>(
"Can't log write and close operations to text file",
logger.toString(),
Matchers.allOf(
Matchers.not(
Matchers.containsString(
new AllOf<>(
new IsNot<String>(
new StringContains(
"Written 16384 byte(s) to text file"
)
),
Matchers.containsString("Written 74536 byte(s) to text file"),
Matchers.containsString("Closed output stream from text file")
new StringContains("Written 74536 byte(s) to text file"),
new StringContains("Closed output stream from text file")
)
).affirm();
}

@Test
@SuppressWarnings("unchecked")
public void logAllWriteToLargeTextFile() throws Exception {
final Logger logger = new FakeLogger(Level.WARNING);
final Path temp = this.folder.newFolder("ccts-2").toPath();
Expand All @@ -168,13 +172,13 @@ public void logAllWriteToLargeTextFile() throws Exception {
new Assertion<>(
"Can't log all write and close operations to text file",
logger.toString(),
Matchers.allOf(
Matchers.containsString("Written 16384 byte(s) to text file"),
Matchers.containsString("Written 32768 byte(s) to text file"),
Matchers.containsString("Written 49152 byte(s) to text file"),
Matchers.containsString("Written 65536 byte(s) to text file"),
Matchers.containsString("Written 74536 byte(s) to text file"),
Matchers.containsString("Closed output stream from text file")
new AllOf<>(
new StringContains("Written 16384 byte(s) to text file"),
new StringContains("Written 32768 byte(s) to text file"),
new StringContains("Written 49152 byte(s) to text file"),
new StringContains("Written 65536 byte(s) to text file"),
new StringContains("Written 74536 byte(s) to text file"),
new StringContains("Closed output stream from text file")
)
).affirm();
}
Expand Down
Loading

0 comments on commit f3d3400

Please sign in to comment.