Fixed logic in bean transformer tests to match API.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141097 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
11da77c693
commit
9267ae3bb2
|
@ -55,10 +55,11 @@ package org.apache.commons.math.util;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import org.apache.commons.math.MathException;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
|
||||
/**
|
||||
* Uses PropertyUtils to map a Bean getter to a double value.
|
||||
* @version $Revision: 1.2 $ $Date: 2004/01/29 00:48:59 $
|
||||
* @version $Revision: 1.3 $ $Date: 2004/02/16 07:04:03 $
|
||||
*/
|
||||
public class BeanTransformer implements NumberTransformer {
|
||||
|
||||
|
@ -104,7 +105,7 @@ public class BeanTransformer implements NumberTransformer {
|
|||
*/
|
||||
public double transform(final Object o) throws MathException {
|
||||
try {
|
||||
return ((Number) org.apache.commons.beanutils.PropertyUtils.getProperty(o, getPropertyName())).doubleValue();
|
||||
return ((Number) PropertyUtils.getProperty(o, getPropertyName())).doubleValue();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new MathException("IllegalAccessException in Transformation: " + e.getMessage(), e);
|
||||
} catch (InvocationTargetException e) {
|
||||
|
|
|
@ -60,7 +60,7 @@ import org.apache.commons.math.TestUtils;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.7 $ $Date: 2004/01/29 00:48:59 $
|
||||
* @version $Revision: 1.8 $ $Date: 2004/02/16 07:04:04 $
|
||||
*/
|
||||
public class BeanTransformerTest extends TestCase {
|
||||
|
||||
|
@ -97,14 +97,12 @@ public class BeanTransformerTest extends TestCase {
|
|||
public void testTransformNoSuchMethod(){
|
||||
BeanTransformer b = new BeanTransformer("z");
|
||||
TestBean target = new TestBean();
|
||||
double value = Double.NaN;
|
||||
try {
|
||||
value = b.transform(target);
|
||||
b.transform(target);
|
||||
fail("Expecting MathException");
|
||||
} catch (MathException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
// expected
|
||||
}
|
||||
TestUtils.assertEquals(Double.NaN, value, 1.0e-2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,22 +121,6 @@ public class BeanTransformerTest extends TestCase {
|
|||
TestUtils.assertEquals(1.0, value, 1.0e-2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testTransformInvocationError(){
|
||||
BeanTransformer b = new BeanTransformer("z");
|
||||
TestBean target = new TestBean();
|
||||
double value = Double.NaN;
|
||||
try {
|
||||
value = b.transform(target);
|
||||
} catch (MathException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
TestUtils.assertEquals(Double.NaN, value, 1.0e-2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -152,7 +134,7 @@ public class BeanTransformerTest extends TestCase {
|
|||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
fail();
|
||||
fail("Expecting ClassCastException");
|
||||
} catch(ClassCastException ex){
|
||||
// success
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ import org.apache.commons.math.TestUtils;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.7 $ $Date: 2004/01/29 00:48:59 $
|
||||
* @version $Revision: 1.8 $ $Date: 2004/02/16 07:04:04 $
|
||||
*/
|
||||
public class DefaultTransformerTest extends TestCase {
|
||||
/**
|
||||
|
@ -84,13 +84,12 @@ public class DefaultTransformerTest extends TestCase {
|
|||
*
|
||||
*/
|
||||
public void testTransformNull(){
|
||||
double expected = Double.NaN;
|
||||
DefaultTransformer t = new DefaultTransformer();
|
||||
try {
|
||||
TestUtils.assertEquals(expected, t.transform(null), 1.0e-4);
|
||||
t.transform(null);
|
||||
fail("Expection MathException");
|
||||
} catch (MathException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,14 +142,13 @@ public class DefaultTransformerTest extends TestCase {
|
|||
*
|
||||
*/
|
||||
public void testTransformObject(){
|
||||
double expected = Double.NaN;
|
||||
Boolean input = Boolean.TRUE;
|
||||
DefaultTransformer t = new DefaultTransformer();
|
||||
try {
|
||||
TestUtils.assertEquals(expected, t.transform(input), 1.0e-4);
|
||||
t.transform(input);
|
||||
fail("Expecting MathException");
|
||||
} catch (MathException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue