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 junit.framework.TestSuite;
021:
022: import org.apache.commons.beanutils.Converter;
023:
024: /**
025: * Test Case for the LongConverter class.
026: *
027: * @author Rodney Waldhoff
028: * @version $Revision: 471348 $ $Date: 2006-11-05 02:59:26 +0000 (Sun, 05 Nov 2006) $
029: */
030:
031: public class LongConverterTestCase extends NumberConverterTestBase {
032:
033: private Converter converter = null;
034:
035: // ------------------------------------------------------------------------
036:
037: public LongConverterTestCase(String name) {
038: super (name);
039: }
040:
041: // ------------------------------------------------------------------------
042:
043: public void setUp() throws Exception {
044: converter = makeConverter();
045: numbers[0] = new Long("-12");
046: numbers[1] = new Long("13");
047: numbers[2] = new Long("-22");
048: numbers[3] = new Long("23");
049: }
050:
051: public static TestSuite suite() {
052: return new TestSuite(LongConverterTestCase.class);
053: }
054:
055: public void tearDown() throws Exception {
056: converter = null;
057: }
058:
059: // ------------------------------------------------------------------------
060:
061: protected NumberConverter makeConverter() {
062: return new LongConverter();
063: }
064:
065: protected NumberConverter makeConverter(Object defaultValue) {
066: return new LongConverter(defaultValue);
067: }
068:
069: protected Class getExpectedType() {
070: return Long.class;
071: }
072:
073: // ------------------------------------------------------------------------
074:
075: public void testSimpleConversion() throws Exception {
076: String[] message = { "from String", "from String",
077: "from String", "from String", "from String",
078: "from String", "from String", "from Byte",
079: "from Short", "from Integer", "from Long",
080: "from Float", "from Double" };
081:
082: Object[] input = { String.valueOf(Long.MIN_VALUE), "-17", "-1",
083: "0", "1", "17", String.valueOf(Long.MAX_VALUE),
084: new Byte((byte) 7), new Short((short) 8),
085: new Integer(9), new Long(10), new Float(11.1),
086: new Double(12.2) };
087:
088: Long[] expected = { new Long(Long.MIN_VALUE), new Long(-17),
089: new Long(-1), new Long(0), new Long(1), new Long(17),
090: new Long(Long.MAX_VALUE), new Long(7), new Long(8),
091: new Long(9), new Long(10), new Long(11), new Long(12) };
092:
093: for (int i = 0; i < expected.length; i++) {
094: assertEquals(message[i] + " to Long", expected[i],
095: converter.convert(Long.class, input[i]));
096: assertEquals(message[i] + " to long", expected[i],
097: converter.convert(Long.TYPE, input[i]));
098: assertEquals(message[i] + " to null type", expected[i],
099: converter.convert(null, input[i]));
100: }
101: }
102:
103: }
|