maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r382699 - in /maven/surefire/branches/surefire-testng: surefire-api/src/main/java/org/apache/maven/surefire/ surefire-api/src/main/java/org/apache/maven/surefire/report/ surefire-api/src/main/java/org/apache/maven/surefire/suite/ surefire-a...
Date Fri, 03 Mar 2006 07:09:43 GMT
Author: brett
Date: Thu Mar  2 23:09:40 2006
New Revision: 382699

URL: http://svn.apache.org/viewcvs?rev=382699&view=rev
Log:
[MSUREFIRE-23] exception handling cleanup

Added:
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
  (with props)
    maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireExecutionException.java
  (with props)
Modified:
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/SurefireTestSuite.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
    maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/TestReport.java
    maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
Thu Mar  2 23:09:40 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.surefire.report.Reporter;
+import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.suite.SurefireTestSuite;
 import org.apache.maven.surefire.testset.TestSetFailedException;
@@ -38,6 +39,7 @@
 
     public boolean run( List reportDefinitions, Object[] testSuiteDefinition, String testSetName,
                         ClassLoader surefireClassLoader, ClassLoader testsClassLoader )
+        throws ReporterException, TestSetFailedException
     {
         ReporterManager reporterManager =
             new ReporterManager( instantiateReports( reportDefinitions, surefireClassLoader
) );
@@ -71,6 +73,7 @@
 
     public boolean run( List reportDefinitions, List testSuiteDefinitions, ClassLoader surefireClassLoader,
                         ClassLoader testsClassLoader )
+        throws ReporterException, TestSetFailedException
     {
         ReporterManager reporterManager =
             new ReporterManager( instantiateReports( reportDefinitions, surefireClassLoader
) );
@@ -114,26 +117,15 @@
 
     private SurefireTestSuite createSuiteFromDefinition( Object[] definition, ClassLoader
surefireClassLoader,
                                                          ClassLoader testsClassLoader )
+        throws TestSetFailedException
     {
         String suiteClass = (String) definition[0];
         Object[] params = (Object[]) definition[1];
 
         SurefireTestSuite suite = instantiateSuite( suiteClass, params, surefireClassLoader
);
 
-        try
-        {
-            suite.locateTestSets( testsClassLoader );
-        }
-        catch ( ClassNotFoundException e )
-        {
-            // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-        }
-        catch ( TestSetFailedException e )
-        {
-            // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-        }
+        suite.locateTestSets( testsClassLoader );
+
         return suite;
     }
 
@@ -150,6 +142,7 @@
     }
 */
     private List instantiateReports( List reportDefinitions, ClassLoader classLoader )
+        throws TestSetFailedException
     {
         List reports = new ArrayList();
 
@@ -169,17 +162,31 @@
     }
 
     private static Reporter instantiateReport( String className, Object[] params, ClassLoader
classLoader )
+        throws TestSetFailedException
     {
-        return (Reporter) instantiateObject( className, params, classLoader );
+        try
+        {
+            return (Reporter) instantiateObject( className, params, classLoader );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new TestSetFailedException( "Unable to find class to create report '" +
className + "'", e );
+        }
+        catch ( NoSuchMethodException e )
+        {
+            throw new TestSetFailedException(
+                "Unable to find appropriate constructor to create report: " + e.getMessage(),
e );
+        }
     }
 
     public static Object instantiateObject( String className, Object[] params, ClassLoader
classLoader )
+        throws TestSetFailedException, ClassNotFoundException, NoSuchMethodException
     {
-        Object object = null;
+        Class clazz = classLoader.loadClass( className );
+
+        Object object;
         try
         {
-            Class clazz = classLoader.loadClass( className );
-
             if ( params != null )
             {
                 Class[] paramTypes = new Class[params.length];
@@ -205,37 +212,37 @@
                 object = clazz.newInstance();
             }
         }
-        catch ( ClassNotFoundException e )
+        catch ( IllegalAccessException e )
         {
-            // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+            throw new TestSetFailedException( "Unable to instantiate object: " + e.getMessage(),
e );
         }
-        catch ( NoSuchMethodException e )
+        catch ( InvocationTargetException e )
         {
-            // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+            throw new TestSetFailedException( e.getTargetException().getMessage(), e.getTargetException()
);
         }
         catch ( InstantiationException e )
         {
-            // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-        }
-        catch ( IllegalAccessException e )
-        {
-            // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-        }
-        catch ( InvocationTargetException e )
-        {
-            // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+            throw new TestSetFailedException( "Unable to instantiate object: " + e.getMessage(),
e );
         }
         return object;
     }
 
     private static SurefireTestSuite instantiateSuite( String suiteClass, Object[] params,
ClassLoader classLoader )
+        throws TestSetFailedException
     {
-        return (SurefireTestSuite) instantiateObject( suiteClass, params, classLoader );
+        try
+        {
+            return (SurefireTestSuite) instantiateObject( suiteClass, params, classLoader
);
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new TestSetFailedException( "Unable to find class to create suite '" +
suiteClass + "'", e );
+        }
+        catch ( NoSuchMethodException e )
+        {
+            throw new TestSetFailedException(
+                "Unable to find appropriate constructor to create suite: " + e.getMessage(),
e );
+        }
     }
 
     public String getResourceString( String key )

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
Thu Mar  2 23:09:40 2006
@@ -17,7 +17,6 @@
  */
 
 import java.io.BufferedOutputStream;
-import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 
@@ -39,7 +38,7 @@
     }
 
     public void testSetStarting( ReportEntry report )
-        throws IOException
+        throws ReporterException
     {
         super.testSetStarting( report );
 

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
Thu Mar  2 23:09:40 2006
@@ -39,7 +39,7 @@
     }
 
     public void testSetStarting( ReportEntry report )
-        throws IOException
+        throws ReporterException
     {
         super.testSetStarting( report );
 
@@ -49,15 +49,22 @@
 
         reportDir.mkdirs();
 
-        PrintWriter writer = new PrintWriter( new FileWriter( reportFile ) );
-
-        writer.println( "-------------------------------------------------------------------------------"
);
-
-        writer.println( "Test set: " + report.getName() );
-
-        writer.println( "-------------------------------------------------------------------------------"
);
-
-        setWriter( writer );
+        try
+        {
+            PrintWriter writer = new PrintWriter( new FileWriter( reportFile ) );
+
+            writer.println( "-------------------------------------------------------------------------------"
);
+
+            writer.println( "Test set: " + report.getName() );
+
+            writer.println( "-------------------------------------------------------------------------------"
);
+
+            setWriter( writer );
+        }
+        catch ( IOException e )
+        {
+            throw new ReporterException( "Unable to create file for report: " + e.getMessage(),
e );
+        }
     }
 
     public void testSetCompleted( ReportEntry report )

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
Thu Mar  2 23:09:40 2006
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.text.NumberFormat;
@@ -67,7 +66,7 @@
     }
 
     public void testSetStarting( ReportEntry report )
