aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2012-01-24 19:24:09 (EST)
committerDariusz Luksza2012-01-24 19:24:41 (EST)
commitb649eaa9a84819f48a9434af67ecab7e6881f37e (patch)
treebfac84d0f8e417f395f65c9859db872409f96049
parent2fa5bcd6bbf9e4905c9e022fa1cb371b96a02694 (diff)
downloadjgit-b649eaa9a84819f48a9434af67ecab7e6881f37e.zip
jgit-b649eaa9a84819f48a9434af67ecab7e6881f37e.tar.gz
jgit-b649eaa9a84819f48a9434af67ecab7e6881f37e.tar.bz2
Move writeTrashFile and deleteFile into JGitTestUtilrefs/changes/82/4982/2
Moves RepositoryTestCase.writeThashFile, RepositoryTestCase.deleteFile and dependencies into JGitTestUtil for further reuse. Required-by-EGit: If8dfa0251797aca56ddc825619500dc21885ba26 Change-Id: I6fc62c8e6626f907e544b5bbe5d64e864a2c323f Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java45
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java11
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java8
3 files changed, 49 insertions, 15 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
index 38a451f..d3da09f 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
@@ -46,10 +46,16 @@
package org.eclipse.jgit.junit;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.net.URL;
+import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.RawParseUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -127,4 +133,43 @@ public abstract class JGitTestUtil {
private static ClassLoader cl() {
return JGitTestUtil.class.getClassLoader();
}
+
+ public static File writeTrashFile(final FileRepository db,
+ final String name, final String data) throws IOException {
+ File path = new File(db.getWorkTree(), name);
+ write(path, data);
+ return path;
+ }
+
+ /**
+ * Write a string as a UTF-8 file.
+ *
+ * @param f
+ * file to write the string to. Caller is responsible for making
+ * sure it is in the trash directory or will otherwise be cleaned
+ * up at the end of the test. If the parent directory does not
+ * exist, the missing parent directories are automatically
+ * created.
+ * @param body
+ * content to write to the file.
+ * @throws IOException
+ * the file could not be written.
+ */
+ public static void write(final File f, final String body)
+ throws IOException {
+ FileUtils.mkdirs(f.getParentFile(), true);
+ Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
+ try {
+ w.write(body);
+ } finally {
+ w.close();
+ }
+ }
+
+ public static void deleteTrashFile(final FileRepository db,
+ final String name) throws IOException {
+ File path = new File(db.getWorkTree(), name);
+ FileUtils.delete(path);
+ }
+
}
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
index 0c7ae7d..d8ae705 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
@@ -49,10 +49,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -435,13 +432,7 @@ public abstract class LocalDiskRepositoryTestCase {
* the file could not be written.
*/
protected void write(final File f, final String body) throws IOException {
- FileUtils.mkdirs(f.getParentFile(), true);
- Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
- try {
- w.write(body);
- } finally {
- w.close();
- }
+ JGitTestUtil.write(f, body);
}
/**
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
index 934c76c..0c573eb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
@@ -62,6 +62,7 @@ import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -98,14 +99,11 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected File writeTrashFile(final String name, final String data)
throws IOException {
- File path = new File(db.getWorkTree(), name);
- write(path, data);
- return path;
+ return JGitTestUtil.writeTrashFile(db, name, data);
}
protected void deleteTrashFile(final String name) throws IOException {
- File path = new File(db.getWorkTree(), name);
- FileUtils.delete(path);
+ JGitTestUtil.deleteTrashFile(db, name);
}
protected static void checkFile(File f, final String checkData)