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