Created
March 1, 2018 06:00
-
-
Save proshin-roman/876f0b4dcd31954e42fb26e5147ecd04 to your computer and use it in GitHub Desktop.
Test cases for TeeInput ctors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment