Skip to content

Commit

Permalink
Test content of file, not the content of TeeInput
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Korzhov committed May 2, 2020
1 parent edf9fe8 commit 4c45c3e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
4 changes: 0 additions & 4 deletions src/test/java/org/cactoos/io/TeeInputFromBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
* Test case for {@link TeeInput}. Cases for ctors which use
* {@link org.cactoos.Bytes} as an input.
* @since 1.0
* @todo #1341:30min Correct any TeeInput tests that are not testing if the
* path actually contains the content, just that TeeInput, as an Input,has
* the content. Solution: test the content of the file, not the content of
* teeinput (e.g. #1331).
* @checkstyle JavadocMethodCheck (100 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (100 lines)
*/
Expand Down
80 changes: 38 additions & 42 deletions src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.cactoos.scalar.LengthOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand All @@ -52,13 +54,12 @@ public void copiesFromCharArrayWithCharsetToFile() throws IOException {
final String input =
"Hello, товарищ file #1 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output))
).intValue();
new Assertion<>(
"char array must be copied to the file with charset UTF_8",
new TeeInput(
input.toCharArray(),
output,
StandardCharsets.UTF_8
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -69,13 +70,12 @@ public void copiesFromCharArrayWithCharsetByNameToFile()
final String input =
"Hello, товарищ file #2 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the file with UTF_8 charset's name",
new TeeInput(
input.toCharArray(),
output,
StandardCharsets.UTF_8.name()
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -85,12 +85,12 @@ public void copiesFromCharArrayToOutput() throws IOException {
final String input =
"Hello, товарищ output #1 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the output",
new TeeInput(
input.toCharArray(),
new OutputTo(output)
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -100,13 +100,12 @@ public void copiesFromCharArrayWithCharsetToOutput() throws IOException {
final String input =
"Hello, товарищ output #2 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the output with UTF_8 charset",
new TeeInput(
input.toCharArray(),
new OutputTo(output),
StandardCharsets.UTF_8
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -117,13 +116,12 @@ public void copiesFromCharArrayWithCharsetByNameToOutput()
final String input =
"Hello, товарищ output #3 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the output with UTF_8 charset's name",
new TeeInput(
input.toCharArray(),
new OutputTo(output),
StandardCharsets.UTF_8.name()
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -133,12 +131,12 @@ public void copiesFromCharArrayToPath() throws IOException {
final String input =
"Hello, товарищ path #1 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the path",
new TeeInput(
input.toCharArray(),
output.toPath()
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -148,13 +146,12 @@ public void copiesFromCharArrayWithCharsetToPath() throws IOException {
final String input =
"Hello, товарищ path #2 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the path with UTF_8 charset",
new TeeInput(
input.toCharArray(),
output.toPath(),
StandardCharsets.UTF_8
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -165,13 +162,12 @@ public void copiesFromCharArrayWithCharsetByNameToPath()
final String input =
"Hello, товарищ path #3 äÄ üÜ öÖ and ß";
final File output = this.folder.newFile();
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the path with UTF_8 charset's name",
new TeeInput(
input.toCharArray(),
output.toPath(),
StandardCharsets.UTF_8.name()
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand All @@ -181,12 +177,12 @@ public void copiesFromCharArrayToFile() throws IOException {
final File output = this.folder.newFile();
final String input =
"Hello, товарищ file äÄ üÜ öÖ and ß";
new LengthOf(
new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name())
).intValue();
new Assertion<>(
"char array must be copied to the file",
new TeeInput(
input.toCharArray(),
output
),
new InputOf(output),
new InputHasContent(input)
).affirm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
* Test case for {@link TeeInput}. Cases for ctors which use char sequence as
* an input.
* @since 1.0
* @todo #1360:30min Correct any TeeInput tests that are not testing if the
* path actually contains the content, just that TeeInput, as an Input,has
* the content. Solution: test the content of the file, not the content of
* teeinput (e.g. #1331).
* @checkstyle JavadocMethodCheck (215 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (215 lines)
*/
Expand Down

0 comments on commit 4c45c3e

Please sign in to comment.