Skip to content
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

Merged
merged 9 commits into from
Feb 9, 2019
Merged

Conversation

BinaryIgor
Copy link
Contributor

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.
.

@0crat 0crat added the scope label Jan 17, 2019
@0crat
Copy link
Collaborator

0crat commented Jan 17, 2019

Job #1021 is now in scope, role is REV

@codecov-io
Copy link

codecov-io commented Jan 17, 2019

Codecov Report

Merging #1021 into master will decrease coverage by 0.02%.
The diff coverage is 71.42%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/cactoos/io/AppendTo.java 71.42% <71.42%> (ø) 2 <2> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 773f8e5...4cd8d50. Read the comment docs.

@0crat
Copy link
Collaborator

0crat commented Jan 17, 2019

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

Copy link
Contributor

@fabriciofx fabriciofx left a 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;
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Contributor

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();
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

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(
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabriciofx Same as above.

Copy link
Contributor

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";
Copy link
Contributor

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.

@BinaryIgor
Copy link
Contributor Author

@fabriciofx I have refactored, what could be refactored.

@fabriciofx
Copy link
Contributor

@Iprogrammerr Let's wait for #1023.

@fabriciofx
Copy link
Contributor

@Iprogrammerr #1023 has solved. Please, go ahead.

@fabriciofx
Copy link
Contributor

@Iprogrammerr ping

@BinaryIgor
Copy link
Contributor Author

@fabriciofx Refactored.

Copy link
Contributor

@fabriciofx fabriciofx left a 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)
Copy link
Contributor

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",
Copy link
Contributor

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",
Copy link
Contributor

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",
Copy link
Contributor

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();
Copy link
Contributor

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.

@BinaryIgor
Copy link
Contributor Author

@fabriciofx I don't understand what you expect me to do with that TemporaryFolder. Could you clarify?

@fabriciofx
Copy link
Contributor

fabriciofx commented Jan 26, 2019

@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.

@BinaryIgor
Copy link
Contributor Author

@fabriciofx Ping.

Copy link
Contributor

@fabriciofx fabriciofx left a 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";
Copy link
Contributor

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";
Copy link
Contributor

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),
Copy link
Contributor

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))
Copy link
Contributor

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.

@BinaryIgor
Copy link
Contributor Author

@fabriciofx Done. Could you give all of your comments upfront, next time? This way both yours and my work will be much faster.

@fabriciofx
Copy link
Contributor

fabriciofx commented Jan 27, 2019

@Iprogrammerr Sorry, but I've see some mistakes later.

@fabriciofx
Copy link
Contributor

@Iprogrammerr This PR seems fine to me. Congratulations!

@fabriciofx
Copy link
Contributor

@rultor merge

@rultor
Copy link
Collaborator

rultor commented Jan 27, 2019

@rultor merge

@fabriciofx Thanks for your request. @llorllale Please confirm this.


@Override
public OutputStream stream() throws Exception {
if (!this.source.exists()) {
Copy link
Contributor

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.

@llorllale
Copy link
Contributor

@Iprogrammerr left you one comment

@BinaryIgor
Copy link
Contributor Author

BinaryIgor commented Jan 28, 2019

@llorllale Done. Travis does not like commits from the past, same as #1026.

@fabriciofx
Copy link
Contributor

@Iprogrammerr Travis is failing due to gitlint. Your comments should not exceed 72 chars size. More details you can check in here and here.

@BinaryIgor
Copy link
Contributor Author

@fabriciofx Check build details, he is not failing on my commits.

@fabriciofx
Copy link
Contributor

@llorllale Can you check it? To me, this PR seems fine to merge.

@fabriciofx
Copy link
Contributor

@llorllale ping

@llorllale
Copy link
Contributor

@Iprogrammerr please pull from master (don't rebase) and retrigger the travis build

@BinaryIgor
Copy link
Contributor Author

@llorllale Done.

@llorllale
Copy link
Contributor

@rultor merge

@rultor
Copy link
Collaborator

rultor commented Feb 9, 2019

@rultor merge

@llorllale OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 4cd8d50 into yegor256:master Feb 9, 2019
@rultor
Copy link
Collaborator

rultor commented Feb 9, 2019

@rultor merge

@llorllale Done! FYI, the full log is here (took me 12min)

@0crat
Copy link
Collaborator

0crat commented Feb 9, 2019

Code review was too long (22 days), architects (@llorllale) were penalized, see §55

@0crat 0crat removed the scope label Feb 9, 2019
@0crat
Copy link
Collaborator

0crat commented Feb 9, 2019

The job #1021 is now out of scope

@0crat
Copy link
Collaborator

0crat commented Feb 9, 2019

Order was finished: +15 point(s) just awarded to @fabriciofx/z

@0crat
Copy link
Collaborator

0crat commented Feb 9, 2019

Payment to ARC for a closed pull request, as in §28: +10 point(s) just awarded to @llorllale/z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants