-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#631: TeeInput test class is incomplete #698
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e8590a3
#631: TeeInput test class is incomplete
proshin-roman 7d4cb7c
#631: TeeInput test class is incomplete: add two puzzles
proshin-roman 22a653a
#631: TeeInput test class is incomplete
proshin-roman 16c4fe0
#631: TeeInput test class is incomplete
proshin-roman c27b67a
#631: TeeInput test class is incomplete
proshin-roman 0e7628a
#631: TeeInput test class is incomplete: fix puzzle description
proshin-roman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
src/main/java/org/cactoos/matchers/TeeInputHasResult.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,127 @@ | ||
/** | ||
* 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.matchers; | ||
|
||
import org.cactoos.Text; | ||
import org.cactoos.io.TeeInput; | ||
import org.cactoos.text.ComparableText; | ||
import org.cactoos.text.FormattedText; | ||
import org.cactoos.text.TextOf; | ||
import org.cactoos.text.UncheckedText; | ||
import org.hamcrest.Description; | ||
import org.hamcrest.TypeSafeMatcher; | ||
|
||
/** | ||
* Matcher for the {@link TeeInput}'s results. | ||
* | ||
* @author Roman Proshin ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0 | ||
*/ | ||
public final class TeeInputHasResult extends TypeSafeMatcher<TeeInput> { | ||
|
||
/** | ||
* Format for matcher description. | ||
*/ | ||
private static final String DESCRIPTION = | ||
"TeeInput with result '%s' and copied value '%s'"; | ||
/** | ||
* Value that is expected to be returned from the given TeeInput. | ||
*/ | ||
private final ComparableText expected; | ||
/** | ||
* Value that is expected to be copied into the output of TeeInput. | ||
*/ | ||
private final ComparableText copied; | ||
/** | ||
* Actual value returned from the given TeeInput. | ||
*/ | ||
private ComparableText actual; | ||
|
||
/** | ||
* Ctor. | ||
* @param expected Value that is expected to be returned from the TeeInput | ||
* @param copied Value that is expected to be copied into the output of | ||
* the TeeInput | ||
*/ | ||
public TeeInputHasResult( | ||
final String expected, | ||
final Text copied) { | ||
this( | ||
new TextOf(expected), | ||
copied | ||
); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param expected Value that is expected to be returned from the TeeInput | ||
* @param copied Value that is expected to be copied into the output of | ||
* the TeeInput | ||
*/ | ||
public TeeInputHasResult( | ||
final Text expected, | ||
final Text copied) { | ||
super(); | ||
this.expected = new ComparableText(expected); | ||
this.copied = new ComparableText(copied); | ||
this.actual = new ComparableText(new TextOf("")); | ||
} | ||
|
||
@Override | ||
public boolean matchesSafely(final TeeInput item) { | ||
this.actual = new ComparableText(new TextOf(item)); | ||
return | ||
this.expected.compareTo(this.actual) == 0 | ||
&& this.expected.compareTo(this.copied) == 0; | ||
} | ||
|
||
@Override | ||
public void describeTo(final Description description) { | ||
description.appendText( | ||
new UncheckedText( | ||
new FormattedText( | ||
TeeInputHasResult.DESCRIPTION, | ||
new UncheckedText(this.expected).asString(), | ||
new UncheckedText(this.expected).asString() | ||
) | ||
).asString() | ||
); | ||
} | ||
|
||
@Override | ||
public void describeMismatchSafely( | ||
final TeeInput item, | ||
final Description description) { | ||
description.appendText( | ||
new UncheckedText( | ||
new FormattedText( | ||
TeeInputHasResult.DESCRIPTION, | ||
new UncheckedText(this.actual).asString(), | ||
new UncheckedText(this.copied).asString() | ||
) | ||
).asString() | ||
); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
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,102 @@ | ||
/** | ||
* 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.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 byte array as an | ||
* input. | ||
* @author Roman Proshin ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0 | ||
* @checkstyle JavadocMethodCheck (100 lines) | ||
* @checkstyle ClassDataAbstractionCouplingCheck (100 lines) | ||
*/ | ||
public final class TeeInputFromByteArrayTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @proshin-roman Just this test class and the next one are enough for this PR. No new, untested matchers, no 13 changed files etc. |
||
|
||
/** | ||
* Temporary files generator. | ||
*/ | ||
@Rule | ||
public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void copiesFromByteArrayToPath() throws Exception { | ||
final String input = | ||
"Hello, товарищ path äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
MatcherAssert.assertThat( | ||
new TeeInput( | ||
input.getBytes(StandardCharsets.UTF_8), | ||
output.toPath() | ||
), | ||
new TeeInputHasResult( | ||
input, | ||
new TextOf(output) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromByteArrayToFile() throws Exception { | ||
final String input = | ||
"Hello, товарищ file äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
MatcherAssert.assertThat( | ||
new TeeInput( | ||
input.getBytes(StandardCharsets.UTF_8), | ||
output | ||
), | ||
new TeeInputHasResult( | ||
input, | ||
new TextOf(output) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromByteArrayToOutput() throws Exception { | ||
final String input = | ||
"Hello, товарищ output äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
MatcherAssert.assertThat( | ||
new TeeInput( | ||
input.getBytes(StandardCharsets.UTF_8), | ||
new OutputTo(output) | ||
), | ||
new TeeInputHasResult( | ||
input, | ||
new TextOf(output) | ||
) | ||
); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
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,102 @@ | ||
/** | ||
* 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.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.Bytes} as an input. | ||
* @author Roman Proshin ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0 | ||
* @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 input = | ||
"Hello, товарищ path äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
MatcherAssert.assertThat( | ||
new TeeInput( | ||
new BytesOf(input), | ||
output.toPath() | ||
), | ||
new TeeInputHasResult( | ||
input, | ||
new TextOf(output) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromBytesToFile() throws IOException { | ||
final String input = | ||
"Hello, товарищ file äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
MatcherAssert.assertThat( | ||
new TeeInput( | ||
new BytesOf(input), | ||
output | ||
), | ||
new TeeInputHasResult( | ||
input, | ||
new TextOf(output) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void copiesFromBytesToOutput() throws IOException { | ||
final String input = | ||
"Hello, товарищ output äÄ üÜ öÖ and ß"; | ||
final File output = this.folder.newFile(); | ||
MatcherAssert.assertThat( | ||
new TeeInput( | ||
new BytesOf(input), | ||
new OutputTo(output) | ||
), | ||
new TeeInputHasResult( | ||
input, | ||
new TextOf(output) | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@proshin-roman We did not discuss about this new Matcher, did we? It's nice that you did it, but there are no unit tests for it, how do we know it works? Countless new tests are relying on it to make assertions, but it (the matcher itself) is not tested at all.
Write some tests for it if you want to use it in these tests, otherwise please use simple Matchers.
Not to mention, this new matcher, together with unit tests for it, should be in a separate PR on a separate ticket, it's basically a new functionality of the library.