Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 28, 2018
2 parents c6c5ad2 + 0e7628a commit 2bcee98
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 95 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/io/TeeInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
* @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 {

Expand Down
108 changes: 108 additions & 0 deletions src/test/java/org/cactoos/io/TeeInputFromByteArrayTest.java
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 src/test/java/org/cactoos/io/TeeInputFromBytesTest.java
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)
);
}
}
95 changes: 0 additions & 95 deletions src/test/java/org/cactoos/io/TeeInputTest.java

This file was deleted.

2 comments on commit 2bcee98

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 2bcee98 Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 631-6c33e53a discovered in src/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.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 2bcee98 Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 631-845093d4 discovered in src/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.

Please sign in to comment.