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