1 9 package org.jboss.portal.setup.util; 10 11 import junit.framework.TestCase; 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.framework.Assert; 15 16 import java.net.URL ; 17 18 19 public class TestPropertyConverter extends TestCase 20 { 21 22 23 public static void main(String args[]) 24 { 25 junit.textui.TestRunner.run(TestPropertyConverter.class); 26 } 27 28 public TestPropertyConverter(String name) 29 { 30 super(name); 31 } 32 33 public static Test suite() 34 { 35 return new TestSuite(TestPropertyConverter.class); 36 } 37 38 39 public void testChar() 40 { 41 Character etalon = new Character (Character.MIN_VALUE); 42 StringBuffer lBuffer = new StringBuffer (); 43 lBuffer.append(Character.MIN_VALUE); 44 String strValue = null; 45 Object value = null; 46 Object value1 = null; 47 strValue = PropertyConverter.convertToString(etalon); 48 Assert.assertEquals(strValue, new String (lBuffer)); 49 value = PropertyConverter.convertToValue(strValue, Character .class); 50 Assert.assertEquals(etalon, value); 51 value1 = PropertyConverter.convertToValue(strValue, char.class); 52 Assert.assertEquals(etalon, value1); 53 } 54 55 56 public void testFloat() 57 { 58 Float etalon = new Float (Float.MAX_VALUE); 59 String strValue = null; 60 Object value, value1 = null; 61 StringBuffer lBuffer = new StringBuffer (); 62 lBuffer.append(Float.MAX_VALUE); 63 strValue = PropertyConverter.convertToString(etalon); 64 Assert.assertEquals(strValue, new String (lBuffer)); 65 value = PropertyConverter.convertToValue(strValue, Float .class); 66 Assert.assertEquals(etalon, value); 67 value1 = PropertyConverter.convertToValue(strValue, float.class); 68 Assert.assertEquals(etalon, value1); 69 } 70 71 public void testLong() 72 { 73 Long etalon = new Long (Long.MAX_VALUE); 74 String strValue = null; 75 Object value, value1 = null; 76 strValue = PropertyConverter.convertToString(etalon); 77 StringBuffer lBuffer = new StringBuffer (); 78 lBuffer.append(Long.MAX_VALUE); 79 Assert.assertEquals(strValue, new String (lBuffer)); 80 value = PropertyConverter.convertToValue(strValue, Long .class); 81 Assert.assertEquals(etalon, value); 82 value1 = PropertyConverter.convertToValue(strValue, long.class); 83 Assert.assertEquals(etalon, value1); 84 } 85 86 public void testShort() 87 { 88 Short etalon = new Short (Short.MAX_VALUE); 89 String strValue = null; 90 Object value, value1 = null; 91 StringBuffer lBuffer = new StringBuffer (); 92 lBuffer.append(Short.MAX_VALUE); 93 strValue = PropertyConverter.convertToString(etalon); 94 Assert.assertEquals(strValue, new String (lBuffer)); 95 value = PropertyConverter.convertToValue(strValue, Short .class); 96 Assert.assertEquals(etalon, value); 97 value1 = PropertyConverter.convertToValue(strValue, short.class); 98 Assert.assertEquals(etalon, value1); 99 } 100 101 public void testByte() 102 { 103 Byte etalon = new Byte (Byte.MAX_VALUE); 104 String strValue = null; 105 Object value, value1 = null; 106 StringBuffer lBuffer = new StringBuffer (); 107 lBuffer.append(Byte.MAX_VALUE); 108 strValue = PropertyConverter.convertToString(etalon); 109 Assert.assertEquals(strValue, new String (lBuffer)); 110 value = PropertyConverter.convertToValue(strValue, Byte .class); 111 Assert.assertEquals(etalon, value); 112 value1 = PropertyConverter.convertToValue(strValue, byte.class); 113 Assert.assertEquals(etalon, value1); 114 } 115 116 public void testDouble() 117 { 118 Double etalon = new Double (Double.MAX_VALUE); 119 String strValue = null; 120 Object value, value1 = null; 121 StringBuffer lBuffer = new StringBuffer (); 122 lBuffer.append(Double.MAX_VALUE); 123 strValue = PropertyConverter.convertToString(etalon); 124 Assert.assertEquals(strValue, new String (lBuffer)); 125 value = PropertyConverter.convertToValue(strValue, Double .class); 126 Assert.assertEquals(etalon, value); 127 value1 = PropertyConverter.convertToValue(strValue, double.class); 128 Assert.assertEquals(etalon, value1); 129 } 130 131 public void testInteger() 132 { 133 Integer etalon = new Integer (Integer.MAX_VALUE); 134 String strValue = null; 135 Object value, value1 = null; 136 StringBuffer lBuffer = new StringBuffer (); 137 lBuffer.append(Integer.MAX_VALUE); 138 strValue = PropertyConverter.convertToString(etalon); 139 Assert.assertEquals(strValue, new String (lBuffer)); 140 value = PropertyConverter.convertToValue(strValue, Integer .class); 141 Assert.assertEquals(etalon, value); 142 value1 = PropertyConverter.convertToValue(strValue, int.class); 143 Assert.assertEquals(etalon, value1); 144 } 145 146 public void testBoolean() 147 { 148 Boolean etalon = Boolean.FALSE; 149 String strValue = null; 150 Object value, value1 = null; 151 StringBuffer lBuffer = new StringBuffer (); 152 lBuffer.append(Boolean.FALSE); 153 strValue = PropertyConverter.convertToString(Boolean.FALSE); 154 Assert.assertTrue(strValue.equalsIgnoreCase(new String (lBuffer))); 155 value = PropertyConverter.convertToValue(strValue, Boolean .class); 156 Assert.assertEquals(etalon, value); 157 value1 = PropertyConverter.convertToValue(strValue, boolean.class); 158 Assert.assertEquals(etalon, value1); 159 } 160 161 public void testString() 162 { 163 String initialValue = "my test, &*(^\""; 164 String strValue = null; 165 Object value = null; 166 strValue = PropertyConverter.convertToString(initialValue); 167 Assert.assertEquals(strValue, initialValue); 168 value = PropertyConverter.convertToValue(strValue, String .class); 169 Assert.assertEquals(initialValue, value); 170 171 } 172 173 public void testURL() 174 { 175 String initialValue = "http://localhost:80/index.jsp"; 176 String strValue = null; 177 Object value = null; 178 value = PropertyConverter.convertToValue(initialValue, URL .class); 179 strValue = PropertyConverter.convertToString(value); 180 Assert.assertEquals(strValue, initialValue); 181 } 182 183 } 184 | Popular Tags |