Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 20, 2020
2 parents 41a409c + 106cbec commit fe323a8
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 120 deletions.
36 changes: 18 additions & 18 deletions src/test/java/org/cactoos/io/InputStreamOfTest.java
Expand Up @@ -31,11 +31,11 @@
import java.nio.file.Path;
import org.cactoos.scalar.LengthOf;
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.InputHasContent;

/**
Expand All @@ -59,17 +59,17 @@ public void readsSimpleFileContent() throws IOException {
.toPath();
final String content = "Hello, товарищ!";
Files.write(temp, content.getBytes(StandardCharsets.UTF_8));
MatcherAssert.assertThat(
new Assertion<>(
"Can't read file content",
new InputOf(new InputStreamOf(temp)),
new InputHasContent(content)
);
).affirm();
}

@Test
public void readsFromReader() {
final String content = "Hello, дорогой товарищ!";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from reader",
new InputOf(new InputStreamOf(new StringReader(content))),
new InputHasContent(content)
Expand All @@ -79,7 +79,7 @@ public void readsFromReader() {
@Test
public void readsFromReaderThroughSmallBuffer() {
final String content = "Hello, صديق!";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from reader through small buffer",
new InputOf(new InputStreamOf(new StringReader(content), 1)),
new InputHasContent(content)
Expand All @@ -89,7 +89,7 @@ public void readsFromReaderThroughSmallBuffer() {
@Test
public void makesDataAvailable() throws IOException {
final String content = "Hello,חבר!";
MatcherAssert.assertThat(
new Assertion<>(
"Can't show that data is available",
new InputStreamOf(content).available(),
Matchers.greaterThan(0)
Expand All @@ -103,7 +103,7 @@ public void readsFileContent() throws Exception {
new LengthOf(
new TeeInput(content, file)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from file",
new TextOf(new InputStreamOf(file)).asString(),
Matchers.equalTo(content)
Expand All @@ -113,7 +113,7 @@ public void readsFileContent() throws Exception {
@Test
public void readsBytes() throws Exception {
final String content = "Bytes content";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from bytes",
new TextOf(new InputStreamOf(new BytesOf(content))).asString(),
Matchers.equalTo(content)
Expand All @@ -124,7 +124,7 @@ public void readsBytes() throws Exception {
public void readsBytesArray() throws Exception {
final String content = "Bytes array content";
final byte[] bytes = new BytesOf(content).asBytes();
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from byte array",
new TextOf(new InputStreamOf(bytes)).asString(),
Matchers.equalTo(content)
Expand All @@ -134,7 +134,7 @@ public void readsBytesArray() throws Exception {
@Test
public void readsText() throws Exception {
final String content = "Text content";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from text",
new TextOf(new InputStreamOf(new TextOf(content))).asString(),
Matchers.equalTo(content)
Expand All @@ -148,7 +148,7 @@ public void readsFromUri() throws Exception {
new LengthOf(
new TeeInput(content, file)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from URI",
new TextOf(new InputStreamOf(file.toURI())).asString(),
Matchers.equalTo(content)
Expand All @@ -162,7 +162,7 @@ public void readsFromUrl() throws Exception {
new LengthOf(
new TeeInput(content, file)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from URL",
new TextOf(new InputStreamOf(file.toURI().toURL())).asString(),
Matchers.equalTo(content)
Expand All @@ -173,7 +173,7 @@ public void readsFromUrl() throws Exception {
public void readsFromReaderWithMax() throws Exception {
final String content = "Reading with charset name and buffer size";
final int max = 3;
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from reader with charset name and buffer size",
new TextOf(
new InputStreamOf(
Expand All @@ -189,7 +189,7 @@ public void readsFromReaderWithMax() throws Exception {
@Test
public void readsFromReaderWithCharsetWithMax() throws Exception {
final String content = "Reading with charset and buffer size";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from reader with charset and buffer size",
new TextOf(
new InputStreamOf(
Expand All @@ -205,7 +205,7 @@ public void readsFromReaderWithCharsetWithMax() throws Exception {
@Test
public void readsFromReaderWithCharset() throws Exception {
final String content = "Content for reading with charset";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from reader with charset name",
new TextOf(
new InputStreamOf(
Expand All @@ -224,7 +224,7 @@ public void readsFromTextWithCharset() throws Exception {
new LengthOf(
new TeeInput(content, file)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from text with charset",
new TextOf(
new InputStreamOf(
Expand All @@ -239,7 +239,7 @@ public void readsFromTextWithCharset() throws Exception {
@Test
public void readsFromCharSequenceWithCharsetName() throws Exception {
final String content = "Simple content";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from char sequence with charset name",
new TextOf(
new InputStreamOf(
Expand All @@ -254,7 +254,7 @@ public void readsFromCharSequenceWithCharsetName() throws Exception {
@Test
public void readsFromCharSequenceWithCharset() throws Exception {
final String content = "Another simple content";
MatcherAssert.assertThat(
new Assertion<>(
"Can't read from char sequence with charset",
new TextOf(
new InputStreamOf(
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/cactoos/io/InputWithFallbackTest.java
Expand Up @@ -26,8 +26,8 @@
import java.io.File;
import java.io.IOException;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.EndsWith;

/**
Expand All @@ -40,7 +40,7 @@ public final class InputWithFallbackTest {

@Test
public void readsAlternativeInput() {
MatcherAssert.assertThat(
new Assertion<>(
"Can't read alternative source",
new TextOf(
new InputWithFallback(
Expand All @@ -51,12 +51,12 @@ public void readsAlternativeInput() {
)
),
new EndsWith("world!")
);
).affirm();
}

@Test
public void readsAlternativeInputUri() {
MatcherAssert.assertThat(
new Assertion<>(
"Can't read alternative source from URI",
new TextOf(
new InputWithFallback(
Expand All @@ -67,7 +67,7 @@ public void readsAlternativeInputUri() {
)
),
new EndsWith("works!")
);
).affirm();
}

}
43 changes: 22 additions & 21 deletions src/test/java/org/cactoos/io/LoggingInputTest.java
Expand Up @@ -28,15 +28,16 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.cactoos.scalar.LengthOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link LoggingInput}.
*
* @since 0.29
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
@SuppressWarnings(
{
Expand All @@ -56,11 +57,11 @@ public void logReadFromDeadInput() throws IOException {
logger
)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't log zero byte read from dead input",
logger.toString(),
Matchers.containsString("Read 0 byte(s) from dead input in")
);
).affirm();
}

@Test
Expand All @@ -73,11 +74,11 @@ public void logReadFromOneByte() throws IOException {
logger
)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't log one byte read from memory",
logger.toString(),
Matchers.containsString("Read 1 byte(s) from memory in")
);
).affirm();
}

@Test
Expand All @@ -90,11 +91,11 @@ public void logReadFromText() throws IOException {
logger
)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't log 22 bytes read from memory",
logger.toString(),
Matchers.containsString("Read 22 byte(s) from memory in")
);
).affirm();
}

@Test
Expand All @@ -107,7 +108,7 @@ public void logReadFromLargeTextFile() throws IOException {
logger
)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't log 74536 bytes read from text file",
logger.toString(),
Matchers.allOf(
Expand All @@ -117,7 +118,7 @@ public void logReadFromLargeTextFile() throws IOException {
Matchers.containsString("Read 74536 byte(s) from text file in"),
Matchers.containsString("Closed input stream from text file")
)
);
).affirm();
}

@Test
Expand All @@ -130,7 +131,7 @@ public void logAllFromLargeTextFile() throws IOException {
logger
)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"Can't log all read and close operations from text file",
logger.toString(),
Matchers.allOf(
Expand All @@ -141,7 +142,7 @@ public void logAllFromLargeTextFile() throws IOException {
Matchers.containsString("Read 74536 byte(s) from text file"),
Matchers.containsString("Closed input stream from text file")
)
);
).affirm();
}

@Test
Expand All @@ -153,11 +154,11 @@ public void logSkipFromLargeTextFile() throws Exception {
logger
// @checkstyle MagicNumber (1 line)
).stream().skip(100);
MatcherAssert.assertThat(
new Assertion<>(
"Can't log skip from text file",
logger.toString(),
Matchers.containsString("Skipped 100 byte(s) from text file.")
);
).affirm();
}

@Test
Expand All @@ -168,13 +169,13 @@ public void logAvailableFromLargeTextFile() throws Exception {
"text file",
logger
).stream().available();
MatcherAssert.assertThat(
new Assertion<>(
"Can't log avaliable byte(s) from text file",
logger.toString(),
Matchers.containsString(
"There is(are) 74536 byte(s) available from text file"
)
);
).affirm();
}

@Test
Expand All @@ -188,14 +189,14 @@ public void logResetFromLargeTextFile() throws Exception {
// @checkstyle MagicNumber (1 line)
input.mark(150);
input.reset();
MatcherAssert.assertThat(
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")
)
);
).affirm();
}

@Test
Expand All @@ -206,13 +207,13 @@ public void logMarkSupportedFromLargeTextFile() throws Exception {
"text file",
logger
).stream().markSupported();
MatcherAssert.assertThat(
new Assertion<>(
"Can't log mark and reset are not supported from text file",
logger.toString(),
Matchers.containsString(
"Mark and reset are supported from text file"
)
);
).affirm();
}

@Test
Expand All @@ -228,11 +229,11 @@ public void logIntoCreatedLogger() {
src
)
).intValue();
MatcherAssert.assertThat(
new Assertion<>(
"",
handler.toString(),
Matchers.containsString("Read 8 byte(s)")
);
).affirm();
} finally {
logger.removeHandler(handler);
}
Expand Down

2 comments on commit fe323a8

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on fe323a8 Mar 20, 2020

Choose a reason for hiding this comment

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

Puzzle 1228-b5541bca disappeared from src/test/java/org/cactoos/io/package-info.java, that's why I closed #1235. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on fe323a8 Mar 20, 2020

Choose a reason for hiding this comment

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

Puzzle 1235-b5541bca discovered in src/test/java/org/cactoos/io/package-info.java and submitted as #1331. 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.