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: * IntegerConverter test case.
24: *
25: * @author Oliver Stuhr
26: */
27: public class IntegerConverterTest extends TestCase {
28: static final Integer[] INTEGERS = new Integer[] {
29: new Integer(Integer.MIN_VALUE), new Integer("-1"),
30: new Integer("0"), new Integer("1"),
31: new Integer(Integer.MAX_VALUE) };
32:
33: /*
34: * Class under test for String format(Object) and Object parse(String)
35: */
36: public void test() {
37: IntegerConverter converter = new IntegerConverter();
38:
39: for (int i = 0; i < INTEGERS.length; i++)
40: try {
41: assertEquals(INTEGERS[i], converter.parse(converter
42: .format(INTEGERS[i])));
43: } catch (ParseException e) {
44: fail("-> ParseException: " + e);
45: }
46:
47: try {
48: assertEquals("0", converter.format(converter.parse(" 0")));
49: assertEquals("0", converter.format(converter.parse("0 ")));
50: assertEquals("0", converter.format(converter.parse("00")));
51: // assertEquals("0", converter.format(converter.parse("+0")));
52: assertEquals("0", converter.format(converter.parse("-0")));
53: // assertEquals("0", converter.format(converter.parse("0.")));
54: } catch (ParseException e) {
55: fail("-> ParseException: " + e);
56: }
57: }
58: }
|