-
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
#939 AppendTo for appending content to files #1021
Conversation
Job #1021 is now in scope, role is |
Codecov Report
@@ Coverage Diff @@
## master #1021 +/- ##
============================================
- Coverage 87.58% 87.55% -0.03%
- Complexity 1520 1522 +2
============================================
Files 267 268 +1
Lines 3897 3904 +7
Branches 215 215
============================================
+ Hits 3413 3418 +5
- Misses 435 437 +2
Partials 49 49
Continue to review full report at Codecov.
|
This pull request #1021 is assigned to @fabriciofx/z, here is why; the budget is 15 minutes, see §4; please, read §27 and when you decide to accept the changes, inform @llorllale/z (the architect) right in this ticket; if you decide that this PR should not be accepted ever, also inform the architect; this blog post will help you understand what is expected from a code reviewer; there will be no monetary reward for this job |
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.
@Iprogrammerr done. Please, check it.
* @param source File to which content will be appended. | ||
*/ | ||
public AppendTo(final File source) { | ||
this.source = source; |
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.
@Iprogrammerr use a different constructor parameter name than attribute name.
* Temporary files and folders generator. | ||
*/ | ||
@Rule | ||
public final TemporaryFolder folder = new TemporaryFolder(); |
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.
@llorllale is there an alternative to this TemporaryFolder
@Rule
?
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.
@Iprogrammerr Please, go ahead here.
* A rule for handling an exception. | ||
*/ | ||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); |
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.
@Iprogrammerr remove this @Rule
and use an alternative provided by cactoos-matchers
to check exceptions.
@Test | ||
public void failsIfFileDoesNotExist() throws Exception { | ||
final File source = new File(new RandomText(5).asString()); | ||
this.exception.expect(IOException.class); |
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.
@Iprogrammerr remove this and use an alternative provided by cactoos-matchers
to check exceptions.
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.
@fabriciofx There is no cactoos-matchers release with that mechanism provided(namely, Throws class).
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.
@Iprogrammerr Let's wait for #1023.
new OutputTo(source).stream().write(first.getBytes()); | ||
final String second = "efgh"; | ||
new AppendTo(source).stream().write(second.getBytes()); | ||
MatcherAssert.assertThat( |
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.
@Iprogrammerr use Assertion
instead of MatcherAssert.assertThat
.
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.
@fabriciofx Same as above.
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.
@Iprogrammerr The same above.
final File source = this.folder.newFile(); | ||
final String first = "abdcd"; | ||
new OutputTo(source).stream().write(first.getBytes()); | ||
final String second = "efgh"; |
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.
@Iprogrammerr let's check with some unicode text too.
@fabriciofx I have refactored, what could be refactored. |
@Iprogrammerr Let's wait for #1023. |
@Iprogrammerr #1023 has solved. Please, go ahead. |
@Iprogrammerr ping |
@fabriciofx Refactored. |
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.
@Iprogrammerr Done. Please, check out.
* Test case for {@link AppendTo}. | ||
* | ||
* @since 1.0 | ||
* @checkstyle MagicNumber (500 line) |
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.
@Iprogrammerr Please, use MagicNumber
just on line(s) where the number is used.
() -> () -> new AppendTo(source).stream(), | ||
new Throws<>( | ||
new FormattedText( | ||
"Can not append to %s file. It does not exist", |
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.
@Iprogrammerr Change "Can not" to "Can't".
public void failsIfFileDoesNotExist() throws Exception { | ||
final File source = new File(new RandomText(5).asString()); | ||
new Assertion<>( | ||
"Doesn't throw exception with proper message", |
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.
@Iprogrammerr Change it to "Can't throw exception with proper message".
final String second = "\\u25E6"; | ||
new AppendTo(source).stream().write(second.getBytes()); | ||
new Assertion<>( | ||
"Does not contain expected unicode text", |
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.
@Iprogrammerr Change here to "Can't find expected unicode text content".
* Temporary files and folders generator. | ||
*/ | ||
@Rule | ||
public final TemporaryFolder folder = new TemporaryFolder(); |
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.
@Iprogrammerr Please, go ahead here.
@fabriciofx I don't understand what you expect me to do with that TemporaryFolder. Could you clarify? |
@Iprogrammerr The idea is use something like I proposed in #1022 but it will delay you to close this issue. So, don' worry about it and go ahead. |
@fabriciofx Ping. |
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.
@Iprogrammerr Done. Please, check it.
@Test | ||
public void appendsUnicodeToFile() throws Exception { | ||
final File source = this.folder.newFile(); | ||
final String first = "\\u0026\\u2022"; |
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.
@Iprogrammerr Let's change these content to something more readble. Please, look at TeeInputFromTextTest
for content examples.
final File source = this.folder.newFile(); | ||
final String first = "\\u0026\\u2022"; | ||
new OutputTo(source).stream().write(first.getBytes()); | ||
final String second = "\\u25E6"; |
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.
@Iprogrammerr Same above.
new AppendTo(source).stream().write(second.getBytes()); | ||
new Assertion<>( | ||
"Can't find expected unicode text content", | ||
() -> new TextOf(source), |
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.
@Iprogrammerr Please, use InputOf
instead.
new Assertion<>( | ||
"Can't find expected unicode text content", | ||
() -> new TextOf(source), | ||
new TextIs(new JoinedText("", first, second)) |
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.
@Iprogrammerr Please, use InputHasContent
instead.
@fabriciofx Done. Could you give all of your comments upfront, next time? This way both yours and my work will be much faster. |
@Iprogrammerr Sorry, but I've see some mistakes later. |
@Iprogrammerr This PR seems fine to me. Congratulations! |
@rultor merge |
@fabriciofx Thanks for your request. @llorllale Please confirm this. |
|
||
@Override | ||
public OutputStream stream() throws Exception { | ||
if (!this.source.exists()) { |
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.
@Iprogrammerr this check is already baked into Files.newOutputStream()
when using the APPEND
option, so it can be removed.
@Iprogrammerr left you one comment |
@llorllale Done. Travis does not like commits from the past, same as #1026. |
@fabriciofx Check build details, he is not failing on my commits. |
@llorllale Can you check it? To me, this PR seems fine to merge. |
@llorllale ping |
@Iprogrammerr please pull from |
@llorllale Done. |
@rultor merge |
@llorllale OK, I'll try to merge now. You can check the progress of the merge here |
@llorllale Done! FYI, the full log is here (took me 12min) |
Code review was too long (22 days), architects (@llorllale) were penalized, see §55 |
The job #1021 is now out of scope |
Order was finished: +15 point(s) just awarded to @fabriciofx/z |
Payment to |
As described in #939, new class AppendTo which implements Output was created. It encapsulates a File and returns an output with guarantee that new content will be appended to existing one. If file does not exist it throws exception.
.