01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 de.odysseus.calyxo.forms.convert;
17:
18: import java.text.ParseException;
19:
20: import junit.framework.TestCase;
21:
22: /**
23: * BooleanConverter test case.
24: *
25: * @author Oliver Stuhr
26: */
27: public class BooleanConverterTest extends TestCase {
28:
29: /*
30: * Class under test for String format(Object)
31: */
32: public void testFormatObject() {
33: BooleanConverter converter = new BooleanConverter();
34: assertEquals(null, converter.format(null));
35: assertEquals("false", converter.format(Boolean.FALSE));
36: assertEquals("true", converter.format(Boolean.TRUE));
37:
38: converter = new BooleanConverter("ja", "nein");
39: assertEquals("nein", converter.format(Boolean.FALSE));
40: assertEquals("ja", converter.format(Boolean.TRUE));
41: }
42:
43: /*
44: * Class under test for Object parse(String)
45: */
46: public void testParseString() {
47: BooleanConverter converter = new BooleanConverter();
48: try {
49: assertEquals(null, converter.parse(null));
50: assertEquals(Boolean.FALSE, converter.parse("false"));
51: assertEquals(Boolean.TRUE, converter.parse("true"));
52:
53: converter = new BooleanConverter("ja", "nein");
54: converter.setDefault(Boolean.FALSE);
55:
56: assertEquals(Boolean.FALSE, converter.parse(null));
57: assertEquals(Boolean.FALSE, converter.parse("nein"));
58: assertEquals(Boolean.TRUE, converter.parse("ja"));
59: } catch (ParseException e) {
60: fail("-> ParseException: " + e);
61: }
62: }
63: }
|