1 16 17 package org.apache.commons.beanutils.converters; 18 19 import junit.framework.TestSuite; 20 21 import org.apache.commons.beanutils.Converter; 22 23 24 30 31 public class ShortConverterTestCase extends NumberConverterTestBase { 32 33 private Converter converter = null; 34 35 37 public ShortConverterTestCase(String name) { 38 super(name); 39 } 40 41 43 public void setUp() throws Exception { 44 converter = makeConverter(); 45 } 46 47 public static TestSuite suite() { 48 return new TestSuite(ShortConverterTestCase.class); 49 } 50 51 public void tearDown() throws Exception { 52 converter = null; 53 } 54 55 57 protected Converter makeConverter() { 58 return new ShortConverter(); 59 } 60 61 protected Class getExpectedType() { 62 return Short .class; 63 } 64 65 67 public void testSimpleConversion() throws Exception { 68 String [] message= { 69 "from String", 70 "from String", 71 "from String", 72 "from String", 73 "from String", 74 "from String", 75 "from String", 76 "from Byte", 77 "from Short", 78 "from Integer", 79 "from Long", 80 "from Float", 81 "from Double" 82 }; 83 84 Object [] input = { 85 String.valueOf(Short.MIN_VALUE), 86 "-17", 87 "-1", 88 "0", 89 "1", 90 "17", 91 String.valueOf(Short.MAX_VALUE), 92 new Byte ((byte)7), 93 new Short ((short)8), 94 new Integer (9), 95 new Long (10), 96 new Float (11.1), 97 new Double (12.2) 98 }; 99 100 Short [] expected = { 101 new Short (Short.MIN_VALUE), 102 new Short ((short)-17), 103 new Short ((short)-1), 104 new Short ((short)0), 105 new Short ((short)1), 106 new Short ((short)17), 107 new Short (Short.MAX_VALUE), 108 new Short ((short)7), 109 new Short ((short)8), 110 new Short ((short)9), 111 new Short ((short)10), 112 new Short ((short)11), 113 new Short ((short)12) 114 }; 115 116 for(int i=0;i<expected.length;i++) { 117 assertEquals(message[i] + " to Short",expected[i],converter.convert(Short .class,input[i])); 118 assertEquals(message[i] + " to short",expected[i],converter.convert(Short.TYPE,input[i])); 119 assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i])); 120 } 121 } 122 123 } 124 125 | Popular Tags |