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

Update TemporaryFolder.newFolder() to give a better error message if a path contains a slash #974

Merged
merged 1 commit into from
Aug 13, 2014

Conversation

priav03
Copy link
Contributor

@priav03 priav03 commented Aug 9, 2014

Please review the fix and let me know if it does good.

* @param folderName Name of the folder being created
* @throws IOException
*/
private void validateFolderName(String folderName) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

indentation is a bit off here

@kcooney
Copy link
Member

kcooney commented Aug 9, 2014

Thanks! Could you add some tests?

@priav03
Copy link
Contributor Author

priav03 commented Aug 9, 2014

Will fix the indentation and will remove the null check.

I am planning to add the following test cases in TemporaryFolderUsageTest class-

  1. Test case to verify the behavior when a folder name with multiple path components is passed to newFolder(String folder) function
  2. Test case to verify the behavior when a folder name with multiple path components is passed to newFolder(String ... folderNames) function

Please let me know if I am missing out on other important test cases.

@priav03
Copy link
Contributor Author

priav03 commented Aug 10, 2014

In the latest fix, I fixed indentation and also removed the null check. Have also added two additional tests. Please let me know your comments on this.

thrown.expect(IOException.class);
String errorMsg = "Folder name cannot consist of multiple path components separated by a file separator."
+ " Please use newFolder('MyParentFolder','MyFolder') to create hierarchies of folders";
thrown.expectMessage(errorMsg);
Copy link
Member

Choose a reason for hiding this comment

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

note that expectMessage does a substring match, so you don't need to put the entire error message. I would rather not hard-code the entire error message in the test because it's unnecessary brittle. Could you just check for a substring like "name cannot consist of multiple path components"? Thanks

@kcooney kcooney changed the title Fix to resolve #946 Update TemporaryFolder.newFolder() to give a better error message if a path contains a slash Aug 11, 2014
@kcooney
Copy link
Member

kcooney commented Aug 11, 2014

I updated the description to state what the change is.

Thanks for adding the tests.

After making the requested changes, could you squash the commits? See https://github.com/junit-team/junit/wiki/Pull-Requests for details.

I'm not sure we will get this into 4.12. I want to make sure that the people discussing this bug agree on this as the fix.

@priav03
Copy link
Contributor Author

priav03 commented Aug 11, 2014

Done. I am waiting to hear from other reviewers. What is the deadline for 4.12?

@marcphilipp
Copy link
Member

LGTM!

@kcooney
Copy link
Member

kcooney commented Aug 11, 2014

@priav03 Thanks.

We already sent out the first release candidate for 4.12. I'm not sure what kinds of changes the other JUnit owners want to allow in before the final 4.12 release

*
* @param folderName
* Name of the folder being created
* @throws IOException
Copy link
Contributor

Choose a reason for hiding this comment

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

The @throws is not necessary and could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix this.

Copy link
Member

Choose a reason for hiding this comment

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

Specifically, having an empty @throws is discouraged (same for empty params). If there is something useful you can say about when the exception is thrown, you can add that to the @throws

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation. I realize the @throws is indeed not necessary. I have removed the throws as suggested by @stefanbirkner .

@stefanbirkner
Copy link
Contributor

I'm fine with adding this pull request to JUnit 4.12 if it is ready.

@paulduffin
Copy link
Contributor

Looks fine to me as it gets rid of the misleading error message.

@marcphilipp
Copy link
Member

+1 for releasing this in 4.12 if it's ready.

@priav03
Copy link
Contributor Author

priav03 commented Aug 12, 2014

I have incorporated the changes suggested by @stefanbirkner .

@priav03
Copy link
Contributor Author

priav03 commented Aug 13, 2014

Hi all. Did we decide on including/excluding this fix for 4.12?

kcooney added a commit that referenced this pull request Aug 13, 2014
Update TemporaryFolder.newFolder() to give a better error message if a path contains a slash
@kcooney kcooney merged commit 4c78da0 into junit-team:master Aug 13, 2014
@kcooney
Copy link
Member

kcooney commented Aug 13, 2014

@priav03 Thanks again for the fix. Could you update the release notes on the wiki?

@marcphilipp
Copy link
Member

The release notes have already been moved to the repo to prepare for
the upcoming release.

You can post them as a comment right here and I can add them.

@stefanbirkner stefanbirkner added this to the 4.12 milestone Aug 13, 2014
@priav03
Copy link
Contributor Author

priav03 commented Aug 13, 2014

Sure. I have used @paulduffin 's description of the issue to state the behavior prior to this fix. Here is the content for release notes -

Pull request #974 - Updated TemporaryFolder.newFolder() to give an error message if a path contains a slash.

If you call TemporaryFolder.newFolder("foo/bar") in JUnit 4.10 the method returns a File object for the new folder but actually fails to create it. That is contrary to the expected behaviour of the method which is to actually create the folder. In JUnit 4.11 the same call throws an exception. Nowhere in the documentation does it explain that the String(s) passed to that method can only be single path components.

With this fix, folder names are validated to contain single path name. If the folder name consists of multiple path names, an exception is thrown stating that usage of multiple path components in a string containing folder name is disallowed.

@priav03
Copy link
Contributor Author

priav03 commented Aug 13, 2014

Please let me know if I need to make any changes to the content posted above.

@paulduffin
Copy link
Contributor

Looks fine to me.
On 13 Aug 2014 17:18, "Priya" notifications@github.com wrote:

Please let me know if I need to make any changes to the content posted
above.


Reply to this email directly or view it on GitHub
#974 (comment).

marcphilipp added a commit that referenced this pull request Aug 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants