KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tagutil > AttributeSupportHelperTest


1 /**
2  * Jun 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.tagutil;
19
20 import junit.framework.TestCase;
21
22 /**
23  * Tests {@link net.sf.uitags.tagutil.AttributeSupportHelper}.
24  *
25  * @author hgani
26  * @version $Id: AttributeSupportHelperTest.java,v 1.1.1.1 2006/02/26 11:39:22 hgani Exp $
27  */

28 public final class AttributeSupportHelperTest extends TestCase {
29   /**
30    * Instance of the class under test
31    */

32   private AttributeSupportHelper helper;
33
34   /**
35    * Main method for the tests.
36    *
37    * @param args main arguments
38    */

39   public static void main(String JavaDoc[] args) {
40     junit.textui.TestRunner.run(AttributeSupportHelperTest.class);
41   }
42
43   /** {@inheritDoc} */
44   protected void setUp() throws Exception JavaDoc {
45     super.setUp();
46     this.helper = new AttributeSupportHelper();
47   }
48
49   /** {@inheritDoc} */
50   protected void tearDown() throws Exception JavaDoc {
51     super.tearDown();
52     this.helper = null;
53   }
54
55   /**
56    * Ensures that {@link AttributeSupportHelper#eval()} returns
57    * the correct HTML code.
58    */

59   public void testToString() {
60     this.helper.addAttribute("name1", "value1");
61     this.helper.addAttribute("name2", "value2");
62     this.helper.addAttribute("name3", "value3");
63
64     String JavaDoc htmlCode = this.helper.eval();
65     // make sure that the first character is a space, because the
66
// method guarantees that the generated String can be appended
67
// to a HTMl tag without any modification
68
assertTrue(htmlCode.charAt(0) == ' ');
69     // we can only test whether a specific attribute exist in the String,
70
// because the helper does not guarantee that all attributes are in
71
// certain order
72
assertTrue(htmlCode.indexOf("name1=\"value1\"") >= 0);
73     assertTrue(htmlCode.indexOf("name2=\"value2\"") >= 0);
74     assertTrue(htmlCode.indexOf("name3=\"value3\"") >= 0);
75     assertTrue(htmlCode.indexOf("name1=value1") < 0);
76     assertTrue(htmlCode.indexOf("name1=\"value3\"") < 0);
77     assertTrue(htmlCode.indexOf("name4=\"value4\"") < 0);
78   }
79 }
80
Popular Tags