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

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 21, 2008, 15:19 UTC
Message-ID
<20080821151904.GT3483@spearce.org>
In-Reply-To
<1219288394-1241-4-git-send-email-imyousuf@gmail.com>
imyousuf@gmail.com wrote:
Show 8 quoted lines
> From: Imran M Yousuf <imyousuf@smartitengineering.com>
> 
> 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.

Show 5 quoted lines
> +/**
> + *
> + * @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.

Show 8 quoted lines
> +    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(".
Show 8 quoted lines
> +            return null;
> +        }
> +        URL url = JGitTestUtil.class.getResource(
> +            new StringBuilder(CLASSPATH_TO_RESOURCES)
> +                .append(fileName).toString());
> +        return new File(url.getPath());
> +    }
>  }
-- 
Shawn.
Previous: Imran M YousufNext: imyousuf@gmail.com
Message 10 of 11 in “Add a POM file for setting JGit library as a Maven project”
  1. 1/7 Add a POM file for setting JGit library as a Maven projectimyousuf@gmail.com, Aug 21, 2008
  2. 2/7 Add test resources to a new package structured directoryimyousuf@gmail.com, Aug 21, 2008
  3. 3/7 Add test resources directory as a classpath entryimyousuf@gmail.com, Aug 21, 2008
  4. 4/7 Use test resources from classpathimyousuf@gmail.com, Aug 21, 2008
  5. 5/7 Add script for adding second pack for test purposeimyousuf@gmail.com, Aug 21, 2008
  6. Shawn O. PearceAug 21, 2008
  7. Imran M YousufAug 22, 2008
  8. Shawn O. PearceAug 22, 2008
  9. Imran M YousufAug 23, 2008
  10. Shawn O. PearceAug 21, 2008
  11. 7/7 Add ignore list for mavenized JGitimyousuf@gmail.com, Aug 21, 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.