-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for strict verification of resource deletion in Tempora…
…ryFolder rule with test cases
- Loading branch information
Showing
4 changed files
with
213 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/test/java/org/junit/tests/experimental/rules/TemporaryFolderRuleAssuredDeletionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.junit.tests.experimental.rules; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.junit.experimental.results.PrintableResult.testResult; | ||
import static org.junit.experimental.results.ResultMatchers.failureCountIs; | ||
import static org.junit.experimental.results.ResultMatchers.isSuccessful; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.results.PrintableResult; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class TemporaryFolderRuleAssuredDeletionTest { | ||
|
||
public static class HasTempFolderWithAssuredDeletion { | ||
@Rule public TemporaryFolder folder = new TemporaryFolder() { | ||
protected void before() throws Throwable { | ||
|
||
}; | ||
|
||
protected boolean tryDelete() { | ||
return false; | ||
}; | ||
|
||
public boolean isDeletionAssured() { | ||
return true; | ||
}; | ||
}; | ||
|
||
@Test | ||
public void test() { | ||
// no-op | ||
} | ||
} | ||
|
||
@Test | ||
public void testStrictVerificationFailure() { | ||
PrintableResult result = testResult(HasTempFolderWithAssuredDeletion.class); | ||
assertThat(result, failureCountIs(1)); | ||
assertThat(result.toString(), CoreMatchers.containsString("Unable to clean up temporary folder")); | ||
} | ||
|
||
public static class HasTempFolderWithoutAssuredDeletion { | ||
@Rule public TemporaryFolder folder = new TemporaryFolder() { | ||
protected void before() throws Throwable { | ||
|
||
}; | ||
|
||
protected boolean tryDelete() { | ||
return false; | ||
}; | ||
}; | ||
|
||
@Test | ||
public void test() { | ||
// no-op | ||
} | ||
} | ||
|
||
@Test | ||
public void testStrictVerificationSuccess() { | ||
PrintableResult result = testResult(HasTempFolderWithoutAssuredDeletion.class); | ||
assertThat(result, isSuccessful()); | ||
} | ||
|
||
public static class HasTempFolderWithLazyAssuredDeletion { | ||
@Rule public TemporaryFolder folder = new TemporaryFolder() { | ||
protected boolean tryDelete() { | ||
return false; | ||
}; | ||
}; | ||
|
||
@Test | ||
public void test1() { | ||
folder.assureDeletion(); | ||
} | ||
|
||
@Test | ||
public void test2() { | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void testStrictVerificationFailureForLazyAssurance() { | ||
PrintableResult result = testResult(HasTempFolderWithLazyAssuredDeletion.class); | ||
assertThat(result, failureCountIs(1)); | ||
} | ||
} |