vmassol     2003/03/17 13:48:11

  Modified:    framework/src/java/share/org/apache/cactus/server
                        AbstractWebTestCaller.java
               framework/src/java/share/org/apache/cactus
                        AbstractTestSuite.java
  Log:
  Allow wrapped JUnit Test Case to only define default constructors
  
  Revision  Changes    Path
  1.19      +17 -7     
jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestCaller.java
  
  Index: AbstractWebTestCaller.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestCaller.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- AbstractWebTestCaller.java        17 Mar 2003 19:13:52 -0000      1.18
  +++ AbstractWebTestCaller.java        17 Mar 2003 21:48:10 -0000      1.19
  @@ -428,12 +428,22 @@
                   Class wrappedTestClass = 
                       getTestClassClass(theWrappedClassName);
                   Constructor wrappedConstructor =
  -                    wrappedTestClass.getConstructor(
  -                    new Class[] {String.class});
  -                Test wrappedTestInstance = 
  -                    (Test) wrappedConstructor.newInstance(
  -                    new Object[] {theTestCaseName});
  -                    
  +                    getTestClassConstructor(wrappedTestClass);
  +
  +                Test wrappedTestInstance;
  +                if (wrappedConstructor.getParameterTypes().length == 0)
  +                {
  +                    wrappedTestInstance = 
  +                        (Test) wrappedConstructor.newInstance(
  +                        new Object[0]);                     
  +                }
  +                else
  +                {
  +                    wrappedTestInstance = 
  +                        (Test) wrappedConstructor.newInstance(
  +                        new Object[] {theTestCaseName});
  +                }
  +                                   
                   constructor = testClass.getConstructor(
                       new Class[] {String.class, Test.class});
   
  
  
  
  1.5       +38 -6     
jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestSuite.java
  
  Index: AbstractTestSuite.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestSuite.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractTestSuite.java    24 Feb 2003 10:28:23 -0000      1.4
  +++ AbstractTestSuite.java    17 Mar 2003 21:48:10 -0000      1.5
  @@ -107,8 +107,7 @@
           try
           {
               // Avoid generating multiple error messages
  -            constructor = theClass.getConstructor(
  -                new Class[] {String.class});
  +            constructor = getTestConstructor(theClass); 
           }
           catch (NoSuchMethodException e)
           {
  @@ -179,12 +178,21 @@
           {
               theNames.addElement(name);
   
  -            Object[] args = new Object[] {name};
               try
               {
                   // Note: We wrap the Test in a Cactus Test Case
  -                addTest(new ServletTestCase(name, 
  -                    (Test) theConstructor.newInstance(args)));
  +                Object constructorInstance;
  +                if (theConstructor.getParameterTypes().length == 0)
  +                {
  +                    constructorInstance = theConstructor.newInstance(
  +                        new Object[0]);
  +                }
  +                else
  +                {
  +                    constructorInstance = theConstructor.newInstance(
  +                        new Object[] {name});
  +                }
  +                addTest(new ServletTestCase(name, (Test) constructorInstance));
               }
               catch (InstantiationException e)
               {
  @@ -290,6 +298,30 @@
       public Test testAt(int theIndex)
       {
           return (Test) this.tests.elementAt(theIndex);
  +    }
  +
  +    /**
  +     * Gets a constructor which takes a single String as
  +     * its argument or a no arg constructor.
  +     * 
  +     * @param theClass the class for which to find the constructor
  +     * @return the valid constructor found
  +     * @exception NoSuchMethodException if no valid constructor is
  +     *            found
  +     */
  +    public static Constructor getTestConstructor(Class theClass) 
  +        throws NoSuchMethodException
  +    {
  +        Class[] args = {String.class};
  +        try
  +        {
  +            return theClass.getConstructor(args);   
  +        }
  +        catch (NoSuchMethodException e)
  +        {
  +            // fall through
  +        }
  +        return theClass.getConstructor(new Class[0]);
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to