Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#1434) Replace calls to Matchers with their OO counterparts #1581

Merged
merged 3 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
91 changes: 49 additions & 42 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 @@ -57,9 +61,9 @@ 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")
"Must log zero byte read from dead input",
new TextOf(logger.toString()),
new HasString("Read 0 byte(s) from dead input in")
).affirm();
}

Expand All @@ -74,9 +78,9 @@ 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")
"Must log one byte read from memory",
new TextOf(logger.toString()),
new HasString("Read 1 byte(s) from memory in")
).affirm();
}

Expand All @@ -91,13 +95,14 @@ 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")
"Must log 22 bytes read from memory",
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 @@ -108,19 +113,20 @@ 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")
"Must log 74536 bytes read 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 @@ -131,15 +137,15 @@ 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")
"Must log all read and close operations 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 @@ -154,9 +160,9 @@ void logSkipFromLargeTextFile() throws Exception {
// @checkstyle MagicNumber (1 line)
).stream().skip(100);
new Assertion<>(
"Can't log skip from text file",
logger.toString(),
Matchers.containsString("Skipped 100 byte(s) from text file.")
"Must log skip from text file",
new TextOf(logger.toString()),
new HasString("Skipped 100 byte(s) from text file.")
).affirm();
}

Expand All @@ -169,15 +175,16 @@ void logAvailableFromLargeTextFile() throws Exception {
logger
).stream().available();
new Assertion<>(
"Can't log avaliable byte(s) from text file",
logger.toString(),
Matchers.containsString(
"Must log avaliable byte(s) from text file",
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 @@ -189,11 +196,11 @@ void logResetFromLargeTextFile() throws Exception {
input.mark(150);
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")
"Must log mark and reset 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 @@ -207,9 +214,9 @@ void logMarkSupportedFromLargeTextFile() throws Exception {
logger
).stream().markSupported();
new Assertion<>(
"Can't log mark and reset are not supported from text file",
logger.toString(),
Matchers.containsString(
"Must log mark and reset are not supported from text file",
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
46 changes: 25 additions & 21 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 @@ -70,9 +72,9 @@ public void logWriteZero() throws Exception {
)
).value();
new Assertion<>(
"Can't log zero byte written to memory",
"Must log write 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 @@ -89,9 +91,9 @@ public void logWriteOneByte() throws Exception {
out.write(new BytesOf("a").asBytes());
}
new Assertion<>(
"Can't log one byte written to memory",
"Must 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 @@ -108,13 +110,14 @@ public void logWriteText() throws Exception {
out.write(new BytesOf("Hello, товарищ!").asBytes());
}
new Assertion<>(
"Can't log 22 bytes written to memory",
"Must 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 @@ -133,21 +136,22 @@ public void logWriteToLargeTextFile() throws Exception {
).value();
}
new Assertion<>(
"Can't log write and close operations to text file",
"Must 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 @@ -166,15 +170,15 @@ public void logAllWriteToLargeTextFile() throws Exception {
).value();
}
new Assertion<>(
"Can't log all write and close operations to text file",
"Must 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