KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > datatype > convertor > EnumConvertorTestCase


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

16 package org.apache.cocoon.forms.datatype.convertor;
17
18 import java.util.Locale JavaDoc;
19
20 import org.apache.cocoon.forms.datatype.Sex;
21
22 import junit.framework.TestCase;
23
24 /**
25  * Test case for the {@link EnumConvertor} class.
26  *
27  * @version $Id: EnumConvertorTestCase.java 151050 2005-02-02 20:47:40Z tim $
28  */

29 public class EnumConvertorTestCase extends TestCase {
30
31     public EnumConvertorTestCase(String JavaDoc name) {
32         super(name);
33     }
34
35     /**
36      * Test the {@link EnumConvertor#convertFromString(java.lang.String, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
37      * method.
38      */

39     public void testConvertFromString() {
40         EnumConvertor convertor = new EnumConvertor("org.apache.cocoon.forms.datatype.Sex");
41         ConversionResult conversionResult = convertor.convertFromString
42             (Sex.class.getName() + ".FEMALE", Locale.getDefault(), null);
43         assertSame("Returned sex must be FEMALE", Sex.FEMALE, conversionResult.getResult());
44     }
45     
46     /**
47      * Test the {@link EnumConvertor##convertToString(java.lang.Object, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
48      * method.
49      */

50     public void testConvertToString() {
51         EnumConvertor convertor = new EnumConvertor("org.apache.cocoon.forms.datatype.Sex");
52         assertEquals("Converted value must match string",
53                 Sex.class.getName() + ".MALE",
54                 convertor.convertToString
55                     (Sex.MALE, Locale.getDefault(), null));
56     }
57 }
58
Popular Tags