1 16 17 package org.apache.commons.math.util; 18 19 import org.apache.commons.math.MathException; 20 import org.apache.commons.math.TestUtils; 21 22 import junit.framework.TestCase; 23 24 27 public class BeanTransformerTest extends TestCase { 28 29 32 public void testConstructor(){ 33 BeanTransformer b = new BeanTransformer(); 34 assertNull(b.getPropertyName()); 35 } 36 37 40 public void testConstructorString(){ 41 String name = "property"; 42 BeanTransformer b = new BeanTransformer(name); 43 assertEquals(name, b.getPropertyName()); 44 } 45 46 49 public void testSetPropertyName(){ 50 String name = "property"; 51 BeanTransformer b = new BeanTransformer(); 52 b.setPropertyName(name); 53 assertEquals(name, b.getPropertyName()); 54 } 55 56 59 public void testTransformNoSuchMethod(){ 60 BeanTransformer b = new BeanTransformer("z"); 61 TestBean target = new TestBean(); 62 try { 63 b.transform(target); 64 fail("Expecting MathException"); 65 } catch (MathException e) { 66 } 68 } 69 70 73 public void testTransform() throws Exception { 74 BeanTransformer b = new BeanTransformer("x"); 75 TestBean target = new TestBean(); 76 double value = Double.NaN; 77 value = b.transform(target); 78 TestUtils.assertEquals(1.0, value, 1.0e-2); 79 } 80 81 83 public void testTransformInvalidType() throws Exception { 84 BeanTransformer b = new BeanTransformer("y"); 85 TestBean target = new TestBean(); 86 try { 87 b.transform(target); 88 fail("Expecting ClassCastException"); 89 } catch(ClassCastException ex){ 90 } 92 } 93 } 94 | Popular Tags |