KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > coerce > TestTypeConverterWrapper


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.coerce;
16
17 import java.util.Collections JavaDoc;
18
19 import org.apache.hivemind.test.HiveMindTestCase;
20 import org.easymock.MockControl;
21
22 /**
23  * Tests for {@link org.apache.tapestry.coerce.TypeConverterWrapper}.
24  *
25  * @author Howard M. Lewis Ship
26  * @since 4.0
27  */

28 public class TestTypeConverterWrapper extends HiveMindTestCase
29 {
30     public void testNonNull()
31     {
32         MockControl tcc = newControl(TypeConverter.class);
33         TypeConverter tc = (TypeConverter) tcc.getMock();
34
35         Object JavaDoc expected = "BARNEY";
36
37         tc.convertValue("FRED");
38         tcc.setReturnValue(expected);
39
40         replayControls();
41
42         TypeConverterContribution contrib = new TypeConverterContribution();
43         contrib.setSubjectClass(Object JavaDoc.class);
44         contrib.setConverter(tc);
45
46         TypeConverterWrapper w = new TypeConverterWrapper();
47
48         w.setContributions(Collections.singletonList(contrib));
49
50         w.initializeService();
51
52         Object JavaDoc actual = w.convertValue("FRED");
53
54         assertSame(expected, actual);
55
56         verifyControls();
57     }
58
59     public void testNull()
60     {
61         MockControl tcc = newControl(TypeConverter.class);
62         TypeConverter tc = (TypeConverter) tcc.getMock();
63
64         Object JavaDoc expected = "NULL";
65
66         tc.convertValue(null);
67         tcc.setReturnValue(expected);
68
69         replayControls();
70
71         TypeConverterWrapper w = new TypeConverterWrapper();
72
73         w.setNullConverter(tc);
74
75         Object JavaDoc actual = w.convertValue(null);
76
77         assertSame(expected, actual);
78
79         verifyControls();
80     }
81
82     public void testNullWithNoNullConverter()
83     {
84         TypeConverterWrapper w = new TypeConverterWrapper();
85
86         assertNull(w.convertValue(null));
87     }
88 }
Popular Tags