You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Christopher Lenz <cm...@gmx.de> on 2002/09/04 11:08:15 UTC

[digester] unit tests swallowing exceptions

Hi all,

While experimenting with my proposed refactorings, I've of course been 
running the unit tests again and again ;o), and I've found something 
that disturbed me quite a lot.

For example, in RuleTestCase.java, we have the test method:

     public void testObjectCreate1() {

         // Configure the digester as required
         digester.addObjectCreate("employee",
                 "org.apache.commons.digester.Employee");
         digester.addSetProperties("employee");

         // Parse our test input.
         Object root = null;
         try {
             root = digester.parse(getInputStream("Test1.xml"));
         } catch (Throwable t) {
             fail("Digester threw IOException: " + t);
         }
         assertNotNull("Digester returned an object", root);
         assertTrue("Digester returned an Employee",
                 root instanceof Employee);
         Employee employee = (Employee) root;
         assertEquals("First name is correct",
                 "First Name",
                 employee.getFirstName());
         assertEquals("Last name is correct",
                 "Last Name",
                 employee.getLastName());
     }

Obviously, this method swallows all exceptions thrown during the parse 
process, (incorrectly) stating that Digester has thrown an IOException, 
and the only somewhat useful output is the implicit Throwable.toString().

For unexpected exceptions, I usually just add a "throws Exception" to 
the test method signature, so that it eventually gets through to the 
JUnit framework as error. And then, the full stacktrace is available 
when trying to look into the cause of the exception.

Now, the question is, would anyone oppose me changing such test-cases as 
the above so that they no longer swallow the exceptions, but rather pass 
them on?

-- 
Christopher Lenz
/=/ cmlenz at gmx.de


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [digester] unit tests swallowing exceptions

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
committed. thanks.

the second patch was a bit mangled and wouldn't apply correctly but i 
think that i've gone through and got just about everything. let me know if 
i've missed anything.

- robert

On Wednesday, September 4, 2002, at 10:26 AM, Christopher Lenz wrote:

