You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by he...@apache.org on 2006/09/17 12:21:35 UTC

svn commit: r447032 - in /jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test: BaseTestCase.java TestBaseTestCase.java

Author: henning
Date: Sun Sep 17 03:21:33 2006
New Revision: 447032

URL: http://svn.apache.org/viewvc?view=rev&rev=447032
Log:
Make getFileName() more predictable on Windows and *ix, add some
test cases to verify its behaviour.

Added:
    jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/TestBaseTestCase.java   (with props)
Modified:
    jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java

Modified: jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java?view=diff&rev=447032&r1=447031&r2=447032
==============================================================================
--- jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java (original)
+++ jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java Sun Sep 17 03:21:33 2006
@@ -57,35 +57,32 @@
     protected static String getFileName (String dir, String base, String ext)
     {
         StringBuffer buf = new StringBuffer();
-        
-        File baseFile = new File(base);
 
-        if (dir != null)
+        try
         {
-            if (!baseFile.isAbsolute())
-            {
-                baseFile = new File(dir, base);
+            File baseFile = new File(base);
 
-                try
-                {
-                    buf.append(baseFile.getCanonicalPath());
-                }
-                catch (IOException e)
+            if (dir != null)
+            {
+                if (!baseFile.isAbsolute())
                 {
-                    fail("IO Exception while getting canonical path for " + baseFile);
+                    baseFile = new File(dir, base);
                 }
+
+                buf.append(baseFile.getCanonicalPath());
             }
             else
             {
-                buf.append(base);
+                buf.append(baseFile.getPath());
             }
+            
+            buf.append('.').append(ext);
+            
         }
-        else
+        catch (IOException e)
         {
-            buf.append(base);
+            fail("IO Exception while running getFileName(" + dir + ", " + base + ", "+ ext + "): " + e.getMessage());
         }
-
-        buf.append('.').append(ext);
 
         return buf.toString();
     }

Added: jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/TestBaseTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/TestBaseTestCase.java?view=auto&rev=447032
==============================================================================
--- jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/TestBaseTestCase.java (added)
+++ jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/TestBaseTestCase.java Sun Sep 17 03:21:33 2006
@@ -0,0 +1,59 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * I keep breaking the getFileName method all the time...
+ */
+public class TestBaseTestCase
+        extends BaseTestCase
+{
+    public TestBaseTestCase(final String name)
+    {
+        super(name);
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite(TestBaseTestCase.class);
+    }
+
+    public void testGetFileName()
+    	throws Exception
+    {
+        String fs = System.getProperty("file.separator");
+	String pwd = System.getProperty("user.dir");
+
+        String root = new File("/").getCanonicalPath();
+
+        assertEquals(pwd + fs + "baz" + fs + "foo.bar", getFileName("baz",        "foo",  "bar"));
+        assertEquals(root     + "baz" + fs + "foo.bar", getFileName(root + "baz", "foo",  "bar"));
+        assertEquals(root + "foo.bar",                  getFileName("baz",        root + "foo", "bar"));
+        assertEquals(root + "foo.bar",                  getFileName(root + "baz", root + "foo", "bar"));
+        assertEquals(".",                               getFileName(null,         "",     ""));
+        assertEquals(root + ".",                        getFileName("",           "",     ""));
+        assertEquals("foo.bar",                         getFileName(null,         "foo",  "bar"));
+        assertEquals(root + "foo.bar",                  getFileName(null,         root + "foo", "bar"));
+        assertEquals(root + "foo.bar",                  getFileName("",           "foo",  "bar"));
+        assertEquals(root + "foo.bar",                  getFileName("",           root + "foo", "bar"));
+    }
+}

Propchange: jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/TestBaseTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/TestBaseTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org