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.math.BigInteger;
19: import java.text.ParseException;
20:
21: import junit.framework.TestCase;
22:
23: /**
24: * BigIntegerConverter test case.
25: *
26: * @author Oliver Stuhr
27: */
28: public class BigIntegerConverterTest extends TestCase {
29: static final BigInteger[] BIGINTEGERS = new BigInteger[] {
30: new BigInteger("-1"),
31: new BigInteger("0"),
32: new BigInteger("1"),
33: new BigInteger("" + Long.MIN_VALUE)
34: .multiply(new BigInteger("2")),
35: new BigInteger("" + Long.MAX_VALUE)
36: .multiply(new BigInteger("2")) };
37:
38: /*
39: * Class under test for String format(Object) and Object parse(String)
40: */
41: public void test() {
42: BigIntegerConverter converter = new BigIntegerConverter();
43:
44: for (int i = 0; i < BIGINTEGERS.length; i++)
45: try {
46: assertEquals(BIGINTEGERS[i], converter.parse(converter
47: .format(BIGINTEGERS[i])));
48: } catch (ParseException e) {
49: fail("-> ParseException: " + e);
50: }
51:
52: try {
53: // assertEquals("0", converter.format(converter.parse(" 0")));
54: // assertEquals("0", converter.format(converter.parse("0 ")));
55: assertEquals("0", converter.format(converter.parse("00")));
56: // assertEquals("0", converter.format(converter.parse("+0")));
57: assertEquals("0", converter.format(converter.parse("-0")));
58: // assertEquals("0", converter.format(converter.parse("0.")));
59: } catch (ParseException e) {
60: fail("-> ParseException: " + e);
61: }
62: }
63: }
|