-        throws IOException
+        throws ReporterException
     {
         testSetStartTime = System.currentTimeMillis();
     }
@@ -129,7 +128,7 @@
         return failures;
     }
 
-    public int getNbTests()
+    public int getNumTests()
     {
         return completedCount;
     }

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
Thu Mar  2 23:09:40 2006
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -94,7 +93,7 @@
     }
 
     public void testSetStarting( ReportEntry report )
-        throws IOException
+        throws ReporterException
     {
         super.testSetStarting( report );
 

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
Thu Mar  2 23:09:40 2006
@@ -31,7 +31,7 @@
 
     // Test Sets
     void testSetStarting( ReportEntry report )
-        throws Exception;
+        throws ReporterException;
 
     void testSetCompleted( ReportEntry report );
 
@@ -46,12 +46,12 @@
 
     void testFailed( ReportEntry report, String stdOut, String stdErr );
 
+    // Counters
     void reset();
 
-    // Counters... TODO (remove?)
     int getNumErrors();
 
     int getNumFailures();
 
-    int getNbTests();
+    int getNumTests();
 }

Added: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java?rev=382699&view=auto
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
(added)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
Thu Mar  2 23:09:40 2006
@@ -0,0 +1,31 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Exception occurring during report generation.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class ReporterException
+    extends Exception
+{
+    public ReporterException( String message, Exception nested )
+    {
+        super( message, nested );
+    }
+}

Propchange: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
Thu Mar  2 23:09:40 2006
@@ -102,14 +102,7 @@
         {
             Reporter report = (Reporter) i.next();
 
-            try
-            {
-                report.runStarting( testCount );
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "runStarting", e );
-            }
+            report.runStarting( testCount );
         }
     }
 
@@ -119,14 +112,7 @@
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
-            {
-                reporter.runStopped();
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "runStopped", e );
-            }
+            reporter.runStopped();
         }
     }
 
