Skip to content

Commit

Permalink
Updated cactoos-matchers to 0.13, refactored test as necessary (yegor…
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Jan 20, 2019
1 parent 36c467a commit d3f328b
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 232 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The MIT License (MIT)
<dependency>
<groupId>org.llorllale</groupId>
<artifactId>cactoos-matchers</artifactId>
<version>0.12</version>
<version>0.13</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/cactoos/TextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
/**
* Test case for {@link Text}.
* @since 0.11
* @todo #1023:30min Replace all occurrences of @Rule ExpectedException
* tests that use it should be refactored to use Throws class
* introduced in cactoos-matchers 0.13.
* @checkstyle JavadocMethodCheck (500 lines)
*/
public final class TextTest {
Expand Down
16 changes: 5 additions & 11 deletions src/test/java/org/cactoos/io/BytesOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,10 @@ public void printsStackTrace() {
)
)
),
new TextHasString(
Matchers.allOf(
Matchers.containsString("java.io.IOException"),
Matchers.containsString("doesn't work at all"),
Matchers.containsString(
"\tat org.cactoos.io.BytesOfTest"
)
)
Matchers.allOf(
new TextHasString("java.io.IOException"),
new TextHasString("doesn't work at all"),
new TextHasString("\tat org.cactoos.io.BytesOfTest")
)
);
}
Expand All @@ -201,9 +197,7 @@ public void printsStackTraceFromArray() {
new IOException("").getStackTrace()
)
),
new TextHasString(
Matchers.containsString("org.cactoos.io.BytesOfTest")
)
new TextHasString("org.cactoos.io.BytesOfTest")
);
}

Expand Down
28 changes: 18 additions & 10 deletions src/test/java/org/cactoos/io/HeadInputStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.TextHasString;
import org.llorllale.cactoos.matchers.TextIs;

