KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > util > TemplateTest


1 /**
2  * Mar 25, 2005
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.util;
19
20 import net.sf.uitags.util.Template;
21 import junit.framework.TestCase;
22
23 /**
24  * Tests {@link net.sf.uitags.util.Template}.
25  *
26  * @author hgani
27  * @version $Id: TemplateTest.java,v 1.2 2006/05/03 10:52:44 jonni Exp $
28  */

29 public class TemplateTest extends TestCase {
30
31   /**
32    * Instance of the class under test.
33    */

34   private Template tpl;
35
36   /**
37    * Main method for the tests.
38    *
39    * @param args main arguments
40    */

41   public static void main(String JavaDoc[] args) {
42     junit.textui.TestRunner.run(TemplateTest.class);
43   }
44
45   /** {@inheritDoc} */
46   protected void setUp() throws Exception JavaDoc {
47     super.setUp();
48     this.tpl = Template.forName("test.vm");
49   }
50
51   /** {@inheritDoc} */
52   protected void tearDown() throws Exception JavaDoc {
53     super.tearDown();
54     this.tpl = null;
55   }
56
57   /**
58    * Ensures that all <i>eval</i> methods return correct String value.
59    */

60   public void testEval() {
61     assertEquals("Simple $template loaded!", this.tpl.evalToString().trim());
62     assertEquals(this.tpl.eval().toString(), this.tpl.evalToString());
63   }
64
65   /**
66    * Ensures that objects are mapped properly.
67    */

68   public void testMap() {
69     this.tpl.map("template", "'String' mapped template");
70     assertEquals(this.tpl.evalToString().trim(),
71         "Simple 'String' mapped template loaded!");
72
73     this.tpl.map("template", new Object JavaDoc() {
74       public String JavaDoc toString() {
75         return "'Object' mapped template";
76       }
77     });
78     assertEquals(this.tpl.evalToString().trim(),
79         "Simple 'Object' mapped template loaded!");
80   }
81 }
82
Popular Tags