@@ -141,14 +127,7 @@
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
-            {
-                reporter.runAborted( report );
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "runAborted", e );
-            }
+            reporter.runAborted( report );
         }
 
         ++errors;
@@ -160,14 +139,7 @@
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
-            {
-                reporter.runCompleted();
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "runCompleted", e );
-            }
+            reporter.runCompleted();
         }
 
         writeMessage( "" );
@@ -181,19 +153,13 @@
     private ByteArrayOutputStream stdErr;
 
     public void testSetStarting( ReportEntry report )
+        throws ReporterException
     {
         for ( Iterator it = reports.iterator(); it.hasNext(); )
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
-            {
-                reporter.testSetStarting( report );
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "suiteStarting", e );
-            }
+            reporter.testSetStarting( report );
         }
     }
 
@@ -207,7 +173,7 @@
 
             failures += reporter.getNumFailures();
 
-            completedCount += reporter.getNbTests();
+            completedCount += reporter.getNumTests();
         }
 
         for ( Iterator it = reports.iterator(); it.hasNext(); )
@@ -230,14 +196,7 @@
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
-            {
-                reporter.testSetAborted( report );
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "suiteAborted", e );
-            }
+            reporter.testSetAborted( report );
         }
 
         ++errors;
@@ -271,14 +230,7 @@
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
-            {
-                reporter.testStarting( report );
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "testStarting", e );
-            }
+            reporter.testStarting( report );
         }
     }
 
@@ -290,14 +242,7 @@
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
-            {
-                reporter.testSucceeded( report );
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "testSucceeded", e );
-            }
+            reporter.testSucceeded( report );
         }
     }
 
@@ -323,20 +268,13 @@
         {
             Reporter reporter = (Reporter) it.next();
 
-            try
+            if ( "failure".equals( typeError ) )
             {
-                if ( "failure".equals( typeError ) )
-                {
-                    reporter.testFailed( reportEntry, stdOutLog, stdErrLog );
-                }
-                else
-                {
-                    reporter.testError( reportEntry, stdOutLog, stdErrLog );
-                }
+                reporter.testFailed( reportEntry, stdOutLog, stdErrLog );
             }
-            catch ( Exception e )
+            else
             {
-                handleReporterException( "testFailed", e );
+                reporter.testError( reportEntry, stdOutLog, stdErrLog );
             }
         }
     }
@@ -356,14 +294,7 @@
         {
             Reporter report = (Reporter) it.next();
 
-            try
-            {
-                report.reset();
-            }
-            catch ( Exception e )
-            {
-                handleReporterException( "reset", e );
-            }
+            report.reset();
         }
     }
 
@@ -384,26 +315,6 @@
     public int getNbTests()
     {
         return completedCount;
-    }
-
-    /**
-     * @todo is this here for throwables? most of these don't throw any checked exceptions
-     */
-    private void handleReporterException( String reporterMethod, Exception e )
-    {
-/*
-        String reporterThrewException = Surefire.getResourceString( "reporterThrew" );
-
-        MessageFormat msgFmt = new MessageFormat( reporterThrewException );
-
-        Object[] args = {reporterMethod};
-
-        String stringToPrint = msgFmt.format( args );
-
-        System.err.println( stringToPrint );
-
-        e.printStackTrace( System.err );
-*/
     }
 
 }

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
Thu Mar  2 23:09:40 2006
@@ -22,8 +22,8 @@
 
 import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
@@ -69,7 +69,7 @@
     }
 
     public void testSetStarting( ReportEntry report )
