dlr         00/10/23 19:03:38

  Modified:    src/java/org/apache/velocity/test TemplateTestCase.java
  Log:
  Build those file names a little more efficiently.
  
  Revision  Changes    Path
  1.8       +29 -26    
jakarta-velocity/src/java/org/apache/velocity/test/TemplateTestCase.java
  
  Index: TemplateTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/TemplateTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TemplateTestCase.java     2000/10/24 01:43:33     1.7
  +++ TemplateTestCase.java     2000/10/24 02:03:37     1.8
  @@ -73,7 +73,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: TemplateTestCase.java,v 1.7 2000/10/24 01:43:33 jvanzyl Exp $
  + * @version $Id: TemplateTestCase.java,v 1.8 2000/10/24 02:03:37 dlr Exp $
    */
   public class TemplateTestCase extends BaseTestCase
   {
  @@ -95,12 +95,12 @@
       /**
        * Results relative to the build directory.
        */
  -    private static final String RESULT_DIR = "../test/templates/results/";
  +    private static final String RESULT_DIR = "../test/templates/results";
   
       /**
        * Results relative to the build directory.
        */
  -    private static final String COMPARE_DIR = "../test/templates/compare/";
  +    private static final String COMPARE_DIR = "../test/templates/compare";
   
       /**
        * The base file name of the template and comparison file (i.e. array for 
  @@ -158,14 +158,10 @@
       {
           try
           {
  -            StringBuffer buf = new StringBuffer();
  -            buf.append(baseFileName).append('.').append(TMPL_FILE_EXT);
  -            Template template = Runtime.getTemplate(buf.toString());
  -
  -            template.merge(context, getWriter(
  -                new FileOutputStream(
  -                    RESULT_DIR + baseFileName + "." + RESULT_FILE_EXT)));
  -            
  +            Template template = Runtime.getTemplate
  +                (getFileName(null, baseFileName, TMPL_FILE_EXT));
  +            template.merge(context, getWriter(new FileOutputStream
  +                (getFileName(RESULT_DIR, baseFileName, RESULT_FILE_EXT))));
               closeWriter();
               
               if (!isMatch())
  @@ -180,6 +176,22 @@
       }
   
       /**
  +     * Concatnates the file name parts together appropriately.
  +     *
  +     * @return The full path to the file.
  +     */
  +    private String getFileName (String dir, String base, String ext)
  +    {
  +        StringBuffer buf = new StringBuffer();
  +        if (dir != null)
  +        {
  +            buf.append(dir).append('/');
  +        }
  +        buf.append(base).append('.').append(ext);
  +        return buf.toString();
  +    }
  +
  +    /**
        * Turns a base file name into a test case name.
        *
        * @param s The base file name.
  @@ -213,11 +225,11 @@
        */
       protected boolean isMatch () throws Exception
       {
  -        String result = StringUtils.fileContentsToString(
  -            RESULT_DIR + baseFileName + "." + RESULT_FILE_EXT);
  +        String result = StringUtils.fileContentsToString
  +            (getFileName(RESULT_DIR, baseFileName, RESULT_FILE_EXT));
               
  -        String compare = StringUtils.fileContentsToString(
  -            COMPARE_DIR + baseFileName + "." + CMP_FILE_EXT);
  +        String compare = StringUtils.fileContentsToString
  +             (getFileName(COMPARE_DIR, baseFileName, CMP_FILE_EXT));
   
           return result.equals(compare);
       }
  @@ -225,18 +237,9 @@
       /**
        * Performs cleanup activities for this test case.
        */
  -    protected void tearDown ()
  +    protected void tearDown () throws Exception
       {
  -        /*
  -        try
  -        {
  -            closeWriter();
  -        }
  -        catch (IOException e)
  -        {
  -            fail(e.getMessage());
  -        }
  -        */
  +        // No op.
       }
   
       /**
  
  
  

Reply via email to