Skip to content

Commit

Permalink
Add test cases #397
Browse files Browse the repository at this point in the history
  • Loading branch information
mehyil committed Aug 9, 2017
1 parent 6738be9 commit fa73bde
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
46 changes: 6 additions & 40 deletions src/main/java/org/cactoos/io/ReaderOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import org.cactoos.Bytes;
Expand Down Expand Up @@ -281,72 +280,39 @@ public ReaderOf(final InputStream stream, final CharsetDecoder decoder) {
/**
* Ctor.
* @param input The input
* @param out The output
* @param output The output
*/
public ReaderOf(final Input input, final Output out) {
public ReaderOf(final Input input, final Output output) {
this(
new TeeReader(
input,
StandardCharsets.UTF_8,
out,
output,
StandardCharsets.UTF_8
)
);
}

// @checkstyle ParameterNumberCheck (8 line)
/**
* Ctor.
* @param input The input
* @param dec The input decoder
* @param out The output
* @param enc The output encoder
*/
public ReaderOf(final Input input, final CharsetDecoder dec,
final Output out, final CharsetEncoder enc) {
this(new TeeReader(input, dec.charset(), out, enc.charset()));
}

// @checkstyle ParameterNumberCheck (8 line)
/**
* Ctor.
* @param input The input
* @param inchar The input charset
* @param out The output
* @param output The output
* @param outchar The output charset
*/
public ReaderOf(final Input input, final Charset inchar,
final Output out, final Charset outchar) {
final Output output, final Charset outchar) {
this(
new TeeReader(
input,
inchar,
out,
output,
outchar
)
);
}

// @checkstyle ParameterNumberCheck (8 line)
/**
* Ctor.
* @param input The input
* @param inchar The input charset
* @param out The output
* @param outchar The output charset
*/
public ReaderOf(final Input input, final String inchar,
final Output out, final String outchar) {
this(
new TeeReader(
input,
Charset.forName(inchar),
out,
Charset.forName(outchar)
)
);
}

/**
* Ctor.
* @param rdr The reader
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/cactoos/io/TeeReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,27 @@ public void testTeeReader() throws IOException {
);
}

@Test
public void testTeeReaderWithCharset() throws IOException {
final Path src = Files.createTempFile("cactoos-3", "txt-3");
final Path dst = Files.createTempFile("cactoos-4", "txt-4");
final String content = "Cactoos!";
Files.write(src, content.getBytes(StandardCharsets.UTF_8));
final Reader reader = new ReaderOf(
new InputOf(src),
StandardCharsets.UTF_8,
new OutputTo(dst),
StandardCharsets.ISO_8859_1
);
int done = 0;
while (done >= 0) {
done = reader.read();
}
reader.close();
MatcherAssert.assertThat(
new InputOf(new ReaderOf(dst)),
new InputHasContent(content)
);
}

}

0 comments on commit fa73bde

Please sign in to comment.