diff --git a/src/main/java/org/cactoos/io/TeeInput.java b/src/main/java/org/cactoos/io/TeeInput.java index b7ca5570e6..943cb2f1a6 100644 --- a/src/main/java/org/cactoos/io/TeeInput.java +++ b/src/main/java/org/cactoos/io/TeeInput.java @@ -45,9 +45,6 @@ * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @since 0.1 - * @todo #631:30min This class needs more test cases. Currently, only a set of - * ctors is covered by tests: ctors which use Bytes and byte array as an - * input. All other ctors should be covered too. */ public final class TeeInput implements Input { diff --git a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java new file mode 100644 index 0000000000..3da56cb1f1 --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java @@ -0,0 +1,214 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use char array as an + * input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (215 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (215 lines) + */ +public final class TeeInputFromCharArrayTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromCharArrayWithCharsetToFile() throws IOException { + final String input = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + output, + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayWithCharsetByNameToFile() + throws IOException { + final String input = + "Hello, товарищ file #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + output, + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayToOutput() throws IOException { + final String input = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + new OutputTo(output) + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayWithCharsetToOutput() throws IOException { + final String input = + "Hello, товарищ output #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + new OutputTo(output), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayWithCharsetByNameToOutput() + throws IOException { + final String input = + "Hello, товарищ output #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + new OutputTo(output), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayToPath() throws IOException { + final String input = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + output.toPath() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayWithCharsetToPath() throws IOException { + final String input = + "Hello, товарищ path #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + output.toPath(), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayWithCharsetByNameToPath() + throws IOException { + final String input = + "Hello, товарищ path #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + output.toPath(), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharArrayToFile() throws IOException { + final File output = this.folder.newFile(); + final String input = + "Hello, товарищ file äÄ üÜ öÖ and ß"; + MatcherAssert.assertThat( + new TeeInput( + input.toCharArray(), + output + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromCharSequenceTest.java b/src/test/java/org/cactoos/io/TeeInputFromCharSequenceTest.java new file mode 100644 index 0000000000..31539c584a --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromCharSequenceTest.java @@ -0,0 +1,214 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use char sequence as + * an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (215 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (215 lines) + */ +public final class TeeInputFromCharSequenceTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromCharSequenceToFile() throws IOException { + final String input = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceWithCharsetToFile() throws IOException { + final String input = + "Hello, товарищ file #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output, + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceWithCharsetByNameToFile() + throws IOException { + final String input = + "Hello, товарищ file #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output, + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceToPath() throws IOException { + final String input = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceWithCharsetToPath() throws IOException { + final String input = + "Hello, товарищ path #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output.toPath(), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceWithCharsetByNameToPath() + throws IOException { + final String input = + "Hello, товарищ path #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output.toPath(), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceToOutput() throws IOException { + final String input = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + new OutputTo(output) + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceWithCharsetToOutput() throws IOException { + final String input = + "Hello, товарищ output #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + new OutputTo(output), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromCharSequenceWithCharsetByNameToOutput() + throws IOException { + final String input = + "Hello, товарищ output #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + new OutputTo(output), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromFileTest.java b/src/test/java/org/cactoos/io/TeeInputFromFileTest.java new file mode 100644 index 0000000000..72e3b3da0c --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromFileTest.java @@ -0,0 +1,118 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use file as an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (120 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (120 lines) + */ +public final class TeeInputFromFileTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromFileToFile() throws IOException { + final String message = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromFileToPath() throws IOException { + final String message = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + output.toPath() + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromFileToOutput() throws IOException { + final String message = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input, + new OutputTo(output) + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromInputTest.java b/src/test/java/org/cactoos/io/TeeInputFromInputTest.java new file mode 100644 index 0000000000..9a719324d1 --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromInputTest.java @@ -0,0 +1,196 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use + * {@link org.cactoos.Input} as an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (200 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (200 lines) + */ +public final class TeeInputFromInputTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromInputToPath() throws IOException { + final String input = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + output.toPath() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromInputToFile() throws IOException { + final String input = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + output + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromInputToWriter() throws IOException { + final String input = + "Hello, товарищ write #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + new WriterTo(output) + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromInputWithSizeToWriter() throws IOException { + final String input = + "Hello, товарищ writer #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + new WriterTo(output), + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromInputWithCharsetToWriter() throws IOException { + final String input = + "Hello, товарищ writer #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + new WriterTo(output), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromInputWithCharsetAndSizeToWriter() throws IOException { + final String input = + "Hello, товарищ writer #4 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + new WriterTo(output), + StandardCharsets.UTF_8, + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromInputWithCharsetByNameToWriter() throws IOException { + final String input = + "Hello, товарищ writer #5 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + new WriterTo(output), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromInputWithCharsetByNameAndSizeToWriter() + throws Exception { + final String input = + "Hello, товарищ writer #6 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new InputOf(input), + new WriterTo(output), + StandardCharsets.UTF_8.name(), + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromPathTest.java b/src/test/java/org/cactoos/io/TeeInputFromPathTest.java new file mode 100644 index 0000000000..e3716877fb --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromPathTest.java @@ -0,0 +1,120 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use {@link Path} as + * an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (120 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (120 lines) + */ +public final class TeeInputFromPathTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromPathToPath() throws IOException { + final String message = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toPath(), + output.toPath() + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromPathToFile() throws IOException { + final String message = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toPath(), + output + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromPathToOutput() throws IOException { + final String message = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toPath(), + new OutputTo(output) + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromReaderTest.java b/src/test/java/org/cactoos/io/TeeInputFromReaderTest.java new file mode 100644 index 0000000000..946048c629 --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromReaderTest.java @@ -0,0 +1,384 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use + * {@link java.io.Reader} as an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (400 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (400 lines) + */ +@SuppressWarnings("PMD.TooManyMethods") +public final class TeeInputFromReaderTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromReaderToFile() throws IOException { + final String input = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithSizeToFile() throws IOException { + final String input = + "Hello, товарищ file #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output, + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetToFile() throws IOException { + final String input = + "Hello, товарищ file #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output, + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetAndSizeToFile() throws IOException { + final String input = + "Hello, товарищ file #4 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output, + StandardCharsets.UTF_8, + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetByNameToFile() throws IOException { + final String input = + "Hello, товарищ file #5 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output, + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetByNameAndSizeToFile() + throws IOException { + final String input = + "Hello, товарищ file #6 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output, + StandardCharsets.UTF_8.name(), + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderToPath() throws IOException { + final String input = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output.toPath() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithSizeToPath() throws IOException { + final String input = + "Hello, товарищ path #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output.toPath(), + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetToPath() throws IOException { + final String input = + "Hello, товарищ path #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output.toPath(), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetAndSizeToPath() throws IOException { + final String input = + "Hello, товарищ path #4 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output.toPath(), + StandardCharsets.UTF_8, + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetByNameToPath() throws IOException { + final String input = + "Hello, товарищ path #5 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output.toPath(), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetByNameAndSizeToPath() + throws IOException { + final String input = + "Hello, товарищ path #6 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + output.toPath(), + StandardCharsets.UTF_8.name(), + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderToOutput() throws IOException { + final String input = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + new OutputTo(output) + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithSizeToOutput() throws IOException { + final String input = + "Hello, товарищ output #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + new OutputTo(output), + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetToOutput() throws IOException { + final String input = + "Hello, товарищ output #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + new OutputTo(output), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetAndSizeToOutput() + throws IOException { + final String input = + "Hello, товарищ output #4 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + new OutputTo(output), + StandardCharsets.UTF_8, + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetByNameToOutput() throws IOException { + final String input = + "Hello, товарищ output #5 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + new OutputTo(output), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromReaderWithCharsetByNameAndSizeToOutput() + throws IOException { + final String input = + "Hello, товарищ output #6 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new ReaderOf(input), + new OutputTo(output), + StandardCharsets.UTF_8.name(), + input.length() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromTextTest.java b/src/test/java/org/cactoos/io/TeeInputFromTextTest.java new file mode 100644 index 0000000000..6041cac91e --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromTextTest.java @@ -0,0 +1,211 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use + * {@link org.cactoos.Text} as an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (215 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (215 lines) + */ +public final class TeeInputFromTextTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromTextToPath() throws IOException { + final String input = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + output.toPath() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextWithCharsetToPath() throws IOException { + final String input = + "Hello, товарищ path #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + output.toPath(), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextWithCharsetByNameToPath() throws IOException { + final String input = + "Hello, товарищ path #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + output.toPath(), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextToFile() throws IOException { + final String input = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + output + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextWithCharsetToFile() throws IOException { + final String input = + "Hello, товарищ file #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + output, + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextWithCharsetByNameToFile() throws IOException { + final String input = + "Hello, товарищ file #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + output, + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextToOutput() throws IOException { + final String input = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + new OutputTo(output) + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextWithCharsetToOutput() throws IOException { + final String input = + "Hello, товарищ output #2 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + new OutputTo(output), + StandardCharsets.UTF_8 + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromTextWithCharsetByNameToOutput() throws IOException { + final String input = + "Hello, товарищ output #3 äÄ üÜ öÖ and ß"; + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + new TextOf(input), + new OutputTo(output), + StandardCharsets.UTF_8.name() + ), + new TeeInputHasResult( + input, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromUriTest.java b/src/test/java/org/cactoos/io/TeeInputFromUriTest.java new file mode 100644 index 0000000000..8062fc318b --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromUriTest.java @@ -0,0 +1,119 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use + * {@link java.net.URI} as an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (120 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (120 lines) + */ +public final class TeeInputFromUriTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromUriToPath() throws IOException { + final String message = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toURI(), + output + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromUriToFile() throws IOException { + final String message = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toURI(), + output + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromUriToOutput() throws IOException { + final String message = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input.toURI(), + new OutputTo(output) + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } +} diff --git a/src/test/java/org/cactoos/io/TeeInputFromUrlTest.java b/src/test/java/org/cactoos/io/TeeInputFromUrlTest.java new file mode 100644 index 0000000000..953154a1db --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputFromUrlTest.java @@ -0,0 +1,125 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import org.cactoos.matchers.TeeInputHasResult; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test case for {@link TeeInput}. Cases for ctors which use + * {@link java.net.URL} as an input. + * @author Roman Proshin (roman@proshin.org) + * @version $Id$ + * @since 1.0 + * @checkstyle JavadocMethodCheck (125 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (125 lines) + */ +public final class TeeInputFromUrlTest { + + /** + * Temporary files generator. + */ + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void copiesFromUrlToPath() throws IOException { + final String message = + "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input + .toURI() + .toURL(), + output.toPath() + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromUrlToFile() throws IOException { + final String message = + "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input + .toURI() + .toURL(), + output + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } + + @Test + public void copiesFromUrlToOutput() throws IOException { + final String message = + "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; + final File input = this.folder.newFile(); + Files.write( + input.toPath(), + message.getBytes(StandardCharsets.UTF_8) + ); + final File output = this.folder.newFile(); + MatcherAssert.assertThat( + new TeeInput( + input + .toURI() + .toURL(), + new OutputTo(output) + ), + new TeeInputHasResult( + message, + new TextOf(output) + ) + ); + } +}