> Christopher Lenz wrote:
>> Now, the question is, would anyone oppose me changing such test-cases as 
>> the above so that they no longer swallow the exceptions, but rather pass 
>> them on?
>
> And here is a patch that does that, also including some line-wrapping 
> fixes where lines were longer than 80 chars.
>
> -- Christopher Lenz
> /=/ cmlenz at gmx.de
> Index: BeanPropertySetterRuleTestCase.java
> ===================================================================
> RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/
> digester/BeanPropertySetterRuleTestCase.java,v
> retrieving revision 1.6
> diff -u -r1.6 BeanPropertySetterRuleTestCase.java
> --- BeanPropertySetterRuleTestCase.java	17 Jul 2002 16:53:50 -0000	1.6
> +++ BeanPropertySetterRuleTestCase.java	4 Sep 2002 09:22:20 -0000
> @@ -66,6 +66,8 @@
>  import java.util.ArrayList;
>  import java.util.List;
>
> +import org.xml.sax.SAXException;
> +
>  import junit.framework.Test;
>  import junit.framework.TestCase;
>  import junit.framework.TestSuite;
> @@ -85,7 +87,8 @@
>       * Simple test xml document used in the tests.
>       */
>      protected final static String TEST_XML =
> -            "<?xml version='1.0'?><root>ROOT BODY<alpha>ALPHA 
> BODY</alpha><beta>BETA BODY</beta><gamma>GAMMA BODY</gamma></root>";
> +        "<?xml version='1.0'?><root>ROOT BODY<alpha>ALPHA BODY</alpha>" 
> +
> +        "<beta>BETA BODY</beta><gamma>GAMMA BODY</gamma></root>";
>
>
>      /**
> @@ -150,7 +153,7 @@
>       * This is a general digester test but it fits into here pretty well.
>       * This tests that the rule calling order is properly enforced.
>       */
> -    public void testDigesterRuleCallOrder() {
> +    public void testDigesterRuleCallOrder() throws SAXException, 
> IOException {
>
>          List callOrder = new ArrayList();
>
> @@ -173,12 +176,7 @@
>          digester.addRule("root/alpha", thirdRule);
>
>
> -        try {
> -            digester.parse(xmlTestReader());
> -
> -        } catch (Throwable t) {
> -            fail("Exception prevented test execution: " + t);
> -        }
> +        digester.parse(xmlTestReader());
>
>          // we should have nine entries in our list of calls
>
> @@ -243,7 +241,7 @@
>       * This is a general digester test but it fits into here pretty well.
>       * This tests that the body text stack is functioning correctly.
>       */
> -    public void testDigesterBodyTextStack() {
> +    public void testDigesterBodyTextStack() throws SAXException, 
> IOException {
>
>          // use the standard rules
>          digester.setRules(new RulesBase());
> @@ -264,12 +262,7 @@
>          TestRule gammaRule = new TestRule("root/gamma");
>          digester.addRule("root/gamma", gammaRule);
>
> -        try {
> -            digester.parse(xmlTestReader());
> -
> -        } catch (Throwable t) {
> -            fail("Exception prevented test execution: " + t);
> -        }
> +        digester.parse(xmlTestReader());
>
>          assertEquals(
>                  "Root body text not set correct.",
> @@ -297,13 +290,14 @@
>      /**
>       * Test that you can successfully set a given property
>       */
> -    public void testSetGivenProperty() {
> +    public void testSetGivenProperty() throws SAXException, IOException 
> {
>
>          // use the standard rules
>          digester.setRules(new RulesBase());
>
>          // going to be setting properties on a SimpleTestBean
> -        digester.addObjectCreate("root", 
> "org.apache.commons.digester.SimpleTestBean");
> +        digester.addObjectCreate("root",
> +                                 
> "org.apache.commons.digester.SimpleTestBean");
>
>          // we'll set property alpha with the body text of root
>          digester.addRule("root", new BeanPropertySetterRule("alpha"));
> @@ -313,16 +307,7 @@
>
>          // we'll leave property gamma alone
>
> -
> -        SimpleTestBean bean = null;
> -        try {
> -            bean = (SimpleTestBean) digester.parse(xmlTestReader());
> -
> -        } catch (Throwable t) {
> -            fail("Exception prevented test execution: " + t);
> -        }
> -
> -
> +        SimpleTestBean bean = (SimpleTestBean) 
> digester.parse(xmlTestReader());
>
>          // check properties are set correctly
>          assertEquals(
> @@ -344,25 +329,20 @@
>      /**
>       * Test that you can successfully automatically set properties.
>       */
> -    public void testAutomaticallySetProperties() {
> +    public void testAutomaticallySetProperties()
> +        throws SAXException, IOException {
>
>          // need the extended rules
>          digester.setRules(new ExtendedBaseRules());
>
>          // going to be setting properties on a SimpleTestBean
> -        digester.addObjectCreate("root", 
> "org.apache.commons.digester.SimpleTestBean");
> +        digester.addObjectCreate("root",
> +                                 
> "org.apache.commons.digester.SimpleTestBean");
>
>          // match all children of root with this rule
>          digester.addRule("root/?", new BeanPropertySetterRule());
>
> -        SimpleTestBean bean = null;
> -        try {
> -            bean = (SimpleTestBean) digester.parse(xmlTestReader());
> -
> -        } catch (Throwable t) {
> -            fail("Exception prevented test execution: " + t);
> -        }
> -
> +        SimpleTestBean bean = (SimpleTestBean) 
> digester.parse(xmlTestReader());
>
>          // check properties are set correctly
>          assertEquals(
> Index: RuleTestCase.java
> ===================================================================
> RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/
> digester/RuleTestCase.java,v
> retrieving revision 1.19
> diff -u -r1.19 RuleTestCase.java
> --- RuleTestCase.java	31 Jul 2002 10:48:08 -0000	1.19
> +++ RuleTestCase.java	4 Sep 2002 09:22:19 -0000
> @@ -69,6 +69,8 @@
>  import java.util.ArrayList;
>  import java.util.Hashtable;
>
> +import org.xml.sax.SAXException;
> +
>  import junit.framework.Test;
>  import junit.framework.TestCase;
>  import junit.framework.TestSuite;
> @@ -152,7 +154,7 @@
>       * the stack, which should cause an appropriate Employee object to be
>       * returned.
>       */
> -    public void testObjectCreate1() {
> +    public void testObjectCreate1() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee",
> @@ -160,12 +162,8 @@
>          digester.addSetProperties("employee");
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test1.xml"));
> +
>          assertNotNull("Digester returned an object", root);
>          assertTrue("Digester returned an Employee",
>                  root instanceof Employee);
> @@ -187,7 +185,7 @@
>       * returned.  The processing rules will process the nested Address 
> elements
>       * as well, but will not attempt to add them to the Employee.
>       */
> -    public void testObjectCreate2() {
> +    public void testObjectCreate2() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> @@ -197,12 +195,8 @@
>          digester.addSetProperties("employee/address");
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test1.xml"));
> +
>          assertNotNull("Digester returned an object", root);
>          assertTrue("Digester returned an Employee",
>                  root instanceof Employee);
> @@ -224,7 +218,7 @@
>       * returned.  The processing rules will process the nested Address 
> elements
>       * as well, and will add them to the owning Employee.
>       */
> -    public void testObjectCreate3() {
> +    public void testObjectCreate3() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> @@ -236,20 +230,11 @@
>                  "addAddress");
>
>          // Parse our test input once
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test1.xml"));
>          validateObjectCreate3(root);
>
>          // Parse the same input again
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        root = digester.parse(getInputStream("Test1.xml"));
>          validateObjectCreate3(root);
>
>      }
> @@ -259,7 +244,7 @@
>       * Same as testObjectCreate1(), except use individual call method 
> rules
>       * to set the properties of the Employee.
>       */
> -    public void testObjectCreate4() {
> +    public void testObjectCreate4() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> @@ -272,12 +257,8 @@
>
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test1.xml"));
> +
>          assertNotNull("Digester returned an object", root);
>          assertTrue("Digester returned an Employee",
>                  root instanceof Employee);
> @@ -299,7 +280,7 @@
>       * a paramCount=0 (ie the body of the element is the argument of the
>       * method).
>       */
> -    public void testObjectCreate5() {
> +    public void testObjectCreate5() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> @@ -308,12 +289,8 @@
>
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test5.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test5.xml"));
> +
>          assertNotNull("Digester returned an object", root);
>          assertTrue("Digester returned an Employee",
>                  root instanceof Employee);
> @@ -332,7 +309,7 @@
>       * It should be possible to parse the same input twice, and get trees
>       * of objects that are isomorphic but not be identical object 
> instances.
>       */
> -    public void testRepeatedParse() {
> +    public void testRepeatedParse() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> @@ -344,21 +321,11 @@
>                  "addAddress");
>
>          // Parse our test input the first time
> -        Object root1 = null;
> -        try {
> -            root1 = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester #1 threw Exception:  " + t);
> -        }
> +        Object root1 = digester.parse(getInputStream("Test1.xml"));
>          validateObjectCreate3(root1);
>
>          // Parse our test input the second time
> -        Object root2 = null;
> -        try {
> -            root2 = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester #2 threw Exception:  " + t);
> -        }
> +        Object root2 = digester.parse(getInputStream("Test1.xml"));
>          validateObjectCreate3(root2);
>
>          // Make sure that it was a different root
> @@ -374,19 +341,14 @@
>       * returned.  The processing rules will process the nested Address 
> elements
>       * as well, but will not attempt to add them to the Employee.
>       */
> -    public void testRuleSet1() {
> +    public void testRuleSet1() throws SAXException, IOException {
>
>          // Configure the digester as required
>          RuleSet rs = new TestRuleSet();
>          digester.addRuleSet(rs);
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test1.xml"));
>
>          assertNotNull("Digester returned an object", root);
>          assertTrue("Digester returned an Employee",
> @@ -409,7 +371,7 @@
>      /**
>       * Same as <code>testRuleSet1</code> except using a single namespace.
>       */
> -    public void testRuleSet2() {
> +    public void testRuleSet2() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.setNamespaceAware(true);
> @@ -418,12 +380,7 @@
>          digester.addRuleSet(rs);
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test2.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test2.xml"));
>
>          assertNotNull("Digester returned an object", root);
>          assertTrue("Digester returned an Employee",
> @@ -448,7 +405,7 @@
>       * for employee that we should recognize, and a namespace for
>       * address that we should skip.
>       */
> -    public void testRuleSet3() {
> +    public void testRuleSet3() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.setNamespaceAware(true);
> @@ -457,12 +414,7 @@
>          digester.addRuleSet(rs);
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test3.xml"));
> -        } catch (Throwable t) {
> -            fail("Digester threw IOException: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test3.xml"));
>
>          assertNotNull("Digester returned an object", root);
>          assertTrue("Digester returned an Employee",
> @@ -492,7 +444,7 @@
>       * with the top-1 (parent) object as an argument.  The three argument
>       * form is tested in <code>testSetTopRule2</code>.
>       */
> -    public void testSetTopRule1() {
> +    public void testSetTopRule1() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee",
> @@ -504,12 +456,7 @@
>          digester.addSetTop("employee/address", "setEmployee");
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Exception t) {
> -            fail("Digester threw Exception: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test1.xml"));
>          validateObjectCreate3(root);
>
>      }
> @@ -519,7 +466,7 @@
>       * Same as <code>testSetTopRule1</code> except using the three 
> argument
>       * form of the SetTopRule rule.
>       */
> -    public void testSetTopRule2() {
> +    public void testSetTopRule2() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee",
> @@ -532,12 +479,7 @@
>                  "org.apache.commons.digester.Employee");
>
>          // Parse our test input.
> -        Object root = null;
> -        try {
> -            root = digester.parse(getInputStream("Test1.xml"));
> -        } catch (Exception t) {
> -            fail("Digester threw Exception: " + t);
> -        }
> +        Object root = digester.parse(getInputStream("Test1.xml"));
>          validateObjectCreate3(root);
>
>      }
> @@ -551,12 +493,13 @@
>          TestRule rule =  new TestRule("Test");
>          digester.addRule("/root", rule);
>
> -        assertEquals("Digester is not properly on rule addition.", 
> digester, rule.getDigester());
> +        assertEquals("Digester is not properly on rule addition.", 
> digester,
> +                     rule.getDigester());
>
>      }
>
>
> -    public void testSetNext() throws Exception {
> +    public void testSetNext() throws SAXException, IOException {
>          Digester digester = new Digester();
>          digester.setRules(new ExtendedBaseRules());
>          digester.setValidating(false);
> @@ -569,7 +512,8 @@
>          digester.addSetNext("!*/b/?", "setChild");
>          digester.addSetNext("!*/a/?", "setChild");
>          digester.addSetNext("!root/?", "add");
> -        ArrayList root = (ArrayList) 
> digester.parse(getInputStream("Test4.xml"));
> +        ArrayList root =
> +            (ArrayList) digester.parse(getInputStream("Test4.xml"));
>
>          assertEquals("Wrong array size", 2, root.size());
>          AlphaBean one = (AlphaBean) root.get(0);
> @@ -588,7 +532,7 @@
>      }
>
>
> -    public void testSetTop() throws Exception {
> +    public void testSetTop() throws SAXException, IOException {
>          Digester digester = new Digester();
>          digester.setRules(new ExtendedBaseRules());
>          digester.setValidating(false);
> @@ -602,7 +546,9 @@
>          digester.addSetTop("!*/a/?", "setParent");
>          digester.addSetRoot("!*/a", "add");
>          digester.addSetRoot("!*/b", "add");
> -        ArrayList root = (ArrayList) 
> digester.parse(getInputStream("Test4.xml"));
> +
> +        ArrayList root =
> +            (ArrayList) digester.parse(getInputStream("Test4.xml"));
>
>          assertEquals("Wrong array size", 5, root.size());
>
> @@ -637,7 +583,7 @@
>       * to call any accessible method of the object on the top of the 
> stack,
>       * even methods with no arguments.
>       */
> -    public void testCallMethod() throws Exception {
> +    public void testCallMethod() throws SAXException, IOException {
>
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> @@ -648,16 +594,8 @@
>          digester.addCallMethod("employee", "toString", 0, new String[] {
> });
>          digester.addCallMethod("employee", "toString");
>
> -        // Parse our test input
> -        Object root1 = null;
> -        try {
> -            // an exception will be thrown if the method can't be found
> -            root1 = digester.parse(getInputStream("Test5.xml"));
> -
> -        } catch (Throwable t) {
> -            // this means that the method can't be found and so the test 
> fails
> -            fail("Digester threw Exception:  " + t);
> -        }
> +        // an exception will be thrown if the method can't be found
> +        Object root1 = digester.parse(getInputStream("Test5.xml"));
>
>      }
>
> @@ -666,7 +604,7 @@
>       * to call any accessible method of the object on the top of the 
> stack,
>       * even methods with no arguments.
>       */
> -    public void testCallMethod2() throws Exception {
> +    public void testCallMethod2() throws SAXException, IOException {
>
>          //I was preparing this test case to fix another bug
>          //    i'll uncomment it once i've fixed it
> @@ -674,85 +612,64 @@
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
>          // try all syntax permutations
> -        digester.addCallMethod("employee", "setLastName", 1, new String[
> ] {"java.lang.String"});
> +        digester.addCallMethod("employee", "setLastName", 1,
> +                               new String[] {"java.lang.String"});
>          digester.addCallParam("employee/lastName", 0);
>
>          // Parse our test input
> -        Object root1 = null;
> -        try {
> -            // an exception will be thrown if the method can't be found
> -            root1 = digester.parse(getInputStream("Test5.xml"));
> -            Employee employee = (Employee) root1;
> -            assertEquals("Failed to call Employee.setLastName", "Last 
> Name", employee.getLastName());
> +        // an exception will be thrown if the method can't be found
> +        Object root1 = digester.parse(getInputStream("Test5.xml"));
> +        Employee employee1 = (Employee) root1;
> +        assertEquals("Failed to call Employee.setLastName", "Last Name",
> +                     employee1.getLastName());
>
> -        } catch (Throwable t) {
> -            // this means that the method can't be found and so the test 
> fails
> -            fail("Digester threw Exception:  " + t);
> -        }
> -
> -
>          digester = new Digester();
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
>          // try out primitive convertion
> -        digester.addCallMethod("employee", "setAge", 1, new Class[] {int.
> class});
> +        digester.addCallMethod("employee", "setAge", 1,
> +                               new Class[] {int.class});
>          digester.addCallParam("employee/age", 0);
>
>          // Parse our test input
> -        root1 = null;
> -        try {
> -            // an exception will be thrown if the method can't be found
> -            root1 = digester.parse(getInputStream("Test5.xml"));
> -            Employee employee = (Employee) root1;
> -            assertEquals("Failed to call Employee.setAge", 21, employee.
> getAge());
> -
> -        } catch (Throwable t) {
> -            // this means that the method can't be found and so the test 
> fails
> -            fail("Digester threw Exception:  " + t);
> -        }
> +        // an exception will be thrown if the method can't be found
> +        root1 = digester.parse(getInputStream("Test5.xml"));
> +        Employee employee2 = (Employee) root1;
> +        assertEquals("Failed to call Employee.setAge", 21, 
> employee2.getAge());
>
>          digester = new Digester();
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> -        digester.addCallMethod("employee", "setActive", 1, new Class[] 
> {boolean.class});
> +        digester.addCallMethod("employee", "setActive", 1,
> +                               new Class[] {boolean.class});
>          digester.addCallParam("employee/active", 0);
>
>          // Parse our test input
> -        root1 = null;
> -        try {
> -            // an exception will be thrown if the method can't be found
> -            root1 = digester.parse(getInputStream("Test5.xml"));
> -            Employee employee = (Employee) root1;
> -            assertEquals("Failed to call Employee.setActive", true, 
> employee.isActive());
> -
> -        } catch (Throwable t) {
> -            // this means that the method can't be found and so the test 
> fails
> -            fail("Digester threw Exception:  " + t);
> -        }
> +        // an exception will be thrown if the method can't be found
> +        root1 = digester.parse(getInputStream("Test5.xml"));
> +        Employee employee3 = (Employee) root1;
> +        assertEquals("Failed to call Employee.setActive", true,
> +                     employee3.isActive());
>
>          digester = new Digester();
>          // Configure the digester as required
>          digester.addObjectCreate("employee", Employee.class);
> -        digester.addCallMethod("employee", "setSalary", 1, new Class[] 
> {float.class});
> +        digester.addCallMethod("employee", "setSalary", 1,
> +                               new Class[] {float.class});
>          digester.addCallParam("employee/salary", 0);
>
>          // Parse our test input
> -        root1 = null;
> -        try {
> -            // an exception will be thrown if the method can't be found
> -            root1 = digester.parse(getInputStream("Test5.xml"));
> -            Employee employee = (Employee) root1;
> -            assertEquals("Failed to call Employee.setSalary", 1000000.0f,
>  employee.getSalary(), 0.1f);
> -
> -        } catch (Throwable t) {
> -            // this means that the method can't be found and so the test 
> fails
> -            fail("Digester threw Exception:  " + t);
> -        }
> +        // an exception will be thrown if the method can't be found
> +        root1 = digester.parse(getInputStream("Test5.xml"));
> +        Employee employee4 = (Employee) root1;
> +
> +        assertEquals("Failed to call Employee.setSalary", 1000000.0f,
> +                     employee4.getSalary(), 0.1f);
>      }
>
>      /**
>       */
> -    public void testSetCustomProperties() throws Exception {
> +    public void testSetCustomProperties() throws SAXException, 
> IOException {
>
>          Digester digester = new Digester();
>
> @@ -778,8 +695,8 @@
>                      new String[] {"city"});
>          digester.addSetProperties("toplevel/four", "alt-city", "city");
>
> -
> -        ArrayList root = (ArrayList) 
> digester.parse(getInputStream("Test7.xml"));
> +        ArrayList root =
> +            (ArrayList) digester.parse(getInputStream("Test7.xml"));
>
>          assertEquals("Wrong array size", 4, root.size());
>
> @@ -789,28 +706,32 @@
>          obj = root.get(0);
>          assertTrue("(1) Should be an Address ", obj instanceof Address);
>          Address addressOne = (Address) obj;
> -        assertEquals("(1) Street attribute", "New Street", 
> addressOne.getStreet());
> +        assertEquals("(1) Street attribute", "New Street",
> +                     addressOne.getStreet());
>          assertEquals("(1) City attribute", "Las Vegas", 
> addressOne.getCity());
>          assertEquals("(1) State attribute", "Nevada", 
> addressOne.getState());
>
>          obj = root.get(1);
>          assertTrue("(2) Should be an Address ", obj instanceof Address);
>          Address addressTwo = (Address) obj;
> -        assertEquals("(2) Street attribute", "Old Street", 
> addressTwo.getStreet());
> +        assertEquals("(2) Street attribute", "Old Street",
> +                     addressTwo.getStreet());
>          assertEquals("(2) City attribute", "Portland", 
> addressTwo.getCity());
>          assertEquals("(2) State attribute", "Oregon", 
> addressTwo.getState());
>
>          obj = root.get(2);
>          assertTrue("(3) Should be an Address ", obj instanceof Address);
>          Address addressThree = (Address) obj;
> -        assertEquals("(3) Street attribute", "4th Street", addressThree.
> getStreet());
> +        assertEquals("(3) Street attribute", "4th Street",
> +                     addressThree.getStreet());
>          assertEquals("(3) City attribute", "Dayton", 
> addressThree.getCity());
>          assertEquals("(3) State attribute", "US" , addressThree.getState(
> ));
>
>          obj = root.get(3);
>          assertTrue("(4) Should be an Address ", obj instanceof Address);
>          Address addressFour = (Address) obj;
> -        assertEquals("(4) Street attribute", "6th Street", 
> addressFour.getStreet());
> +        assertEquals("(4) Street attribute", "6th Street",
> +                     addressFour.getStreet());
>          assertEquals("(4) City attribute", "Cleveland", 
> addressFour.getCity());
>          assertEquals("(4) State attribute", "Ohio", addressFour.getState(
> ));
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.
> org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [digester] unit tests swallowing exceptions

Posted by Christopher Lenz <cm...@gmx.de>.
Christopher Lenz wrote:
> Now, the question is, would anyone oppose me changing such test-cases as 
> the above so that they no longer swallow the exceptions, but rather pass 
> them on?

And here is a patch that does that, also including some line-wrapping 
fixes where lines were longer than 80 chars.

-- 
Christopher Lenz
/=/ cmlenz at gmx.de