/**
* Test cases for {@link HeadInputStream}.
*
* @since 0.31
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumberCheck (500 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class HeadInputStreamTest {

Expand All @@ -45,11 +48,13 @@ public void testSkippingLessThanTotal() throws Exception {
5
);
stream.skip(3L);
MatcherAssert.assertThat(
new Assertion<>(
"Incorrect head of the input stream has been read",
new TextOf(stream),
() -> new TextOf(
new Sticky(() -> stream)
),
new TextHasString("tS")
);
).affirm();
}

@Test
Expand All @@ -59,11 +64,12 @@ public void testSkippingMoreThanTotal() throws Exception {
5
);
stream.skip(7L);
MatcherAssert.assertThat(
final String input = new TextOf(stream).asString();
new Assertion<>(
"The result text wasn't empty",
new TextOf(stream),
new TextHasString("")
);
() -> new TextOf(input),
new TextIs("")
).affirm();
}

@Test
Expand All @@ -74,11 +80,13 @@ public void testResetting() throws Exception {
);
stream.skip(7L);
stream.reset();
MatcherAssert.assertThat(
new Assertion<>(
"Reset didn't change the state",
new TextOf(stream),
() -> new TextOf(
new Sticky(() -> stream)
),
new TextHasString("testR")
);
).affirm();
}

@Test
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/cactoos/io/InputOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.llorllale.cactoos.matchers.EndsWith;
import org.llorllale.cactoos.matchers.InputHasContent;
import org.llorllale.cactoos.matchers.MatcherOf;
import org.llorllale.cactoos.matchers.StartsWith;
import org.llorllale.cactoos.matchers.TextHasString;
import org.takes.http.FtRemote;
import org.takes.tk.TkHtml;
Expand Down Expand Up @@ -78,7 +80,7 @@ public void readsAlternativeInputForFileCase() {
new InputOf(new TextOf("Alternative text!"))
)
),
new TextHasString(Matchers.endsWith("text!"))
new EndsWith("text!")
);
}

Expand Down Expand Up @@ -149,11 +151,9 @@ public void readsRealUrl() throws IOException {
new TextOf(
new InputOf(home)
),
new TextHasString(
Matchers.allOf(
Matchers.startsWith("<html"),
Matchers.endsWith("html>")
)
Matchers.allOf(
new StartsWith("<html"),
new EndsWith("html>")
)
)
);
Expand All @@ -173,7 +173,7 @@ public void readsStringUrl() throws IOException {
)
)
),
new TextHasString(Matchers.containsString("Lorem ipsum"))
new TextHasString("Lorem ipsum")
);
}

Expand Down
7 changes: 3 additions & 4 deletions src/test/java/org/cactoos/io/InputWithFallbackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import java.io.IOException;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.TextHasString;
import org.llorllale.cactoos.matchers.EndsWith;

/**
* Test case for {@link InputWithFallback}.
Expand All @@ -51,7 +50,7 @@ public void readsAlternativeInput() {
new InputOf("hello, world!")
)
),
new TextHasString(Matchers.endsWith("world!"))
new EndsWith("world!")
);
}

Expand All @@ -67,7 +66,7 @@ public void readsAlternativeInputUri() {
new InputOf("it works!")
)
),
new TextHasString(Matchers.endsWith("works!"))
new EndsWith("works!")
);
}

Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/cactoos/io/Md5DigestOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ public void checksumFromFile() throws Exception {
"Can't calculate the file's MD5 checksum",
new HexOf(
new Md5DigestOf(
new InputOf(
new ResourceOf(
"org/cactoos/digest-calculation.txt"
).stream()
new Sticky(
new InputOf(
new ResourceOf(
"org/cactoos/digest-calculation.txt"
).stream()
)
)
)
),
Expand Down
19 changes: 8 additions & 11 deletions src/test/java/org/cactoos/io/OutputStreamToTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.llorllale.cactoos.matchers.MatcherOf;
import org.llorllale.cactoos.matchers.TextHasString;
import org.llorllale.cactoos.matchers.TextIs;

/**
* Test case for {@link OutputStreamTo}.
Expand All @@ -54,17 +53,15 @@ public void writesLargeContentToFile() throws IOException {
MatcherAssert.assertThat(
"Can't copy Input to Output and return Input",
new TextOf(
new TeeInput(
new ResourceOf("org/cactoos/large-text.txt"),
new OutputTo(new OutputStreamTo(temp))
new Sticky(
new TeeInput(
new ResourceOf("org/cactoos/large-text.txt"),
new OutputTo(new OutputStreamTo(temp))
)
)
),
new TextHasString(
new MatcherOf<>(
str -> {
return new TextOf(temp).asString().equals(str);
}
)
new TextIs(
new TextOf(temp)
)
);
}
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/cactoos/io/Sha1DigestOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ public void checksumFromFile() throws Exception {
"Can't calculate the file's SHA-1 checksum",
new HexOf(
new Sha1DigestOf(
new InputOf(
new ResourceOf(
"org/cactoos/digest-calculation.txt"
).stream()
new Sticky(
new InputOf(
new ResourceOf(
"org/cactoos/digest-calculation.txt"
).stream()
)
)
)
),
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/cactoos/io/Sha256DigestOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ public void checksumFromFile() throws Exception {
"Can't calculate the file's SHA-256 checksum",
new HexOf(
new Sha256DigestOf(
new InputOf(
new ResourceOf(
"org/cactoos/digest-calculation.txt"
).stream()
new Sticky(
new InputOf(
new ResourceOf(
"org/cactoos/digest-calculation.txt"
).stream()
)
)
)
),
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/cactoos/io/StickyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.EndsWith;
import org.llorllale.cactoos.matchers.MatcherOf;
import org.llorllale.cactoos.matchers.TextHasString;

/**
* Test case for {@link Sticky}.
Expand Down Expand Up @@ -77,9 +77,7 @@ public void readsRealUrl() throws MalformedURLException {
)
)
),
new TextHasString(
Matchers.endsWith("est laborum.\n")
)
new EndsWith("est laborum.\n")
);
}

Expand Down
Loading

0 comments on commit d3f328b

Please sign in to comment.