Subject: Re: [JGit Patch v2 4/7] Use test resources from classpath

From: "Shawn O. Pearce" <[email-masked]>
Date: Thu, 21 Aug 2008 08:19:04 -0700

[email-masked] wrote:
> From: Imran M Yousuf <[email-masked]>
> 
> Searched and fixed usage of resources, all tests are now passing and using
> classpath resources.
> 
> A utility class for test classes are created. One of its operation turns
> classpath resources to File and it is used by all test classes to locate
> test resources.

I would change the way you do this series a little bit.

Start the series with this patch, only have JGitTestUtil do:

	return new File("test", name);

like DirCacheCGitCompatabilityTest.pathOf does.  That way you
have the code replacement done in the first step, before you start
mucking around with the resource locations.

In the 2nd patch, change JGitTestUtil to get resources from
the classpath, move (not copy) the resources, and add the
tst-rsc directory to the Eclipse .classpath file.

In the 3rd patch, add your Maven POM file, including the .gitignore
for "target".

The tests will always work, and we don't get this weird copy-delete
pair on the resources.

> +/**
> + *
> + * @author imyousuf
> + */
> +public abstract class JGitTestUtil {

We don't comment classes like this.  Either document it for real,
or remove the Javadoc comment entirely.  In "real" documentation
we do not include @author tags.

> +    public static final String CLASSPATH_TO_RESOURCES =
> +        "/org/spearce/jgit/test/resources/";
> +    private JGitTestUtil() {
> +        throw new AssertionError();
> +    }
> +    
> +    public static File getTestResourceFile(String fileName) {
> +        if(fileName == null || fileName.length() <= 0) {

Formatting error.  We put space between "if(".

> +            return null;
> +        }
> +        URL url = JGitTestUtil.class.getResource(
> +            new StringBuilder(CLASSPATH_TO_RESOURCES)
> +                .append(fileName).toString());
> +        return new File(url.getPath());
> +    }
>  }

-- 
Shawn.