1   package org.apache.velocity.test;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  
28  import org.apache.velocity.runtime.RuntimeInstance;
29  import org.apache.velocity.util.StringUtils;
30  
31  /**
32   * Test case for any miscellaneous stuff.  If it isn't big, and doesn't fit
33   * anywhere else, it goes here
34   *
35   * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
36   * @version $Id: MiscTestCase.java 473760 2006-11-11 16:55:40Z wglass $
37   */
38  public class MiscTestCase extends BaseTestCase
39  {
40      public MiscTestCase (String name)
41      {
42          super(name);
43      }
44  
45      public static Test suite ()
46      {
47          return new TestSuite(MiscTestCase.class);
48      }
49  
50      public void testRuntimeInstanceProperties()
51      {
52          // check that runtime instance properties can be set and retrieved
53          RuntimeInstance ri = new RuntimeInstance();
54          ri.setProperty("baabaa.test","the answer");
55          assertEquals("the answer",ri.getProperty("baabaa.test"));
56      }
57      
58      public void testStringUtils()
59      {
60          /*
61           *  some StringUtils tests
62           */
63  
64          String eol = "XY";
65  
66          String arg = "XY";
67          String res = StringUtils.chop(arg, 1, eol );
68          assertTrue( "Test 1", res.equals("") );
69  
70          arg = "X";
71          res = StringUtils.chop( arg, 1, eol );
72          assertTrue( "Test 2", res.equals("") );
73  
74          arg = "ZXY";
75          res = StringUtils.chop( arg, 1, eol );
76          assertTrue( "Test 3", res.equals("Z") );
77  
78  
79          arg = "Hello!";
80          res = StringUtils.chop( arg, 2, eol );
81          assertTrue( "Test 4", res.equals("Hell"));
82  
83          arg = null;
84          res = StringUtils.nullTrim(arg);
85          assertNull(arg);
86  
87          arg = " test ";
88          res = StringUtils.nullTrim(arg);
89          assertEquals("test",res);
90  
91          arg = "test";
92          res = StringUtils.nullTrim(arg);
93          assertEquals("test",res);
94  
95          List list = null;
96          assertNull(StringUtils.trimStrings(list));
97  
98          list = new ArrayList();
99          assertEquals(new ArrayList(),StringUtils.trimStrings(list));
100 
101         list.add("test");
102         list.add(" abc");
103         StringUtils.trimStrings(list);
104         assertEquals("test",list.get(0));
105         assertEquals("abc",list.get(1));
106 
107     }
108 
109 }