KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > translator > TestStringTranslator


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

15 package org.apache.tapestry.form.translator;
16
17 import org.apache.tapestry.valid.ValidatorException;
18
19 /**
20  * Test case for {@link StringTranslator}.
21  *
22  * @author Paul Ferraro
23  * @since 4.0
24  */

25 public class TestStringTranslator extends TranslatorTestCase
26 {
27     private StringTranslator _translator = new StringTranslator();
28
29     public void testFormat()
30     {
31         replay();
32         
33         String JavaDoc result = _translator.format(_component, "Test this");
34         
35         assertEquals("Test this", result);
36
37         verify();
38     }
39
40     public void testNullFormat()
41     {
42         replay();
43         
44         String JavaDoc result = _translator.format(_component, null);
45         
46         assertEquals("", result);
47
48         verify();
49     }
50
51     public void testParse()
52     {
53         replay();
54         
55         try
56         {
57             String JavaDoc result = (String JavaDoc) _translator.parse(_component, "Test this");
58
59             assertEquals("Test this", result);
60         }
61         catch (ValidatorException e)
62         {
63             unreachable();
64         }
65         finally
66         {
67             verify();
68         }
69     }
70
71     public void testTrimmedParse()
72     {
73         _translator.setTrim(true);
74         
75         replay();
76         
77         try
78         {
79             String JavaDoc result = (String JavaDoc) _translator.parse(_component, " Test this ");
80
81             assertEquals("Test this", result);
82         }
83         catch (ValidatorException e)
84         {
85             unreachable();
86         }
87         finally
88         {
89             verify();
90         }
91     }
92
93     public void testEmptyParse()
94     {
95         replay();
96         
97         try
98         {
99             String JavaDoc result = (String JavaDoc) _translator.parse(_component, "");
100
101             assertEquals(null, result);
102         }
103         catch (ValidatorException e)
104         {
105             unreachable();
106         }
107         finally
108         {
109             verify();
110         }
111     }
112
113     public void testCustomEmptyParse()
114     {
115         _translator.setEmpty("");
116         
117         replay();
118         
119         try
120         {
121             String JavaDoc result = (String JavaDoc) _translator.parse(_component, "");
122
123             assertEquals("", result);
124         }
125         catch (ValidatorException e)
126         {
127             unreachable();
128         }
129         finally
130         {
131             verify();
132         }
133     }
134     
135     public void testRenderContribution()
136     {
137         replay();
138         
139         _translator.renderContribution(null, _cycle, null, _component);
140         
141         verify();
142     }
143     
144     public void testTrimRenderContribution()
145     {
146         _translator.setTrim(true);
147         trim();
148         
149         replay();
150         
151         _translator.renderContribution(null, _cycle, null, _component);
152         
153         verify();
154     }
155 }
156
Popular Tags