01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.datatype.convertor;
18:
19: import java.util.Locale;
20:
21: import org.apache.cocoon.forms.datatype.Sex;
22:
23: import junit.framework.TestCase;
24:
25: /**
26: * Test case for the {@link EnumConvertor} class.
27: *
28: * @version $Id: EnumConvertorTestCase.java 449149 2006-09-23 03:58:05Z crossley $
29: */
30: public class EnumConvertorTestCase extends TestCase {
31:
32: public EnumConvertorTestCase(String name) {
33: super (name);
34: }
35:
36: /**
37: * Test the {@link EnumConvertor#convertFromString(java.lang.String, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
38: * method.
39: */
40: public void testConvertFromString() {
41: EnumConvertor convertor = new EnumConvertor(
42: "org.apache.cocoon.forms.datatype.Sex");
43: ConversionResult conversionResult = convertor
44: .convertFromString(Sex.class.getName() + ".FEMALE",
45: Locale.getDefault(), null);
46: assertSame("Returned sex must be FEMALE", Sex.FEMALE,
47: conversionResult.getResult());
48: }
49:
50: /**
51: * Test the {@link EnumConvertor##convertToString(java.lang.Object, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
52: * method.
53: */
54: public void testConvertToString() {
55: EnumConvertor convertor = new EnumConvertor(
56: "org.apache.cocoon.forms.datatype.Sex");
57: assertEquals("Converted value must match string", Sex.class
58: .getName()
59: + ".MALE", convertor.convertToString(Sex.MALE, Locale
60: .getDefault(), null));
61: }
62: }
|