提交 b415b467 编写于 作者: J Jesse Glick

Replacing Util.createTempDir with the standard TemporaryFolder rule in some tests.

上级 89cdd511
......@@ -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("<root><stuff plugin='stuff@1.0'><more plugin='other@2.0'><things plugin='stuff@1.2'/></more></stuff></root>")).toString());
}
......
......@@ -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<String,String> m = new HashMap<String,String>();
......@@ -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);
......
......@@ -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 {
@Rule public TemporaryFolder tmpRule = new TemporaryFolder();
public void testGlobShouldUseDefaultExcludes() throws Exception {
FilePath tmp = new FilePath(Util.createTempDir());
@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");
......
......@@ -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(), "**");
}
......
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 {
......
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册