001: package org.apache.velocity.test;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import junit.framework.Test;
026: import junit.framework.TestSuite;
027:
028: import org.apache.velocity.runtime.RuntimeInstance;
029: import org.apache.velocity.util.StringUtils;
030:
031: /**
032: * Test case for any miscellaneous stuff. If it isn't big, and doesn't fit
033: * anywhere else, it goes here
034: *
035: * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
036: * @version $Id: MiscTestCase.java 473760 2006-11-11 16:55:40Z wglass $
037: */
038: public class MiscTestCase extends BaseTestCase {
039: public MiscTestCase(String name) {
040: super (name);
041: }
042:
043: public static Test suite() {
044: return new TestSuite(MiscTestCase.class);
045: }
046:
047: public void testRuntimeInstanceProperties() {
048: // check that runtime instance properties can be set and retrieved
049: RuntimeInstance ri = new RuntimeInstance();
050: ri.setProperty("baabaa.test", "the answer");
051: assertEquals("the answer", ri.getProperty("baabaa.test"));
052: }
053:
054: public void testStringUtils() {
055: /*
056: * some StringUtils tests
057: */
058:
059: String eol = "XY";
060:
061: String arg = "XY";
062: String res = StringUtils.chop(arg, 1, eol);
063: assertTrue("Test 1", res.equals(""));
064:
065: arg = "X";
066: res = StringUtils.chop(arg, 1, eol);
067: assertTrue("Test 2", res.equals(""));
068:
069: arg = "ZXY";
070: res = StringUtils.chop(arg, 1, eol);
071: assertTrue("Test 3", res.equals("Z"));
072:
073: arg = "Hello!";
074: res = StringUtils.chop(arg, 2, eol);
075: assertTrue("Test 4", res.equals("Hell"));
076:
077: arg = null;
078: res = StringUtils.nullTrim(arg);
079: assertNull(arg);
080:
081: arg = " test ";
082: res = StringUtils.nullTrim(arg);
083: assertEquals("test", res);
084:
085: arg = "test";
086: res = StringUtils.nullTrim(arg);
087: assertEquals("test", res);
088:
089: List list = null;
090: assertNull(StringUtils.trimStrings(list));
091:
092: list = new ArrayList();
093: assertEquals(new ArrayList(), StringUtils.trimStrings(list));
094:
095: list.add("test");
096: list.add(" abc");
097: StringUtils.trimStrings(list);
098: assertEquals("test", list.get(0));
099: assertEquals("abc", list.get(1));
100:
101: }
102:
103: }
|