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

TemporaryFolder.newFolder(String...) supports path separator #1406

Merged

Conversation

kcooney
Copy link
Member

@kcooney kcooney commented Jan 6, 2017

No description provided.

@kcooney kcooney force-pushed the TemporaryFolder-support-path-separator branch from 6763c81 to 288c6df Compare January 6, 2017 19:16
Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

Looks very good! I added a few suggestions inline.

directory = new File(directory, "temp3");
assertFileIsDirectory(directory);
directory = new File(directory, "temp4");
assertFileIsDirectory(directory);
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be sufficient have a single assertion: assertFileIsDirectory(new File(tempFolder.getRoot(), "temp1/temp2/temp3/temp4")?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't 100% certain that would work on all platforms

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure it should. Can we assume it does until proven otherwise?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. I have no way to verify on Windows though.

File file = root;
boolean lastMkdirsCallSuccessful = true;
for (int i = 0; i < paths.length; i++) {
relativePath = relativePath == null ? new File(paths[i]) : new File(relativePath, paths[i]);
Copy link
Member

Choose a reason for hiding this comment

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

According to the Javadoc of File this can be simplified to relativePath = new File(relativePath, paths[i]).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Done.

if (new File(path).isAbsolute()) {
throw new IOException("folder path \'" + path + "\' is not a relative path");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also add a check for paths.length > 0. Because in that case we currently return getRoot() which isn't a "new fresh folder".

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I noticed that was the current behavior, too. I wasn't sure you wanted that in the same pull. I added the fix in a new commit. I also added a commit fixing some incorrect test method names.

@kcooney kcooney force-pushed the TemporaryFolder-support-path-separator branch from 288c6df to 4a3cfd9 Compare January 7, 2017 08:32
@@ -63,7 +63,7 @@ public void newFileWithGivenFilenameThrowsIllegalArgumentExceptionIfFileExists()
}

@Test(expected = IllegalStateException.class)
public void newFolderThrowsIllegalStateExceptionIfCreateWasNotInvoked()
public void newFolderThrowsIOExceptionIfCreateWasNotInvoked()
Copy link
Member

Choose a reason for hiding this comment

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

This one actually does throw an IllegalStateException.

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops! Fixed

@kcooney kcooney force-pushed the TemporaryFolder-support-path-separator branch from 4a3cfd9 to 109397b Compare January 7, 2017 18:11
@kcooney kcooney force-pushed the TemporaryFolder-support-path-separator branch from 109397b to 70a86fb Compare January 10, 2017 03:16
/*
* Before checking if the paths are absolute paths, check if create() was ever called,
* and if it wasn't, throw IllegalStateException.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the comment is wrong because I could not find the IllegalStateException.

Copy link
Member Author

Choose a reason for hiding this comment

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

getRoot() throws IllegalStateException if before() wasn't (yet?) called.

@stefanbirkner stefanbirkner merged commit f15ee64 into junit-team:master Jan 18, 2017
@stefanbirkner stefanbirkner added this to the 4.13 milestone Jan 18, 2017
@stefanbirkner
Copy link
Contributor

That's a nice improvement. Thanks.

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.

3 participants