diff --git a/core/src/test/java/hudson/PluginManagerTest.java b/core/src/test/java/hudson/PluginManagerTest.java index cbda2857f8..fe674b7d5a 100644 --- a/core/src/test/java/hudson/PluginManagerTest.java +++ b/core/src/test/java/hudson/PluginManagerTest.java @@ -27,14 +27,17 @@ package hudson; import org.apache.tools.ant.filters.StringInputStream; import org.junit.Test; -import java.io.File; import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; public class PluginManagerTest { + @Rule public TemporaryFolder tmp = new TemporaryFolder(); + @Test public void parseRequestedPlugins() throws Exception { - assertEquals("{other=2.0, stuff=1.2}", new LocalPluginManager(Util.createTempDir()) + assertEquals("{other=2.0, stuff=1.2}", new LocalPluginManager(tmp.getRoot()) .parseRequestedPlugins(new StringInputStream("")).toString()); } diff --git a/core/src/test/java/hudson/UtilTest.java b/core/src/test/java/hudson/UtilTest.java index a40b588616..ea1a13b6cb 100644 --- a/core/src/test/java/hudson/UtilTest.java +++ b/core/src/test/java/hudson/UtilTest.java @@ -40,12 +40,17 @@ import org.jvnet.hudson.test.Bug; import hudson.util.StreamTaskListener; import java.io.FileOutputStream; import java.io.OutputStream; +import org.junit.Rule; import org.junit.internal.AssumptionViolatedException; +import org.junit.rules.TemporaryFolder; /** * @author Kohsuke Kawaguchi */ public class UtilTest { + + @Rule public TemporaryFolder tmp = new TemporaryFolder(); + @Test public void testReplaceMacro() { Map m = new HashMap(); @@ -167,7 +172,7 @@ public class UtilTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener l = new StreamTaskListener(baos); - File d = Util.createTempDir(); + File d = tmp.getRoot(); try { new FilePath(new File(d, "a")).touch(0); assertNull(Util.resolveSymlink(new File(d, "a"))); @@ -215,7 +220,7 @@ public class UtilTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener l = new StreamTaskListener(baos); - File d = Util.createTempDir(); + File d = tmp.getRoot(); try { new FilePath(new File(d, "original")).touch(0); assertFalse(Util.isSymlink(new File(d, "original"))); @@ -247,7 +252,7 @@ public class UtilTest { } catch (ClassNotFoundException x) { throw new AssumptionViolatedException("prior to JDK 7", x); } - File d = Util.createTempDir(); + File d = tmp.getRoot(); try { File f = new File(d, "f"); OutputStream os = new FileOutputStream(f); diff --git a/core/src/test/java/hudson/util/DirScannerTest.java b/core/src/test/java/hudson/util/DirScannerTest.java index 2725d5ced6..c48007222c 100644 --- a/core/src/test/java/hudson/util/DirScannerTest.java +++ b/core/src/test/java/hudson/util/DirScannerTest.java @@ -23,21 +23,23 @@ */ package hudson.util; +import hudson.FilePath; import java.io.File; import java.io.IOException; - -import hudson.FilePath; -import hudson.Util; - -import junit.framework.TestCase; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; /** * @author Christoph Thelen */ -public class DirScannerTest extends TestCase { +public class DirScannerTest { - public void testGlobShouldUseDefaultExcludes() throws Exception { - FilePath tmp = new FilePath(Util.createTempDir()); + @Rule public TemporaryFolder tmpRule = new TemporaryFolder(); + + @Test public void globShouldUseDefaultExcludes() throws Exception { + FilePath tmp = new FilePath(tmpRule.getRoot()); try { tmp.child(".gitignore").touch(0); FilePath git = tmp.child(".git"); @@ -59,8 +61,8 @@ public class DirScannerTest extends TestCase { } } - public void testGlobShouldIgnoreDefaultExcludesByRequest() throws Exception { - FilePath tmp = new FilePath(Util.createTempDir()); + @Test public void globShouldIgnoreDefaultExcludesByRequest() throws Exception { + FilePath tmp = new FilePath(tmpRule.getRoot()); try { tmp.child(".gitignore").touch(0); FilePath git = tmp.child(".git"); diff --git a/core/src/test/java/hudson/util/io/TarArchiverTest.java b/core/src/test/java/hudson/util/io/TarArchiverTest.java index a4cbfd5874..3278928ff6 100644 --- a/core/src/test/java/hudson/util/io/TarArchiverTest.java +++ b/core/src/test/java/hudson/util/io/TarArchiverTest.java @@ -34,11 +34,15 @@ import java.io.File; import java.io.FileOutputStream; import static org.junit.Assert.*; import static org.junit.Assume.*; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.jvnet.hudson.test.Bug; public class TarArchiverTest { + @Rule public TemporaryFolder tmp = new TemporaryFolder(); + /** * Makes sure that permissions are properly stored in the tar file. */ @@ -97,7 +101,7 @@ public class TarArchiverTest { @Bug(14922) @Test public void brokenSymlinks() throws Exception { assumeTrue(!Functions.isWindows()); - File dir = Util.createTempDir(); + File dir = tmp.getRoot(); Util.createSymlink(dir, "nonexistent", "link", TaskListener.NULL); new FilePath(dir).tar(new NullStream(), "**"); } diff --git a/core/src/test/java/jenkins/security/ConfidentialStoreRule.java b/core/src/test/java/jenkins/security/ConfidentialStoreRule.java index 6f940b2918..db46255ba6 100644 --- a/core/src/test/java/jenkins/security/ConfidentialStoreRule.java +++ b/core/src/test/java/jenkins/security/ConfidentialStoreRule.java @@ -1,34 +1,26 @@ package jenkins.security; -import hudson.Util; import org.junit.rules.ExternalResource; -import java.io.File; -import java.io.IOException; +import org.junit.rules.TemporaryFolder; /** * Test rule that injects a temporary {@link DefaultConfidentialStore} * @author Kohsuke Kawaguchi */ public class ConfidentialStoreRule extends ExternalResource { - public ConfidentialStore store; - public File tmp; + private final TemporaryFolder tmp = new TemporaryFolder(); @Override protected void before() throws Throwable { - tmp = Util.createTempDir(); - store = new DefaultConfidentialStore(tmp); - ConfidentialStore.TEST.set(store); + tmp.create(); + ConfidentialStore.TEST.set(new DefaultConfidentialStore(tmp.getRoot())); } @Override protected void after() { ConfidentialStore.TEST.set(null); - try { - Util.deleteRecursive(tmp); - } catch (IOException e) { - throw new Error(e); - } + tmp.delete(); } static { diff --git a/test/src/test/java/hudson/model/ItemsTest.java b/test/src/test/java/hudson/model/ItemsTest.java index 566fe380dd..59e168b4e6 100644 --- a/test/src/test/java/hudson/model/ItemsTest.java +++ b/test/src/test/java/hudson/model/ItemsTest.java @@ -27,10 +27,10 @@ package hudson.model; import java.io.File; import java.util.Arrays; -import hudson.Util; import org.junit.Test; import static org.junit.Assert.*; import org.junit.Rule; +import org.junit.rules.TemporaryFolder; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.MockFolder; @@ -38,6 +38,7 @@ import org.jvnet.hudson.test.MockFolder; public class ItemsTest { @Rule public JenkinsRule r = new JenkinsRule(); + @Rule public TemporaryFolder tmpRule = new TemporaryFolder(); @Test public void getAllItems() throws Exception { MockFolder d = r.createFolder("d"); @@ -62,7 +63,7 @@ public class ItemsTest { @Issue("JENKINS-24825") @Test public void moveItem() throws Exception { - File tmp = Util.createTempDir(); + File tmp = tmpRule.getRoot(); r.jenkins.setRawBuildsDir(tmp.getAbsolutePath()+"/${ITEM_FULL_NAME}"); MockFolder foo = r.createFolder("foo"); MockFolder bar = r.createFolder("bar");