Skip to content

Commit

Permalink
(yegor256#1182) Remove some more static call to assert
Browse files Browse the repository at this point in the history
  • Loading branch information
victornoel committed Nov 2, 2019
1 parent 5e0da30 commit de831b8
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 175 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.17</version>
<version>0.18</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/cactoos/io/OutputStreamToTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.io.IOException;
import java.nio.file.Path;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.TextIs;

/**
Expand All @@ -50,8 +50,8 @@ public final class OutputStreamToTest {
public void writesLargeContentToFile() throws IOException {
final Path temp = this.folder.newFile("cactoos-1.txt-1")
.toPath();
MatcherAssert.assertThat(
"Can't copy Input to Output and return Input",
new Assertion<>(
"Must copy Input to Output and return Input",
new TextOf(
new Sticky(
new TeeInput(
Expand All @@ -63,7 +63,7 @@ public void writesLargeContentToFile() throws IOException {
new TextIs(
new TextOf(temp)
)
);
).affirm();
}

}
56 changes: 28 additions & 28 deletions src/test/java/org/cactoos/io/OutputToTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import org.cactoos.scalar.LengthOf;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.InputHasContent;

/**
Expand All @@ -55,11 +55,11 @@ public void writesIntoPath() throws IOException {
final Path path = temp.resolve("one/two/three/file.txt");
final String content = "Hello, товарищ!";
new LengthOf(new TeeInput(content, new OutputTo(path))).intValue();
MatcherAssert.assertThat(
"Can't write into path",
new Assertion<>(
"Must write into path",
new InputOf(path),
new InputHasContent(content)
);
).affirm();
}

@Test
Expand All @@ -70,23 +70,23 @@ public void writesIntoFile() throws IOException {
new LengthOf(
new TeeInput(txt, new SyncOutput(new OutputTo(path.toFile())))
).intValue();
MatcherAssert.assertThat(
"Can't write into file",
new Assertion<>(
"Must write into file",
new InputOf(path.toFile()),
new InputHasContent(txt)
);
).affirm();
}

@Test
public void writesIntoWriter() {
final String txt = "Hello, writer!";
final StringWriter output = new StringWriter();
new LengthOf(new TeeInput(txt, new OutputTo(output))).intValue();
MatcherAssert.assertThat(
"Can't write into writer",
new Assertion<>(
"Must write into writer",
new InputOf(output.getBuffer()),
new InputHasContent(txt)
);
).affirm();
}

@Test
Expand All @@ -96,11 +96,11 @@ public void writesIntoWriterWithCharset() {
new LengthOf(
new TeeInput(txt, new OutputTo(output, StandardCharsets.UTF_8))
).intValue();
MatcherAssert.assertThat(
"Can't write into writer with charset",
new Assertion<>(
"Must write into writer with charset",
new InputOf(output.getBuffer()),
new InputHasContent(txt)
);
).affirm();
}

@Test
Expand All @@ -110,11 +110,11 @@ public void writesIntoWriterWithCharsetByName() {
new LengthOf(
new TeeInput(txt, new OutputTo(output, StandardCharsets.UTF_8))
).intValue();
MatcherAssert.assertThat(
"Can't write into writer with charset by name",
new Assertion<>(
"Must write into writer with charset by name",
new InputOf(output.getBuffer()),
new InputHasContent(txt)
);
).affirm();
}

@Test
Expand All @@ -127,11 +127,11 @@ public void writesIntoWriterWithCharsetAndSize() {
new OutputTo(output, StandardCharsets.UTF_8, 1)
)
).intValue();
MatcherAssert.assertThat(
"Can't write into writer with charset and size",
new Assertion<>(
"Must write into writer with charset and size",
new InputOf(output.getBuffer()),
new InputHasContent(txt)
);
).affirm();
}

@Test
Expand All @@ -144,11 +144,11 @@ public void writesIntoWriterWithSize() {
new OutputTo(output, 1)
)
).intValue();
MatcherAssert.assertThat(
"Can't write into writer with size",
new Assertion<>(
"Must write into writer with size",
new InputOf(output.getBuffer()),
new InputHasContent(txt)
);
).affirm();
}

@Test
Expand All @@ -161,11 +161,11 @@ public void writesIntoWriterWithCharsetByNameAndSize() {
new OutputTo(output, StandardCharsets.UTF_8.name(), 1)
)
).intValue();
MatcherAssert.assertThat(
"Can't write into writer with charset by name and size",
new Assertion<>(
"Must write into writer with charset by name and size",
new InputOf(output.getBuffer()),
new InputHasContent(txt)
);
).affirm();
}

@Test
Expand All @@ -178,10 +178,10 @@ public void writesIntoWriterWithDecoderAndSize() {
new OutputTo(output, StandardCharsets.UTF_8.newDecoder(), 1)
)
).intValue();
MatcherAssert.assertThat(
"Can't write into writer with decoder and size",
new Assertion<>(
"Must write into writer with decoder and size",
new InputOf(output.getBuffer()),
new InputHasContent(txt)
);
).affirm();
}
}
40 changes: 14 additions & 26 deletions src/test/java/org/cactoos/io/ReaderAsBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
package org.cactoos.io;

import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.Path;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.IsTrue;
import org.llorllale.cactoos.matchers.TextIs;

/**
* Test case for {@link ReaderAsBytes}.
*
* @since 0.12
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class ReaderAsBytesTest {
/**
Expand All @@ -49,37 +49,25 @@ public final class ReaderAsBytesTest {
@Test
public void readsString() throws Exception {
final String source = "hello, друг!";
MatcherAssert.assertThat(
"Can't read string through a reader",
new Assertion<>(
"Must read string through a reader",
new TextOf(
new ReaderAsBytes(
new StringReader(source)
)
).asString(),
Matchers.equalTo(source)
);
),
new TextIs(source)
).affirm();
}

@Test
public void readsAsBytesAndDeletesTempFile() throws Exception {
final Path file = this.folder.newFile().toPath();
new ReaderAsBytes(
new ReaderOf(file)
).asBytes();
Files.delete(file);
MatcherAssert.assertThat(
Files.exists(file),
Matchers.equalTo(false)
);
}

@Test
public void readsEmptyClosableReaderAsBytes() throws Exception {
public void readsAndClosesReader() throws Exception {
final EmptyClosableReader reader = new EmptyClosableReader();
new ReaderAsBytes(reader).asBytes();
MatcherAssert.assertThat(
new Assertion<>(
"Must close the reader after reading it",
reader.isClosed(),
Matchers.equalTo(true)
);
new IsTrue()
).affirm();
}
}
Loading

0 comments on commit de831b8

Please sign in to comment.