From d085445d68242797f547fe99156bb2278dc04e4d Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 13 Jan 2008 20:02:59 +0000 Subject: [PATCH] be more restrictive on ignored exceptions for the test added a long to double conversion to also test the getN() methods git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@611628 13f79535-47bb-0310-9956-ffa450edef68 --- .../stat/data/CertifiedDataAbstractTest.java | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java b/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java index cc6722d32..50b1521bb 100644 --- a/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java +++ b/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java @@ -20,6 +20,7 @@ package org.apache.commons.math.stat.data; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.util.HashMap; @@ -113,30 +114,48 @@ public abstract class CertifiedDataAbstractTest extends TestCase { public void testCertifiedValues() { Iterator iter = certifiedValues.keySet().iterator(); + while (iter.hasNext()) { String name = iter.next().toString(); Double expectedValue = (Double)certifiedValues.get(name); - try { - Double summariesValue = (Double)this.getProperty(summaries, name); + + Double summariesValue = getProperty(summaries, name); + if (summariesValue != null) { TestUtils.assertEquals("summary value for " + name + " is incorrect.", - summariesValue.doubleValue(), expectedValue.doubleValue(), getMaximumAbsoluteError()); - } catch (Exception ex) { + summariesValue.doubleValue(), expectedValue.doubleValue(), + getMaximumAbsoluteError()); } - - try { - Double descriptivesValue = (Double)this.getProperty(descriptives, name); + + Double descriptivesValue = getProperty(descriptives, name); + if (descriptivesValue != null) { TestUtils.assertEquals("descriptive value for " + name + " is incorrect.", - descriptivesValue.doubleValue(), expectedValue.doubleValue(), getMaximumAbsoluteError()); - } catch (Exception ex) { + descriptivesValue.doubleValue(), expectedValue.doubleValue(), + getMaximumAbsoluteError()); } } } - protected Object getProperty(Object bean, String name) throws Exception{ - // Get the value of prop - String prop = "get" + name.substring(0,1).toUpperCase() + name.substring(1); - Method meth = bean.getClass().getMethod(prop, new Class[0]); - return meth.invoke(bean, new Object[0]); + protected Double getProperty(Object bean, String name) { + try { + // Get the value of prop + String prop = "get" + name.substring(0,1).toUpperCase() + name.substring(1); + Method meth = bean.getClass().getMethod(prop, new Class[0]); + Object property = meth.invoke(bean, new Object[0]); + if (meth.getReturnType().equals(Double.TYPE)) { + return (Double) property; + } else if (meth.getReturnType().equals(Long.TYPE)) { + return new Double(((Long) property).doubleValue()); + } else { + fail("wrong type: " + meth.getReturnType().getName()); + } + } catch (NoSuchMethodException nsme) { + // ignored + } catch (InvocationTargetException ite) { + fail(ite.getMessage()); + } catch (IllegalAccessException iae) { + fail(iae.getMessage()); + } + return null; } }