summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2012-09-25 16:56:58 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2012-09-25 16:56:58 -0400
commit83e7554e177cb9226d9b17f1e214e2b3dd80e881 (patch)
treefe7612e52b4fbc4c2c069c0b52c558398e0d233f
parent01a33350eef2f83f75f23485aa179314e278ebca (diff)
parent9ea38173ccc5e4ef76abb9317fd7a1a221a228c6 (diff)
downloadjgit-83e7554e177cb9226d9b17f1e214e2b3dd80e881.tar.gz
jgit-83e7554e177cb9226d9b17f1e214e2b3dd80e881.zip
Merge "Provide a convenient read() in RepositoryTestCase"
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java22
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java4
3 files changed, 27 insertions, 13 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 b3376a54be..4bf597a807 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
@@ -56,6 +56,7 @@ import java.net.URL;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -174,6 +175,27 @@ public abstract class JGitTestUtil {
}
}
+ /**
+ * Fully read a UTF-8 file and return as a string.
+ *
+ * @param file
+ * file to read the content of.
+ * @return UTF-8 decoded content of the file, empty string if the file
+ * exists but has no content.
+ * @throws IOException
+ * the file does not exist, or could not be read.
+ */
+ public static String read(final File file) throws IOException {
+ final byte[] body = IO.readFully(file);
+ return new String(body, 0, body.length, "UTF-8");
+ }
+
+ public static String read(final FileRepository db, final String name)
+ throws IOException {
+ File file = new File(db.getWorkTree(), name);
+ return read(file);
+ }
+
public static void deleteTrashFile(final FileRepository db,
final String name) throws IOException {
File path = new File(db.getWorkTree(), name);
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 d8ae705c48..676698a8e2 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
@@ -68,7 +68,6 @@ import org.eclipse.jgit.storage.file.WindowCache;
import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
-import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
import org.junit.Before;
@@ -435,19 +434,8 @@ public abstract class LocalDiskRepositoryTestCase {
JGitTestUtil.write(f, body);
}
- /**
- * Fully read a UTF-8 file and return as a string.
- *
- * @param f
- * file to read the content of.
- * @return UTF-8 decoded content of the file, empty string if the file
- * exists but has no content.
- * @throws IOException
- * the file does not exist, or could not be read.
- */
protected String read(final File f) throws IOException {
- final byte[] body = IO.readFully(f);
- return new String(body, 0, body.length, "UTF-8");
+ return JGitTestUtil.read(f);
}
private static String[] toEnvArray(final Map<String, String> env) {
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 457fd1a7ef..dd03427f9c 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
@@ -108,6 +108,10 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
return JGitTestUtil.writeTrashFile(db, subdir, name, data);
}
+ protected String read(final String name) throws IOException {
+ return JGitTestUtil.read(db, name);
+ }
+
protected void deleteTrashFile(final String name) throws IOException {
JGitTestUtil.deleteTrashFile(db, name);
}