Re: [PATCH JGit 01/19] adding tests for ObjectDirectory
- From
Robin Rosenberg <robin.rosenberg.lists@dewire.com>
- Date
- Sep 15, 2009, 15:38 UTC
- Message-ID
- <200909151738.05742.robin.rosenberg.lists@dewire.com>
- In-Reply-To
- <1252867475-858-2-git-send-email-mr.gaffo@gmail.com>
söndag 13 september 2009 20:44:17 skrev mr.gaffo@gmail.com:
Show 28 quoted lines
> From: mike.gaffney <mike.gaffney@asolutions.com>
>
> ---
> .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 80 ++++++++++++++++++++
> 1 files changed, 80 insertions(+), 0 deletions(-)
> create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
>
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> new file mode 100644
> index 0000000..fe019af
> --- /dev/null
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> @@ -0,0 +1,80 @@
> +package org.spearce.jgit.lib;
> +
> +import java.io.File;
> +import java.util.UUID;
> +
> +import junit.framework.TestCase;
> +
> +public class ObjectDirectoryTest extends TestCase {
> +
> + private File testDir;
> +
> + @Override
> + protected void setUp() throws Exception {
> + testDir = new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString());
> + }Good. Now that we're on Java5 we might use this more.
Show 9 quoted lines
> + public void testGettingObjectFile() throws Exception {
> + ObjectDirectory od = new ObjectDirectory(testDir);
> + assertEquals(new File(testDir, "02/829ae153935095e4223f30cfc98c835de71bee"),
> + od.fileFor(ObjectId.fromString("02829ae153935095e4223f30cfc98c835de71bee")));
> + assertEquals(new File(testDir, "b0/52a1272310d8df34de72f60204dee7e28a43d0"),
> + od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0")));
> + }
> +
> + public boolean deleteDir(File dir) {RepositoryTestcase already contains a recursive delete, including a static one that you can use even without inheritance since you are within the same package. It is rather standalone so it could perhaps move to JGitTestUtil.
Show 16 quoted lines
> + if (dir.isDirectory()) {
> + String[] children = dir.list();
> + for (int i=0; i<children.length; i++) {
> + boolean success = deleteDir(new File(dir, children[i]));
> + if (!success) {
> + return false;
> + }
> + }
> + }
> +
> + // The directory is now empty so delete it
> + return dir.delete();
> + }
> +
> + private void createTestDir(){
> + testDir.mkdir();No error checking. If mkdirfails the test probably fails for mysterious reasons,
> + } > + > +}