-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
222 additions
and
95 deletions.
There are no files selected for viewing
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
108 changes: 108 additions & 0 deletions
108
src/test/java/org/cactoos/io/TeeInputFromByteArrayTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* 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.nio.charset.StandardCharsets; | ||
import org.cactoos.text.TextOf; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
/** | ||
* Test case for {@link TeeInput}. Cases for ctors which use byte array as an | ||
* input. | ||
* @author Roman Proshin (roman@proshin.org) | ||
* @version $Id$ | ||
* @since 1.0 | ||
* @checkstyle JavadocMethodCheck (100 lines) | ||
* @checkstyle ClassDataAbstractionCouplingCheck (100 lines) | ||
*/ | ||
public final class TeeInputFromByteArrayTest { | ||
|
||
/** | ||
* Temporary files generator. | ||
*/ | ||
@Rule | ||
public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void copiesFromByteArrayToPath() throws Exception { | ||
final String message = | ||
"Hello, товарищ path äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
final TeeInput input = new TeeInput( | ||
message.getBytes(StandardCharsets.UTF_8), | ||
output.toPath() | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(input).asString(), | ||
new IsEqual<>(message) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(output).asString(), | ||
new IsEqual<>(message) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromByteArrayToFile() throws Exception { | ||
final String message = | ||
"Hello, товарищ file äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
final TeeInput input = new TeeInput( | ||
message.getBytes(StandardCharsets.UTF_8), | ||
output | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(input).asString(), | ||
new IsEqual<>(message) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(output).asString(), | ||
new IsEqual<>(message) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromByteArrayToOutput() throws Exception { | ||
final String message = | ||
"Hello, товарищ output äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
final TeeInput input = new TeeInput( | ||
message.getBytes(StandardCharsets.UTF_8), | ||
new OutputTo(output) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(input).asString(), | ||
new IsEqual<>(message) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(output).asString(), | ||
new IsEqual<>(message) | ||
); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/test/java/org/cactoos/io/TeeInputFromBytesTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* 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 org.cactoos.text.TextOf; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.core.IsEqual; | ||
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.Bytes} as an input. | ||
* @author Roman Proshin (roman@proshin.org) | ||
* @version $Id$ | ||
* @since 1.0 | ||
* @todo #631:30min Create a new Matcher that will compare results of TeeInput | ||
* as well as copied content to the original message. Apply this new matcher | ||
* for this test and for {@link TeeInputFromByteArrayTest}. | ||
* @checkstyle JavadocMethodCheck (100 lines) | ||
* @checkstyle ClassDataAbstractionCouplingCheck (100 lines) | ||
*/ | ||
public final class TeeInputFromBytesTest { | ||
|
||
/** | ||
* Temporary files generator. | ||
*/ | ||
@Rule | ||
public final TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void copiesFromBytesToPath() throws IOException { | ||
final String message = | ||
"Hello, товарищ path äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
final TeeInput input = new TeeInput( | ||
new BytesOf(message), | ||
output.toPath() | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(input).asString(), | ||
new IsEqual<>(message) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(output).asString(), | ||
new IsEqual<>(message) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromBytesToFile() throws IOException { | ||
final String message = | ||
"Hello, товарищ file äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
final TeeInput input = new TeeInput( | ||
new BytesOf(message), | ||
output | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(input).asString(), | ||
new IsEqual<>(message) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(output).asString(), | ||
new IsEqual<>(message) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromBytesToOutput() throws IOException { | ||
final String message = | ||
"Hello, товарищ output äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
final TeeInput input = new TeeInput( | ||
new BytesOf(message), | ||
new OutputTo(output) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(input).asString(), | ||
new IsEqual<>(message) | ||
); | ||
MatcherAssert.assertThat( | ||
new TextOf(output).asString(), | ||
new IsEqual<>(message) | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
2bcee98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
631-6c33e53a
discovered insrc/main/java/org/cactoos/io/TeeInput.java
and submitted as #720. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.2bcee98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
631-845093d4
discovered insrc/test/java/org/cactoos/io/TeeInputFromBytesTest.java
and submitted as #721. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.