-        throws IOException, UnsupportedEncodingException
+        throws ReporterException
     {
         super.testSetStarting( report );
 
@@ -79,8 +79,19 @@
 
         reportDir.mkdirs();
 
-        writer = new PrintWriter(
-            new BufferedWriter( new OutputStreamWriter( new FileOutputStream( reportFile
), "UTF-8" ) ) );
+        try
+        {
+            writer = new PrintWriter(
+                new BufferedWriter( new OutputStreamWriter( new FileOutputStream( reportFile
), "UTF-8" ) ) );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            throw new ReporterException( "Unable to use UTF-8 encoding", e );
+        }
+        catch ( FileNotFoundException e )
+        {
+            throw new ReporterException( "Unable to create file: " + e.getMessage(), e );
+        }
 
         writer.write( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" );
 
@@ -92,7 +103,7 @@
     {
         super.testSetCompleted( report );
 
-        testSuite.setAttribute( "tests", String.valueOf( this.getNbTests() ) );
+        testSuite.setAttribute( "tests", String.valueOf( this.getNumTests() ) );
 
         testSuite.setAttribute( "errors", String.valueOf( this.getNumErrors() ) );
 

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
Thu Mar  2 23:09:40 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.testset.SurefireTestSet;
 import org.apache.maven.surefire.testset.TestSetFailedException;
@@ -61,7 +62,7 @@
     }
 
     public Map locateTestSets( ClassLoader classLoader )
-        throws ClassNotFoundException, TestSetFailedException
+        throws TestSetFailedException
     {
         if ( testSets != null )
         {
@@ -75,11 +76,18 @@
         {
             String className = tests[i];
 
-            SurefireTestSet testSet = createTestSet( className, classLoader );
+            SurefireTestSet testSet;
+            try
+            {
+                testSet = createTestSet( className, classLoader );
+            }
+            catch ( ClassNotFoundException e )
+            {
+                throw new TestSetFailedException( "Unable to create test class '" + className
+ "'", e );
+            }
 
             if ( testSets.containsKey( testSet.getName() ) )
             {
-                // TODO: better error
                 throw new TestSetFailedException( "Duplicate test set '" + testSet.getName()
+ "'" );
             }
 
@@ -97,6 +105,7 @@
         throws ClassNotFoundException;
 
     public void execute( ReporterManager reporterManager, ClassLoader classLoader )
+        throws ReporterException, TestSetFailedException
     {
         if ( testSets == null )
         {
@@ -111,34 +120,28 @@
     }
 
     private void executeTestSet( SurefireTestSet testSet, ReporterManager reporterManager,
ClassLoader classLoader )
+        throws ReporterException, TestSetFailedException
     {
-        try
-        {
-            // TODO: fix all these messages, and improve bundle resolution
-            String rawString = bundle.getString( "testSetStarting" );
+        // TODO: fix all these messages, and improve bundle resolution
+        String rawString = bundle.getString( "testSetStarting" );
 
-            ReportEntry report = new ReportEntry( this, testSet.getName(), rawString );
+        ReportEntry report = new ReportEntry( this, testSet.getName(), rawString );
 
-            reporterManager.testSetStarting( report );
+        reporterManager.testSetStarting( report );
 
-            testSet.execute( reporterManager, classLoader );
+        testSet.execute( reporterManager, classLoader );
 
-            rawString = bundle.getString( "testSetCompletedNormally" );
+        rawString = bundle.getString( "testSetCompletedNormally" );
 
-            report = new ReportEntry( this, testSet.getName(), rawString );
+        report = new ReportEntry( this, testSet.getName(), rawString );
 
-            reporterManager.testSetCompleted( report );
+        reporterManager.testSetCompleted( report );
 
-            reporterManager.reset();
-        }
-        catch ( Exception e )
-        {
-            // TODO
-            e.printStackTrace();
-        }
+        reporterManager.reset();
     }
 
     public void execute( String testSetName, ReporterManager reporterManager, ClassLoader
classLoader )
+        throws ReporterException, TestSetFailedException
     {
         if ( testSets == null )
         {
@@ -148,7 +151,7 @@
 
         if ( testSet == null )
         {
-            // TODO: throw exception
+            throw new TestSetFailedException( "Unable to find test set '" + testSetName +
"' in suite" );
         }
 
         executeTestSet( testSet, reporterManager, classLoader );

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/SurefireTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/SurefireTestSuite.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/SurefireTestSuite.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/SurefireTestSuite.java
Thu Mar  2 23:09:40 2006
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 
@@ -28,14 +29,16 @@
  */
 public interface SurefireTestSuite
 {
-    void execute( ReporterManager reporterManager, ClassLoader classLoader );
+    void execute( ReporterManager reporterManager, ClassLoader classLoader )
+        throws ReporterException, TestSetFailedException;
 
-    void execute( String testSetName, ReporterManager reporterManager, ClassLoader classLoader
);
+    void execute( String testSetName, ReporterManager reporterManager, ClassLoader classLoader
)
+        throws ReporterException, TestSetFailedException;
 
     int getNumTests();
 
     int getNumTestSets();
 
     Map locateTestSets( ClassLoader classLoader )
-        throws ClassNotFoundException, TestSetFailedException;
+        throws TestSetFailedException;
 }

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
Thu Mar  2 23:09:40 2006
@@ -21,9 +21,8 @@
 public interface SurefireTestSet
 {
     void execute( ReporterManager reportManager, ClassLoader loader )
-        throws Exception;
+        throws TestSetFailedException;
 
-    // TODO: fix exception and its propogation
     int getTestCount()
         throws TestSetFailedException;
 

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/TestReport.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/TestReport.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/TestReport.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/TestReport.java
Thu Mar  2 23:09:40 2006
@@ -108,9 +108,9 @@
         return 0;
     }
 
-    public int getNbTests()
+    public int getNumTests()
     {
-        System.out.println( "TestReport::getNbTests" );
+        System.out.println( "TestReport::getNumTests" );
         return 0;
     }
 }

Modified: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Thu Mar  2 23:09:40 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.surefire.Surefire;
+import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -107,10 +108,8 @@
         this.forkConfiguration = forkConfiguration;
     }
 
-    // TODO: fix error handling
     public boolean run()
-        throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException,
-        InvocationTargetException, MalformedURLException, SurefireBooterForkException
+        throws SurefireBooterForkException, SurefireExecutionException
     {
         boolean result = false;
 
@@ -130,8 +129,7 @@
     }
 
     private boolean runSuitesInProcess( String testSet, boolean childDelegation )
-        throws MalformedURLException, ClassNotFoundException, IllegalAccessException, InstantiationException,
-        NoSuchMethodException, InvocationTargetException
+        throws SurefireExecutionException
     {
         if ( testSuites.size() != 1 )
         {
@@ -140,56 +138,79 @@
 
         // TODO: replace with plexus
 
-        ClassLoader surefireClassLoader = createClassLoader( surefireClassPathUrls, getClass().getClassLoader()
);
+        //noinspection CatchGenericClass,OverlyBroadCatchBlock
+        try
+        {
+            ClassLoader surefireClassLoader = createClassLoader( surefireClassPathUrls, getClass().getClassLoader()
);
 
-        ClassLoader testsClassLoader = createClassLoader( classPathUrls, childDelegation
);
+            ClassLoader testsClassLoader = createClassLoader( classPathUrls, childDelegation
);
 
-        Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName() );
+            Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName()
);
 
-        Object surefire = surefireClass.newInstance();
+            Object surefire = surefireClass.newInstance();
 
-        Method run = surefireClass.getMethod( "run", new Class[]{List.class, Object[].class,
String.class,
-            ClassLoader.class, ClassLoader.class} );
+            Method run = surefireClass.getMethod( "run", new Class[]{List.class, Object[].class,
String.class,
+                ClassLoader.class, ClassLoader.class} );
 
-        ClassLoader oldContextClassLoader = Thread.currentThread() .getContextClassLoader();
+            ClassLoader oldContextClassLoader = Thread.currentThread() .getContextClassLoader();
 
-        Thread.currentThread().setContextClassLoader( testsClassLoader );
+            Thread.currentThread().setContextClassLoader( testsClassLoader );
 
-        Boolean result = (Boolean) run.invoke( surefire, new Object[]{reports, testSuites.get(
0 ), testSet,
-            surefireClassLoader, testsClassLoader} );
+            Boolean result = (Boolean) run.invoke( surefire, new Object[]{reports, testSuites.get(
0 ), testSet,
+                surefireClassLoader, testsClassLoader} );
 
-        Thread.currentThread().setContextClassLoader( oldContextClassLoader );
+            Thread.currentThread().setContextClassLoader( oldContextClassLoader );
 
-        return result.booleanValue();
+            return result.booleanValue();
+        }
+        catch ( InvocationTargetException e )
+        {
+            throw new SurefireExecutionException( e.getTargetException().getMessage(), e.getTargetException()
);
+        }
+        catch ( Exception e )
+        {
+            throw new SurefireExecutionException( "Unable to instantiate and execute Surefire",
e );
+        }
     }
 
     private boolean runSuitesInProcess( boolean childDelegation )
-        throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException,
-        InvocationTargetException, MalformedURLException
+        throws SurefireExecutionException
     {
         // TODO: replace with plexus
 
-        ClassLoader surefireClassLoader = createClassLoader( surefireClassPathUrls, getClass().getClassLoader()
);
+        //noinspection CatchGenericClass,OverlyBroadCatchBlock
+        try
+        {
+            ClassLoader surefireClassLoader = createClassLoader( surefireClassPathUrls, getClass().getClassLoader()
);
 
-        ClassLoader testsClassLoader = createClassLoader( classPathUrls, childDelegation
);
+            ClassLoader testsClassLoader = createClassLoader( classPathUrls, childDelegation
);
 
-        Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName() );
+            Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName()
);
 
-        Object surefire = surefireClass.newInstance();
+            Object surefire = surefireClass.newInstance();
 
-        Method run =
-            surefireClass.getMethod( "run", new Class[]{List.class, List.class, ClassLoader.class,
ClassLoader.class} );
+            Method run = surefireClass.getMethod( "run", new Class[]{List.class, List.class,
ClassLoader.class,
+                ClassLoader.class} );
 
-        ClassLoader oldContextClassLoader = Thread.currentThread() .getContextClassLoader();
+            ClassLoader oldContextClassLoader = Thread.currentThread() .getContextClassLoader();
 
-        Thread.currentThread().setContextClassLoader( testsClassLoader );
+            Thread.currentThread().setContextClassLoader( testsClassLoader );
 
-        Boolean result =
-            (Boolean) run.invoke( surefire, new Object[]{reports, testSuites, surefireClassLoader,
testsClassLoader} );
+            Boolean result = (Boolean) run.invoke( surefire, new Object[]{reports, testSuites,
surefireClassLoader,
+                testsClassLoader} );
 
-        Thread.currentThread().setContextClassLoader( oldContextClassLoader );
+            Thread.currentThread().setContextClassLoader( oldContextClassLoader );
 
-        return result.booleanValue();
+            return result.booleanValue();
+        }
+        catch ( InvocationTargetException e )
+        {
+            throw new SurefireExecutionException( e.getTargetException().getMessage(), e.getTargetException()
);
+        }
+        catch ( Exception e )
+        {
+            throw new SurefireExecutionException( "Unable to instantiate and execute Surefire",
e );
+        }
     }
 
     private boolean runSuitesForkOnce()
@@ -244,7 +265,24 @@
 
         Object[] params = (Object[]) testSuite[1];
 
-        Object suite = Surefire.instantiateObject( className, params, surefireClassLoader
);
+        Object suite;
+        try
+        {
+            suite = Surefire.instantiateObject( className, params, surefireClassLoader );
+        }
+        catch ( TestSetFailedException e )
+        {
+            throw new SurefireBooterForkException( e.getMessage(), e.getCause() );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new SurefireBooterForkException( "Unable to find class for test suite '"
+ className + "'", e );
+        }
+        catch ( NoSuchMethodException e )
+        {
+            throw new SurefireBooterForkException(
+                "Unable to find appropriate constructor for test suite '" + className + "':
" + e.getMessage(), e );
+        }
 
         Map testSets;
         try
@@ -263,7 +301,7 @@
         }
         catch ( InvocationTargetException e )
         {
-            throw new SurefireBooterForkException( "Error obtaining test sets", e );
+            throw new SurefireBooterForkException( e.getTargetException().getMessage(), e.getTargetException()
);
         }
         return testSets;
     }
@@ -553,8 +591,7 @@
      * @param args
      */
     public static void main( String[] args )
-        throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException,
-        NoSuchMethodException, IOException
+        throws SurefireExecutionException, IOException
     {
         if ( args.length > 1 )
         {

Added: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireExecutionException.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireExecutionException.java?rev=382699&view=auto
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireExecutionException.java
(added)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireExecutionException.java
Thu Mar  2 23:09:40 2006
@@ -0,0 +1,31 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * An error occurring during the invocation of Surefire via an alternate class loader.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class SurefireExecutionException
+    extends Exception
+{
+    public SurefireExecutionException( String message, Throwable nested )
+    {
+        super( message, nested );
+    }
+}

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireExecutionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireExecutionException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
Thu Mar  2 23:09:40 2006
@@ -23,7 +23,7 @@
 import java.util.ArrayList;
 
 /**
- * TODO: Description.
+ * Test suite for JUnit tests based on a directory of Java test classes.
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  */

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
Thu Mar  2 23:09:40 2006
@@ -273,7 +273,7 @@
         }
         catch ( InvocationTargetException e )
         {
-            throw new TestSetFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e.getTargetException()
);
         }
     }
 
@@ -305,7 +305,7 @@
         }
         catch ( InvocationTargetException e )
         {
-            throw new TestSetFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e.getTargetException()
);
         }
     }
 

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?rev=382699&r1=382698&r2=382699&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
Thu Mar  2 23:09:40 2006
@@ -23,7 +23,7 @@
 import java.util.ArrayList;
 
 /**
- * Test suite for TestNG based on a directory of Java test classes.
+ * Test suite for TestNG based on a directory of Java test classes. Can also execute JUnit
tests.
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  */



Mime
View raw message