-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Strict verification of resource deletion in TemporaryFolder rule #1044
Conversation
@@ -65,7 +65,7 @@ protected void before() throws Throwable { | |||
/** | |||
* Override to tear down your specific external resource. | |||
*/ | |||
protected void after() { | |||
protected void after() throws Throwable { |
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.
We can't change the signature of published methods
fc4be6a
to
982bb48
Compare
@kcooney I have updated the code please review.
|
@marcphilipp you were the one who suggested we shouldn't add a builder. Could you respond to that part? |
private boolean assureDeletion; | ||
|
||
/** | ||
* |
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.
Could you add something useful here? Note you don't need to add Javadoc for params if they are abious based on the method Javadoc. Somewhere we should document want the parent folder is used for
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.
@kcooney Done.
68864cb
to
54dc9ca
Compare
@kcooney Incorporated all the suggested changes. Only the mutability part is remaining to be discussed and finalized. Will take care of style guide in future. |
recursiveDelete(folder); | ||
if (!tryDelete()) { | ||
if (isDeletionAssured()) { | ||
throw new IllegalStateException("Unable to clean up temporary folder " + folder); |
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.
IOException?
Edit: Not a good idea. We need an unchecked exception.
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.
The only other things that comes to mind is to use an AssertionError
or even assertTrue("Unable to clean up temporary folder " + folder, isDeletionAssured())
. What do you think?
On the other hand, I could live with IllegalStateException, too.
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.
IllegalStateException
doesn't sound right to me because it "signals that a method has been invoked at an illegal or inappropriate time"
I think we should either throw AssertionError
or RuntimeException
. In either case, we could introduce a custom exception in the future.
Let's go with AssertionError
. I have a sight preference for using fail()
vs. assertTrue()
here
BuilderI am not sure how many people use the @Rule public TemporaryFolder temporaryFolder = TemporaryFolder.builder().assureDeletion().build(); compared to a static factory method @Rule public TemporaryFolder temporaryFolder = TemporaryFolder.assureDeletion(); We could do both but that might be confusing, too. I'd say let's keep the builder and drop the static factory method. MutabilitySorry for the confusion. @kcooney has convinced me in the discussion in #1001 that rules should rather not allow to have their behavior changed after they are constructed ( |
@marcphilipp I have made Behavior
|
@@ -29,15 +29,86 @@ | |||
public class TemporaryFolder extends ExternalResource { | |||
private final File parentFolder; | |||
private File folder; | |||
|
|||
private final boolean assureDeletion; |
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.
style-nit: let's but final fields before mutable fields. Thanks
@kcooney I have used
|
The |
/** | ||
* Builds an instance of {@link TemporaryFolder}. | ||
*/ | ||
public static class Builder { |
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.
For the Timeout
rule, we gave the Builder
a protected constructor. I think the reason was because most users should use the builder()
static method, but if someone wants to subclass Timeout
they should be allowed to subclass the Builder.
Perhaps we should make this Builder have a protected constructor, too.
…ryFolder rule with test cases
@kcooney All done :) |
LGTM! One last thing: Please add Javadoc to |
public void testStrictVerificationFailure() { | ||
PrintableResult result = testResult(HasTempFolderWithAssuredDeletion.class); | ||
assertThat(result, failureCountIs(1)); | ||
assertThat(result.toString(), CoreMatchers.containsString("Unable to clean up temporary folder")); |
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.
Please add a static import for containsString
.
@marcphilipp Done. Should I also add this feature to 4.13 release notes? Also we need to update the Rules wiki which still says that deletion is guaranteed. |
@NarendraPathai Thanks! Yes, we should update the release notes in the wiki after the merge and update the Rules wiki page (good catch!). @kcooney Can you please take a look at the Javadoc as a native speaker? |
I'm on vacation, but I'll take a look at the Javadoc and merge this within a week. Thanks for all of the work on this! |
@kcooney @marcphilipp Thanks to you too for supporting. |
Did some very minor style cleanup, and some cleanup of the tests, and merged. @NarendraPathai could you update the release notes? Thanks! |
@kcooney Yes I will do it on Tuesday. Just a reminder that wiki section needs to be updated too. |
@kcooney I have updated the release notes. Should I also update the wiki? |
@NarendraPathai yes please |
@NarendraPathai Please mention on the wiki page that the new feature will be available from 4.13 on. |
@marcphilipp Yes for sure. I will add it today. |
@kcooney @marcphilipp Done. |
Thanks! |
PR that adds support of strict verification of deleted resources when using
TemporaryFolder
rule #1001