git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 2/2] Move pathOf to RepositoryTestCase and use it for locating test files

From
Jonas Fonseca <fonseca@diku.dk>
Date
Sep 3, 2008, 09:10 UTC
Message-ID
<20080903091022.GC23406@diku.dk>
This simplifies the code for accessing files.
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 This is a workaround patch disguised as a cleanup patch. For NetBeans I
 am not yet sure how to setup JGit as a project where everythng works.
 For now I need to be able to override the path to files used by the
 tests and this patch reduces that change to one single place.
 .../dircache/DirCacheCGitCompatabilityTest.java    |    4 ----
 .../tst/org/spearce/jgit/lib/PackIndexV1Test.java  |    6 ++----
 .../tst/org/spearce/jgit/lib/PackIndexV2Test.java  |    6 ++----
 .../org/spearce/jgit/lib/PackReverseIndexTest.java |    3 +--
 .../tst/org/spearce/jgit/lib/PackWriterTest.java   |    3 +--
 .../org/spearce/jgit/lib/RepositoryTestCase.java   |    8 ++++++--
 .../tst/org/spearce/jgit/lib/T0004_PackReader.java |    4 ++--
 .../org/spearce/jgit/transport/IndexPackTest.java  |    4 ++--
 8 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/dircache/DirCacheCGitCompatabilityTest.java
index 43b23f6..f8f7fe9 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/dircache/DirCacheCGitCompatabilityTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/dircache/DirCacheCGitCompatabilityTest.java
@@ -137,10 +137,6 @@ assertEquals(ObjectId
 		}
 	}
 
-	private File pathOf(final String name) {
-		return new File("tst", name);
-	}
-
 	private Map<String, CGitIndexRecord> readLsFiles() throws Exception {
 		final LinkedHashMap<String, CGitIndexRecord> r = new LinkedHashMap<String, CGitIndexRecord>();
 		final BufferedReader br = new BufferedReader(new InputStreamReader(
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java
index 49235ca..036aacb 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java
@@ -44,14 +44,12 @@
 public class PackIndexV1Test extends PackIndexTest {
 	@Override
 	public File getFileForPack34be9032() {
-		return new File(new File("tst"),
-				"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx");
+		return pathOf("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx");
 	}
 
 	@Override
 	public File getFileForPackdf2982f28() {
-		return new File(new File("tst"),
-				"pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx");
+		return pathOf("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx");
 	}
 
 	/**
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java
index c986c49..c44edcf 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java
@@ -44,14 +44,12 @@
 public class PackIndexV2Test extends PackIndexTest {
 	@Override
 	public File getFileForPack34be9032() {
-		return new File(new File("tst"),
-				"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2");
+		return pathOf("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2");
 	}
 
 	@Override
 	public File getFileForPackdf2982f28() {
-		return new File(new File("tst"),
-				"pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2");
+		return pathOf("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2");
 	}
 
 	/**
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java
index 52d1282..63bf083 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java
@@ -54,8 +54,7 @@
 	public void setUp() throws Exception {
 		super.setUp();
 		// index with both small (< 2^31) and big offsets
-		idx = PackIndex.open(new File(new File("tst"),
-				"pack-huge.idx"));
+		idx = PackIndex.open(pathOf("pack-huge.idx"));
 		reverseIdx = new PackReverseIndex(idx);
 	}
 
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
index 4dd4b2a..c715182 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
@@ -239,8 +239,7 @@ public void testWritePack2DeltasCRC32Copy() throws IOException {
 				"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
 		final File crc32Idx = new File(packDir,
 				"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx");
-		copyFile(new File(new File("tst"),
-				"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2"),
+		copyFile(pathOf("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2"),
 				crc32Idx);
 		db.openPack(crc32Pack, crc32Idx);
 
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
index 14e7179..610296f 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
@@ -50,7 +50,7 @@
 
 public abstract class RepositoryTestCase extends TestCase {
 
-	protected final File trashParent = new File("trash");
+	protected final File trashParent = pathOf("trash");
 
 	protected File trash;
 
@@ -65,6 +65,10 @@
 		jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com");
 	}
 
+	protected static File pathOf(final String name) {
+		return new File("tst", name);
+	}
+
 	protected static void recursiveDelete(final File dir) {
 		final File[] ls = dir.listFiles();
 		if (ls != null) {
@@ -142,7 +146,7 @@ public void run() {
 				"pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745",
 				"pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa"
 		};
-		final File tst = new File("tst");
+		final File tst = pathOf(".");
 		final File packDir = new File(db.getObjectsDirectory(), "pack");
 		for (int k = 0; k < packs.length; k++) {
 			copyFile(new File(tst, packs[k] + ".pack"), new File(packDir,
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0004_PackReader.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0004_PackReader.java
index c036e79..fa95939 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0004_PackReader.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0004_PackReader.java
@@ -43,7 +43,7 @@
 
 public class T0004_PackReader extends RepositoryTestCase {
 	private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
-	private static final File TEST_PACK = new File(new File("tst"), PACK_NAME + ".pack");
+	private static final File TEST_PACK = pathOf(PACK_NAME + ".pack");
 	private static final File TEST_IDX = new File(TEST_PACK.getParentFile(), PACK_NAME + ".idx");
 
 	public void test003_lookupCompressedObject() throws IOException {
@@ -77,7 +77,7 @@ public void test004_lookupDeltifiedObject() throws IOException {
 	}
 
 	public void test005_todopack() throws IOException {
-		final File todopack = new File(new File("tst"), "todopack");
+		final File todopack = pathOf("todopack");
 		if (!todopack.isDirectory()) {
 			System.err.println("Skipping " + getName() + ": no " + todopack);
 			return;
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/IndexPackTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/IndexPackTest.java
index ffa9142..18575c8 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/IndexPackTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/IndexPackTest.java
@@ -63,7 +63,7 @@
 	 * @throws IOException
 	 */
 	public void test1() throws  IOException {
-		File packFile = new File("tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
+		File packFile = pathOf("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
 		final InputStream is = new FileInputStream(packFile);
 		try {
 			IndexPack pack = new IndexPack(db, is, new File(trash, "tmp_pack1"));
@@ -89,7 +89,7 @@ public void test1() throws  IOException {
 	 * @throws IOException
 	 */
 	public void test2() throws  IOException {
-		File packFile = new File("tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");
+		File packFile = pathOf("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");
 		final InputStream is = new FileInputStream(packFile);
 		try {
 			IndexPack pack = new IndexPack(db, is, new File(trash, "tmp_pack2"));
-- 
1.6.0.336.ga07ba



-- 
Jonas Fonseca
Next: Shawn O. Pearce
Message 1 of 13 in “Move pathOf to RepositoryTestCase and use it for locating test files”
  1. 2/2 Move pathOf to RepositoryTestCase and use it for locating test filesJonas Fonseca, Sep 3, 2008
  2. Shawn O. PearceSep 3, 2008
  3. Jonas FonsecaSep 3, 2008
  4. Shawn O. PearceSep 3, 2008
  5. Jonas FonsecaSep 3, 2008
  6. Shawn O. PearceSep 4, 2008
  7. Imran M YousufSep 4, 2008
  8. Imran M YousufSep 4, 2008
  9. Shawn O. PearceSep 4, 2008
  10. Jonas FonsecaSep 4, 2008
  11. Jakub NarebskiSep 4, 2008
  12. Jonas FonsecaSep 4, 2008
  13. Imran M YousufSep 5, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.