001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.beanutils.converters;
019:
020: import java.math.BigInteger;
021:
022: import junit.framework.TestSuite;
023:
024: import org.apache.commons.beanutils.Converter;
025:
026: /**
027: * Test Case for the BigInteger class.
028: *
029: * @version $Revision: 471348 $ $Date $
030: */
031: public class BigIntegerConverterTestCase extends
032: NumberConverterTestBase {
033:
034: private Converter converter = null;
035:
036: // ------------------------------------------------------------------------
037:
038: public BigIntegerConverterTestCase(String name) {
039: super (name);
040: }
041:
042: // ------------------------------------------------------------------------
043:
044: public void setUp() throws Exception {
045: converter = makeConverter();
046: numbers[0] = new BigInteger("-12");
047: numbers[1] = new BigInteger("13");
048: numbers[2] = new BigInteger("-22");
049: numbers[3] = new BigInteger("23");
050: }
051:
052: public static TestSuite suite() {
053: return new TestSuite(BigIntegerConverterTestCase.class);
054: }
055:
056: public void tearDown() throws Exception {
057: converter = null;
058: }
059:
060: // ------------------------------------------------------------------------
061:
062: protected NumberConverter makeConverter() {
063: return new BigIntegerConverter();
064: }
065:
066: protected NumberConverter makeConverter(Object defaultValue) {
067: return new BigIntegerConverter(defaultValue);
068: }
069:
070: protected Class getExpectedType() {
071: return BigInteger.class;
072: }
073:
074: // ------------------------------------------------------------------------
075:
076: public void testSimpleConversion() throws Exception {
077: String[] message = { "from String", "from String",
078: "from String", "from String", "from String",
079: "from String", "from String", "from Byte",
080: "from Short", "from Integer", "from Long",
081: "from Float", "from Double" };
082:
083: Object[] input = { String.valueOf(Long.MIN_VALUE), "-17", "-1",
084: "0", "1", "17", String.valueOf(Long.MAX_VALUE),
085: new Byte((byte) 7), new Short((short) 8),
086: new Integer(9), new Long(10), new Float(11.1),
087: new Double(12.2) };
088:
089: BigInteger[] expected = { BigInteger.valueOf(Long.MIN_VALUE),
090: BigInteger.valueOf(-17), BigInteger.valueOf(-1),
091: BigInteger.valueOf(0), BigInteger.valueOf(1),
092: BigInteger.valueOf(17),
093: BigInteger.valueOf(Long.MAX_VALUE),
094: BigInteger.valueOf(7), BigInteger.valueOf(8),
095: BigInteger.valueOf(9), BigInteger.valueOf(10),
096: BigInteger.valueOf(11), BigInteger.valueOf(12) };
097:
098: for (int i = 0; i < expected.length; i++) {
099: assertEquals(message[i] + " to BigInteger", expected[i],
100: converter.convert(BigInteger.class, input[i]));
101: assertEquals(message[i] + " to null type", expected[i],
102: converter.convert(null, input[i]));
103: }
104: }
105:
106: }
|