maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r381892 - in /maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire: battery/ battery/assertion/ report/ util/
Date Wed, 01 Mar 2006 03:29:12 GMT
Author: brett
Date: Tue Feb 28 19:29:10 2006
New Revision: 381892

URL: http://svn.apache.org/viewcvs?rev=381892&view=rev
Log:
clean up using inspections

Modified:
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/AbstractBattery.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/SingleTestBattery.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestListenerInvocationHandler.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryAssert.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryComparisonFailure.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryTestFailedException.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/FileReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingReport.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingSummaryConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/SummaryConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
    maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/util/TeeStream.java

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/AbstractBattery.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/AbstractBattery.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/AbstractBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/AbstractBattery.java Tue Feb 28 19:29:10 2006
@@ -38,6 +38,8 @@
 
     private List subBatteryClassNames;
 
+    private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
+
     public void execute( ReporterManager reportManager )
         throws Exception
     {
@@ -61,13 +63,11 @@
             discoverTestMethods();
         }
 
-        Object[] args = new Object[0];
-
         boolean abort = false;
 
-        for ( int i = 0; ( i < testMethods.size() ) && !abort; ++i )
+        for ( int i = 0; i < testMethods.size() && !abort; ++i )
         {
-            abort = executeTestMethod( (Method) testMethods.get( i ), args, reportManager );
+            abort = executeTestMethod( (Method) testMethods.get( i ), EMPTY_OBJECT_ARRAY, reportManager );
         }
     }
 
@@ -176,12 +176,6 @@
 
             String stringToPrint = msgFmt.format( stringArgs );
 
-            String msg = e.getMessage();
-            if ( msg == null )
-            {
-                msg = e.toString();
-            }
-
             report = new ReportEntry( this, getTestName( userFriendlyMethodName ), stringToPrint, e );
 
             reportManager.testFailed( report );
@@ -246,46 +240,40 @@
 
     protected void discoverTestMethods()
     {
-        if ( testMethods != null )
+        if ( testMethods == null )
         {
-            return;
-        }
-
-        testMethods = new ArrayList();
+            testMethods = new ArrayList();
 
-        Method[] methods = getTestClass().getMethods();
+            Method[] methods = getTestClass().getMethods();
 
-        for ( int i = 0; i < methods.length; ++i )
-        {
-            Method m = methods[i];
+            for ( int i = 0; i < methods.length; ++i )
+            {
+                Method m = methods[i];
 
-            Class[] paramTypes = m.getParameterTypes();
+                Class[] paramTypes = m.getParameterTypes();
 
-            boolean isInstanceMethod = !Modifier.isStatic( m.getModifiers() );
+                boolean isInstanceMethod = !Modifier.isStatic( m.getModifiers() );
 
-            boolean returnsVoid = m.getReturnType() == void.class;
+                boolean returnsVoid = m.getReturnType().equals( void.class );
 
-            boolean hasNoParams = paramTypes.length == 0;
+                boolean hasNoParams = paramTypes.length == 0;
 
-            if ( isInstanceMethod && returnsVoid && hasNoParams )
-            {
-                String simpleName = m.getName();
-
-                if ( simpleName.length() <= 4 )
+                if ( isInstanceMethod && returnsVoid && hasNoParams )
                 {
-                    // name must have 5 or more chars
-                    continue;
-                }
-
-                String firstFour = simpleName.substring( 0, 4 );
+                    String simpleName = m.getName();
 
-                if ( !firstFour.equals( TEST_METHOD_PREFIX ) )
-                {
-                    // name must start with "test"
-                    continue;
+                    // name must have 5 or more chars
+                    if ( simpleName.length() > 4 )
+                    {
+                        String firstFour = simpleName.substring( 0, 4 );
+
+                        // name must start with "test"
+                        if ( firstFour.equals( TEST_METHOD_PREFIX ) )
+                        {
+                            testMethods.add( m );
+                        }
+                    }
                 }
-
-                testMethods.add( m );
             }
         }
     }

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java Tue Feb 28 19:29:10 2006
@@ -23,10 +23,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
-public class DirectoryBattery
+public final class DirectoryBattery
     extends AbstractBattery
 {
-
     private static final String FS = System.getProperty( "file.separator" );
 
     private File basedir;
@@ -52,20 +51,18 @@
     {
         String[] tests = collectTests( basedir, includes, excludes );
 
-        if ( tests == null )
-        {
-            return;
-        }
-
-        for ( int i = 0; i < tests.length; i++ )
+        if ( tests != null )
         {
-            String s = tests[i];
+            for ( int i = 0; i < tests.length; i++ )
+            {
+                String s = tests[i];
 
-            s = s.substring( 0, s.indexOf( "." ) );
+                s = s.substring( 0, s.indexOf( "." ) );
 
-            s = s.replace( FS.charAt( 0 ), ".".charAt( 0 ) );
+                s = s.replace( FS.charAt( 0 ), ".".charAt( 0 ) );
 
-            addSubBatteryClassName( s );
+                addSubBatteryClassName( s );
+            }
         }
     }
 

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java Tue Feb 28 19:29:10 2006
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import org.apache.maven.surefire.battery.assertion.BatteryTestFailedException;
 import org.apache.maven.surefire.report.ReporterManager;
 
 import java.lang.reflect.Constructor;
@@ -24,7 +25,7 @@
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
 
-public class JUnitBattery
+public final class JUnitBattery
     extends AbstractBattery
 {
     public static final String TEST_CASE = "junit.framework.TestCase";
@@ -63,25 +64,29 @@
 
     private Method runMethod;
 
+    private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
+
+    private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
+
     public JUnitBattery( String testClassName )
         throws Exception
     {
         processTestClass( getClass().getClassLoader().loadClass( testClassName ), getClass().getClassLoader() );
     }
 
-    public JUnitBattery( final String testClass, ClassLoader loader )
+    public JUnitBattery( String testClass, ClassLoader loader )
         throws Exception
     {
         processTestClass( loader.loadClass( testClass ), loader );
     }
 
-    public JUnitBattery( final Class testClass, ClassLoader loader )
+    public JUnitBattery( Class testClass, ClassLoader loader )
         throws Exception
     {
         processTestClass( testClass, loader );
     }
 
-    public void processTestClass( final Class testClass, ClassLoader loader )
+    private void processTestClass( Class testClass, ClassLoader loader )
         throws Exception
     {
         if ( testClass == null )
@@ -119,15 +124,14 @@
         // o look for test classes that only implement the Test interface
         // ----------------------------------------------------------------------
 
+        Object testObject = null;
         try
         {
-            Class[] emptyArgs = new Class[0];
-
-            Method suiteMethod = testClass.getMethod( "suite", emptyArgs );
+            Method suiteMethod = testClass.getMethod( "suite", EMPTY_CLASS_ARRAY );
 
             if ( Modifier.isPublic( suiteMethod.getModifiers() ) && Modifier.isStatic( suiteMethod.getModifiers() ) )
             {
-                testObject = suiteMethod.invoke( null, emptyArgs );
+                testObject = suiteMethod.invoke( null, EMPTY_CLASS_ARRAY );
             }
         }
         catch ( NoSuchMethodException e )
@@ -151,13 +155,14 @@
 
             if ( testConstructor.getParameterTypes().length == 0 )
             {
-                testObject = testConstructor.newInstance( new Object[0] );
+                testObject = testConstructor.newInstance( EMPTY_OBJECT_ARRAY );
             }
             else
             {
                 testObject = testConstructor.newInstance( new Object[]{testClass.getName()} );
             }
         }
+        this.testObject = testObject;
 
         interfacesImplementedByDynamicProxy = new Class[1];
 
@@ -171,7 +176,7 @@
 
         if ( testInterface.isAssignableFrom( testClass ) )//testObject.getClass() ) )
         {
-            countTestCasesMethod = testInterface.getMethod( COUNT_TEST_CASES_METHOD, new Class[0] );
+            countTestCasesMethod = testInterface.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
 
             runMethod = testInterface.getMethod( RUN_METHOD, new Class[]{testResultClass} );
 
@@ -180,7 +185,7 @@
         {
             try
             {
-                countTestCasesMethod = testClass.getMethod( COUNT_TEST_CASES_METHOD, new Class[0] );
+                countTestCasesMethod = testClass.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
             }
             catch ( Exception e )
             {
@@ -221,7 +226,7 @@
         }
     }
 
-    protected void executeJUnit( ReporterManager reportManager )
+    private void executeJUnit( ReporterManager reportManager )
     {
         try
         {
@@ -243,23 +248,19 @@
         }
         catch ( IllegalArgumentException e )
         {
-            throw new org.apache.maven.surefire.battery.assertion.BatteryTestFailedException(
-                testObject.getClass().getName(), e );
+            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
         }
         catch ( InstantiationException e )
         {
-            throw new org.apache.maven.surefire.battery.assertion.BatteryTestFailedException(
-                testObject.getClass().getName(), e );
+            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
         }
         catch ( IllegalAccessException e )
         {
-            throw new org.apache.maven.surefire.battery.assertion.BatteryTestFailedException(
-                testObject.getClass().getName(), e );
+            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
         }
         catch ( InvocationTargetException e )
         {
-            throw new org.apache.maven.surefire.battery.assertion.BatteryTestFailedException(
-                testObject.getClass().getName(), e );
+            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
         }
     }
 
@@ -267,52 +268,50 @@
     {
         try
         {
+            int testCount;
             if ( countTestCasesMethod != null )
             {
-                Integer integer = (Integer) countTestCasesMethod.invoke( testObject, new Class[0] );
+                Integer integer = (Integer) countTestCasesMethod.invoke( testObject, EMPTY_CLASS_ARRAY );
 
-                return integer.intValue();
+                testCount = integer.intValue();
             }
             else
             {
-                return super.getTestCount();
+                testCount = super.getTestCount();
             }
+            return testCount;
         }
         catch ( IllegalAccessException e )
         {
-            throw new org.apache.maven.surefire.battery.assertion.BatteryTestFailedException(
-                testObject.getClass().getName(), e );
+            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
         }
         catch ( IllegalArgumentException e )
         {
-            throw new org.apache.maven.surefire.battery.assertion.BatteryTestFailedException(
-                testObject.getClass().getName(), e );
+            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
         }
         catch ( InvocationTargetException e )
         {
-            throw new org.apache.maven.surefire.battery.assertion.BatteryTestFailedException(
-                testObject.getClass().getName(), e );
+            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
         }
     }
 
     public String getBatteryName()
     {
         return testClass.getName();
-        //return testClass.getPackage().getName();
     }
 
-    protected Constructor getTestConstructor( Class testClass )
+    private Constructor getTestConstructor( Class testClass )
         throws NoSuchMethodException
     {
-        Class[] params = {String.class};
-
+        Constructor constructor;
         try
         {
-            return testClass.getConstructor( params );
+            constructor = testClass.getConstructor( new Class[]{String.class} );
         }
         catch ( NoSuchMethodException e )
         {
-            return testClass.getConstructor( new Class[0] );
+            constructor = testClass.getConstructor( EMPTY_CLASS_ARRAY );
         }
+        return constructor;
     }
 }

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/SingleTestBattery.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/SingleTestBattery.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/SingleTestBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/SingleTestBattery.java Tue Feb 28 19:29:10 2006
@@ -26,8 +26,6 @@
 public class SingleTestBattery
     extends AbstractBattery
 {
-    private String testClassName;
-
     private Class testClass;
 
     private Object testObject;
@@ -35,8 +33,6 @@
     public SingleTestBattery( String testClassName )
         throws Exception
     {
-        this.testClassName = testClassName;
-
         this.testClass = getClass().getClassLoader().loadClass( testClassName );
 
         this.testObject = testClass.newInstance();

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestListenerInvocationHandler.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestListenerInvocationHandler.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestListenerInvocationHandler.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestListenerInvocationHandler.java Tue Feb 28 19:29:10 2006
@@ -22,6 +22,7 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.util.HashSet;
+import java.util.Set;
 
 public class TestListenerInvocationHandler
     implements InvocationHandler
@@ -35,17 +36,17 @@
 
     private static final String END_TEST = "endTest";
 
-    private HashSet failedTestsSet = new HashSet();
+    private Set failedTestsSet = new HashSet();
 
     private ReporterManager reportManager;
 
-    private class FailedTest
+    private static class FailedTest
     {
         private Object testThatFailed;
 
         private Thread threadOnWhichTestFailed;
 
-        public FailedTest( Object testThatFailed, Thread threadOnWhichTestFailed )
+        FailedTest( Object testThatFailed, Thread threadOnWhichTestFailed )
         {
             if ( testThatFailed == null )
             {
@@ -62,27 +63,29 @@
             this.threadOnWhichTestFailed = threadOnWhichTestFailed;
         }
 
-        public boolean equals( Object o )
+        public boolean equals( Object obj )
         {
+            boolean retVal = true;
 
-            if ( ( o == null ) || ( getClass() != o.getClass() ) )
+            if ( obj == null || getClass() != obj.getClass() )
             {
-                return false;
+                retVal = false;
             }
-
-            FailedTest ft = (FailedTest) o;
-
-            if ( ft.testThatFailed != testThatFailed )
+            else
             {
-                return false;
-            }
+                FailedTest ft = (FailedTest) obj;
 
-            if ( !ft.threadOnWhichTestFailed.equals( threadOnWhichTestFailed ) )
-            {
-                return false;
+                if ( ft.testThatFailed != testThatFailed )
+                {
+                    retVal = false;
+                }
+                else if ( !ft.threadOnWhichTestFailed.equals( threadOnWhichTestFailed ) )
+                {
+                    retVal = false;
+                }
             }
 
-            return true;
+            return retVal;
         }
 
         public int hashCode()

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java Tue Feb 28 19:29:10 2006
@@ -45,10 +45,8 @@
      *
      * @param testClass
      * @param loader
-     * @throws Exception
      */
-    public TestNGBattery( final Class testClass, ClassLoader loader )
-        throws Exception
+    public TestNGBattery( Class testClass, ClassLoader loader )
     {
         processTestClass( testClass, loader );
     }
@@ -59,10 +57,8 @@
      *
      * @param testClass
      * @param loader
-     * @throws Exception
      */
-    public void processTestClass( final Class testClass, ClassLoader loader )
-        throws Exception
+    private void processTestClass( Class testClass, ClassLoader loader )
     {
         if ( testClass == null )
         {
@@ -84,51 +80,45 @@
 
     protected void discoverTestMethods()
     {
-        if ( testMethods != null )
+        if ( testMethods == null )
         {
-            return;
-        }
-
-        testMethods = new ArrayList();
+            testMethods = new ArrayList();
 
-        Method[] methods = testClass.getMethods();
-
-        for ( int i = 0; i < methods.length; ++i )
-        {
-            Method m = methods[i];
+            Method[] methods = testClass.getMethods();
 
-            Class[] paramTypes = m.getParameterTypes();
+            for ( int i = 0; i < methods.length; ++i )
+            {
+                Method m = methods[i];
 
-            boolean isInstanceMethod = !Modifier.isStatic( m.getModifiers() );
+                Class[] paramTypes = m.getParameterTypes();
 
-            boolean returnsVoid = m.getReturnType() == void.class;
+                boolean isInstanceMethod = !Modifier.isStatic( m.getModifiers() );
 
-            boolean hasNoParams = paramTypes.length == 0;
+                boolean returnsVoid = m.getReturnType().equals( void.class );
 
-            if ( isInstanceMethod && returnsVoid && hasNoParams )
-            {
-                String simpleName = m.getName();
+                boolean hasNoParams = paramTypes.length == 0;
 
-                if ( simpleName.length() <= 4 )
+                if ( isInstanceMethod && returnsVoid && hasNoParams )
                 {
+                    String simpleName = m.getName();
+
+                    // TODO: WHY?
                     // name must have 5 or more chars
-                    continue;
+                    if ( simpleName.length() > 4 )
+                    {
+                        testMethods.add( m );
+                    }
                 }
-
-                testMethods.add( m );
             }
         }
     }
 
     public void discoverBatteryClassNames()
-        throws Exception
     {
     }
 
     public void execute( ReporterManager reportManager )
-        throws Exception
     {
-        // TODO Auto-generated method stub
     }
 
     public String getBatteryName()

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java Tue Feb 28 19:29:10 2006
@@ -1,6 +1,3 @@
-/**
- * 
- */
 package org.apache.maven.surefire.battery;
 
 /*
@@ -36,7 +33,6 @@
 import java.util.Collections;
 import java.util.List;
 
-
 /**
  * Handles suite xml file definitions for TestNG.
  *
@@ -45,12 +41,11 @@
 public class TestNGXMLBattery
     implements Battery
 {
-
     protected File suiteFile;
 
     protected TestNG testRunner;
 
-    protected int m_testCount = 0;
+    protected int m_testCount;
 
     protected String m_suiteName = "TestNG XML Suite";
 
@@ -65,12 +60,10 @@
     }
 
     public void discoverBatteryClassNames()
-        throws Exception
     {
     }
 
     public void execute( ReporterManager reportManager )
-        throws Exception
     {
         testRunner.runSuitesLocally();
     }
@@ -104,7 +97,7 @@
     /**
      * Instantiates and partially configures testng suite
      */
-    protected void parseSuite()
+    private void parseSuite()
     {
         testRunner = new TestNG();
         List suites = new ArrayList();

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryAssert.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryAssert.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryAssert.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryAssert.java Tue Feb 28 19:29:10 2006
@@ -112,16 +112,13 @@
 
     public static void assertEquals( String message, Object expected, Object actual )
     {
-        if ( expected == null && actual == null )
+        if ( expected != null || actual != null )
         {
-            return;
-        }
-        if ( expected != null && expected.equals( actual ) )
-        {
-            return;
+            if ( expected == null || !expected.equals( actual ) )
+            {
+                failNotEquals( message, expected, actual );
+            }
         }
-
-        failNotEquals( message, expected, actual );
     }
 
     public static void assertEquals( Object expected, Object actual )
@@ -131,17 +128,13 @@
 
     public static void assertEquals( String message, String expected, String actual )
     {
-        if ( expected == null && actual == null )
+        if ( expected != null || actual != null )
         {
-            return;
-        }
-
-        if ( expected != null && expected.equals( actual ) )
-        {
-            return;
+            if ( expected == null || !expected.equals( actual ) )
+            {
+                throw new BatteryComparisonFailure( message, expected, actual );
+            }
         }
-
-        throw new BatteryComparisonFailure( message, expected, actual );
     }
 
     public static void assertEquals( String expected, String actual )
@@ -155,7 +148,7 @@
         // the following test fails
         if ( Double.isInfinite( expected ) )
         {
-            if ( !( expected == actual ) )
+            if ( !Double.isInfinite( actual ) )
             {
                 failNotEquals( message, new Double( expected ), new Double( actual ) );
             }
@@ -177,7 +170,7 @@
         // the following test fails
         if ( Float.isInfinite( expected ) )
         {
-            if ( !( expected == actual ) )
+            if ( !Float.isInfinite( actual ) )
             {
                 failNotEquals( message, new Float( expected ), new Float( actual ) );
             }
@@ -206,7 +199,7 @@
 
     public static void assertEquals( String message, boolean expected, boolean actual )
     {
-        assertEquals( message, new Boolean( expected ), new Boolean( actual ) );
+        assertEquals( message, Boolean.valueOf( expected ), Boolean.valueOf( actual ) );
     }
 
     public static void assertEquals( boolean expected, boolean actual )
@@ -276,12 +269,11 @@
 
     public static void assertSame( String message, Object expected, Object actual )
     {
-        if ( expected == actual )
+        //noinspection ObjectEquality
+        if ( expected != actual )
         {
-            return;
+            failNotSame( message, expected, actual );
         }
-
-        failNotSame( message, expected, actual );
     }
 
     public static void assertSame( Object expected, Object actual )
@@ -291,6 +283,7 @@
 
     public static void assertNotSame( String message, Object expected, Object actual )
     {
+        //noinspection ObjectEquality
         if ( expected == actual )
         {
             failSame( message );
@@ -302,7 +295,7 @@
         assertNotSame( null, expected, actual );
     }
 
-    static private void failSame( String message )
+    private static void failSame( String message )
     {
         String formatted = "";
 
@@ -314,7 +307,7 @@
         fail( formatted + "expected not same" );
     }
 
-    static private void failNotSame( String message, Object expected, Object actual )
+    private static void failNotSame( String message, Object expected, Object actual )
     {
         String formatted = "";
 
@@ -326,7 +319,7 @@
         fail( formatted + "expected same:<" + expected + "> was not:<" + actual + ">" );
     }
 
-    static private void failNotEquals( String message, Object expected, Object actual )
+    private static void failNotEquals( String message, Object expected, Object actual )
     {
         fail( formatMismatch( message, expected, actual ) );
     }

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryComparisonFailure.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryComparisonFailure.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryComparisonFailure.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryComparisonFailure.java Tue Feb 28 19:29:10 2006
@@ -50,55 +50,59 @@
      */
     public String getMessage()
     {
+        String actual;
+        String expected;
         if ( fExpected == null || fActual == null )
         {
-            return BatteryAssert.formatMismatch( super.getMessage(), fExpected, fActual );
-        }
-
-        int end = Math.min( fExpected.length(), fActual.length() );
-
-        int i = 0;
-        for ( ; i < end; i++ )
-        {
-            if ( fExpected.charAt( i ) != fActual.charAt( i ) )
-            {
-                break;
-            }
-        }
-        int j = fExpected.length() - 1;
-        int k = fActual.length() - 1;
-        for ( ; k >= i && j >= i; k--, j-- )
-        {
-            if ( fExpected.charAt( j ) != fActual.charAt( k ) )
-            {
-                break;
-            }
-        }
-        String actual, expected;
-
-        // equal strings
-        if ( j < i && k < i )
-        {
             expected = fExpected;
             actual = fActual;
         }
         else
         {
-            expected = fExpected.substring( i, j + 1 );
-            actual = fActual.substring( i, k + 1 );
-            if ( i <= end && i > 0 )
+            int end = Math.min( fExpected.length(), fActual.length() );
+
+            int i = 0;
+            for ( ; i < end; i++ )
+            {
+                if ( fExpected.charAt( i ) != fActual.charAt( i ) )
+                {
+                    break;
+                }
+            }
+            int j = fExpected.length() - 1;
+            int k = fActual.length() - 1;
+            for ( ; k >= i && j >= i; k--, j-- )
             {
-                expected = "..." + expected;
-                actual = "..." + actual;
+                if ( fExpected.charAt( j ) != fActual.charAt( k ) )
+                {
+                    break;
+                }
             }
 
-            if ( j < fExpected.length() - 1 )
+            // equal strings
+            if ( j < i && k < i )
             {
-                expected = expected + "...";
+                expected = fExpected;
+                actual = fActual;
             }
-            if ( k < fActual.length() - 1 )
+            else
             {
-                actual = actual + "...";
+                expected = fExpected.substring( i, j + 1 );
+                actual = fActual.substring( i, k + 1 );
+                if ( i <= end && i > 0 )
+                {
+                    expected = "..." + expected;
+                    actual = "..." + actual;
+                }
+
+                if ( j < fExpected.length() - 1 )
+                {
+                    expected = expected + "...";
+                }
+                if ( k < fActual.length() - 1 )
+                {
+                    actual = actual + "...";
+                }
             }
         }
         return BatteryAssert.formatMismatch( super.getMessage(), expected, actual );

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryTestFailedException.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryTestFailedException.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryTestFailedException.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/assertion/BatteryTestFailedException.java Tue Feb 28 19:29:10 2006
@@ -24,18 +24,11 @@
 public class BatteryTestFailedException
     extends RuntimeException
 {
-
-    private boolean causeInitialized;
-
-    private Throwable cause;
-
     /**
      * Create a <code>TestFailedException</code> with no detail message.
      */
     public BatteryTestFailedException()
     {
-
-        super();
     }
 
     /**
@@ -47,7 +40,6 @@
      */
     public BatteryTestFailedException( String message )
     {
-
         super( message );
     }
 
@@ -65,11 +57,7 @@
      */
     public BatteryTestFailedException( String message, Throwable cause )
     {
-
-        super( message );
-
-        this.cause = cause;
-        causeInitialized = true;
+        super( message, cause );
     }
 
     /**
@@ -79,58 +67,6 @@
      */
     public BatteryTestFailedException( Throwable cause )
     {
-
-        super( cause == null ? "" : cause.toString() );
-
-        this.cause = cause;
-        causeInitialized = true;
-    }
-
-    /**
-     * Returns the cause of this <code>TestFailedException</code>, or <code>null</code> if
-     * the cause is nonexistent or unknown. (The cause is the <code>Throwable</code> that caused
-     * this <code>TestFailedException</code> to get thrown.)
-     */
-    public Throwable getCause()
-    {
-        return cause;
-    }
-
-    /**
-     * Initializes the cause of this <code>TestFailedException</code> to the specified value.
-     * (The cause is the <code>Throwable</code> that caused this <code>TestFailedException</code>
-     * to get thrown.)
-     * <p/>
-     * This method can be called at most once. It is generally called immediately after creating
-     * the <code>TestFailedException</code>. If this <code>TestFailedException</code> was created
-     * with <code>TestFailedException(Throwable)</code> or
-     * <code>TestFailedException(String, Throwable)</code>, this method cannot be called even once.
-     *
-     * @param cause the cause (which is saved for later retrieval by the <code>getCause()</code>
-     *              method). A <code>null</code> value is permitted, and indicates that the cause is
-     *              nonexistent or unknown.)
-     * @throws IllegalArgumentException - if cause is this <code>TestFailedException</code>. (A
-     *                                  <code>TestFailedException</code> cannot be its own cause.)
-     * @throws IllegalStateException    if this <code>TestFailedException</code> was created
-     *                                  with <code>TestFailedException(Throwable)</code> or
-     *                                  <code>TestFailedException(String, Throwable)</code>, or this method has already been
-     *                                  called on this <code>TestFailedException</code>.
-     */
-    public synchronized Throwable initCause( Throwable cause )
-    {
-
-        if ( cause != null && cause == this )
-        {
-            throw new IllegalArgumentException();
-        }
-
-        if ( causeInitialized )
-        {
-            throw new IllegalStateException();
-        }
-
-        this.cause = cause;
-        causeInitialized = true;
-        return this;
+        super( cause == null ? "" : cause.toString(), cause );
     }
 }

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java Tue Feb 28 19:29:10 2006
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import java.io.IOException;
 import java.text.NumberFormat;
 
 /**
@@ -39,6 +40,8 @@
 
     private NumberFormat numberFormat = NumberFormat.getInstance();
 
+    private static final int MS_PER_SEC = 1000;
+
     public void setReportsDirectory( String reportsDirectory )
     {
         this.reportsDirectory = reportsDirectory;
@@ -74,7 +77,7 @@
     }
 
     public void batteryStarting( ReportEntry report )
-        throws Exception
+        throws IOException
     {
     }
 
@@ -153,6 +156,6 @@
 
     protected String elapsedTimeAsString( long runTime )
     {
-        return numberFormat.format( (double) runTime / 1000 );
+        return numberFormat.format( (double) runTime / MS_PER_SEC );
     }
 }

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java Tue Feb 28 19:29:10 2006
@@ -39,7 +39,7 @@
 
     private long batteryStartTime;
 
-    String newLine = System.getProperty( "line.separator" );
+    private static final String NL = System.getProperty( "line.separator" );
 
     public BriefConsoleReporter()
     {
@@ -63,7 +63,6 @@
     }
 
     public void batteryStarting( ReportEntry report )
-        throws Exception
     {
         batteryStartTime = System.currentTimeMillis();
 
@@ -78,13 +77,14 @@
 
         StringBuffer batterySummary = new StringBuffer();
 
-        batterySummary.append( "[surefire] Tests run: " + String.valueOf( this.getNbTests() ) )
-            .append( ", Failures: " + String.valueOf( this.getNbFailures() ) )
-            .append( ", Errors: " + String.valueOf( this.getNbErrors() ) )
-            .append( ", Time elapsed: " + elapsedTimeAsString( runTime ) )
-            .append( " sec" )
-            .append( newLine )
-            .append( "[surefire] " + newLine );
+        batterySummary.append( "[surefire] Tests run: " );
+        batterySummary.append( String.valueOf( this.getNbTests() ) );
+        batterySummary.append( ", Failures: " ).append( String.valueOf( this.getNbFailures() ) );
+        batterySummary.append( ", Errors: " ).append( String.valueOf( this.getNbErrors() ) );
+        batterySummary.append( ", Time elapsed: " ).append( elapsedTimeAsString( runTime ) );
+        batterySummary.append( " sec" );
+        batterySummary.append( NL );
+        batterySummary.append( "[surefire] " ).append( NL );
 
         reportContent = batterySummary.append( reportContent );
 
@@ -103,30 +103,30 @@
     {
         super.testError( report, stdOut, stdErr );
 
-        reportContent.append( "[surefire] " + report.getName() );
+        reportContent.append( "[surefire] " ).append( report.getName() );
 
         long runTime = this.endTime - this.startTime;
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( "  <<< ERROR!" + newLine );
+        reportContent.append( "  <<< ERROR!" ).append( NL );
 
-        reportContent.append( getStackTrace( report ) + newLine );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void testFailed( ReportEntry report, String stdOut, String stdErr )
     {
         super.testFailed( report, stdOut, stdErr );
 
-        reportContent.append( "[surefire] " + report.getName() );
+        reportContent.append( "[surefire] " ).append( report.getName() );
 
         long runTime = this.endTime - this.startTime;
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( "  <<< FAILURE!" + newLine );
+        reportContent.append( "  <<< FAILURE!" ).append( NL );
 
-        reportContent.append( getStackTrace( report ) + newLine );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void dispose()
@@ -140,7 +140,7 @@
 
     private void writeTimeElapsed( long sec )
     {
-        reportContent.append( "  Time elapsed: " + elapsedTimeAsString( sec ) + " sec" );
+        reportContent.append( "  Time elapsed: " ).append( elapsedTimeAsString( sec ) ).append( " sec" );
     }
 
     /**

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java Tue Feb 28 19:29:10 2006
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.io.FileWriter;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 
@@ -36,13 +37,10 @@
 
     private long batteryStartTime;
 
-    public void runStarting( int testCount )
-    {
-
-    }
+    private static final String NL = "\n";
 
     public void batteryStarting( ReportEntry report )
-        throws Exception
+        throws IOException
     {
         batteryStartTime = System.currentTimeMillis();
 
@@ -69,11 +67,11 @@
 
         StringBuffer batterySummary = new StringBuffer();
 
-        batterySummary.append( "Tests run: " + String.valueOf( this.getNbTests() ) )
-            .append( ", Failures: " + String.valueOf( this.getNbFailures() ) )
-            .append( ", Errors: " + String.valueOf( this.getNbErrors() ) )
-            .append( ", Time elapsed: " + elapsedTimeAsString( runTime ) )
-            .append( " sec \n\n" );
+        batterySummary.append( "Tests run: " ).append( String.valueOf( this.getNbTests() ) );
+        batterySummary.append( ", Failures: " ).append( String.valueOf( this.getNbFailures() ) );
+        batterySummary.append( ", Errors: " ).append( String.valueOf( this.getNbErrors() ) );
+        batterySummary.append( ", Time elapsed: " ).append( elapsedTimeAsString( runTime ) );
+        batterySummary.append( " sec \n\n" );
 
         reportContent = batterySummary.append( reportContent );
 
@@ -103,7 +101,7 @@
 
         writeStdLogs( stdOut, stdErr );
 
-        reportContent.append( getStackTrace( report ) + "\n" );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void testFailed( ReportEntry report, String stdOut, String stdErr )
@@ -120,7 +118,7 @@
 
         writeStdLogs( stdOut, stdErr );
 
-        reportContent.append( getStackTrace( report ) + "\n" );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void dispose()
@@ -134,32 +132,32 @@
 
     private void writeTimeElapsed( long sec )
     {
-        reportContent.append( "  Time elapsed: " + elapsedTimeAsString( sec ) + " sec" );
+        reportContent.append( "  Time elapsed: " ).append( elapsedTimeAsString( sec ) ).append( " sec" );
     }
 
     private void writeStdLogs( String stdOut, String stdErr )
     {
-        reportContent.append( "\n" );
+        reportContent.append( NL );
 
-        reportContent.append( "[ stdout ] ---------------------------------------------------------------\n" );
+        reportContent.append( "[ stdout ] ---------------------------------------------------------------" + NL );
 
-        reportContent.append( "\n" );
+        reportContent.append( NL );
 
-        reportContent.append( stdOut + "\n" );
+        reportContent.append( stdOut ).append( NL );
 
-        reportContent.append( "\n" );
+        reportContent.append( NL );
 
-        reportContent.append( "[ stderr ] ---------------------------------------------------------------\n" );
+        reportContent.append( "[ stderr ] ---------------------------------------------------------------" + NL );
 
-        reportContent.append( "\n" );
+        reportContent.append( NL );
 
-        reportContent.append( stdErr + "\n" );
+        reportContent.append( stdErr ).append( NL );
 
-        reportContent.append( "\n" );
+        reportContent.append( NL );
 
-        reportContent.append( "[ stacktrace ] -----------------------------------------------------------\n" );
+        reportContent.append( "[ stacktrace ] -----------------------------------------------------------" + NL );
 
-        reportContent.append( "\n" );
+        reportContent.append( NL );
     }
 
     /**

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java Tue Feb 28 19:29:10 2006
@@ -87,7 +87,6 @@
     // ----------------------------------------------------------------------
 
     public void batteryStarting( ReportEntry report )
-        throws Exception
     {
         batteryStartTime = System.currentTimeMillis();
 

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java Tue Feb 28 19:29:10 2006
@@ -23,6 +23,8 @@
 
 /**
  * Detailed console reporter.
+ * <p/>
+ * TODO: this seems to have a lot in common with other console reporters. Check CPD.
  *
  * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
  * @version $Id$
@@ -38,7 +40,7 @@
 
     private long batteryStartTime;
 
-    String newLine = System.getProperty( "line.separator" );
+    private static final String NL = System.getProperty( "line.separator" );
 
     public DetailedConsoleReporter()
     {
@@ -62,7 +64,6 @@
     }
 
     public void batteryStarting( ReportEntry report )
-        throws Exception
     {
         batteryStartTime = System.currentTimeMillis();
 
@@ -77,13 +78,13 @@
 
         StringBuffer batterySummary = new StringBuffer();
 
-        batterySummary.append( "[surefire] Tests run: " + String.valueOf( this.getNbTests() ) )
-            .append( ", Failures: " + String.valueOf( this.getNbFailures() ) )
-            .append( ", Errors: " + String.valueOf( this.getNbErrors() ) )
-            .append( ", Time elapsed: " + elapsedTimeAsString( runTime ) )
-            .append( " sec" )
-            .append( newLine )
-            .append( "[surefire] " + newLine );
+        batterySummary.append( "[surefire] Tests run: " ).append( String.valueOf( this.getNbTests() ) );
+        batterySummary.append( ", Failures: " ).append( String.valueOf( this.getNbFailures() ) );
+        batterySummary.append( ", Errors: " ).append( String.valueOf( this.getNbErrors() ) );
+        batterySummary.append( ", Time elapsed: " ).append( elapsedTimeAsString( runTime ) );
+        batterySummary.append( " sec" );
+        batterySummary.append( NL );
+        batterySummary.append( "[surefire] " ).append( NL );
 
         reportContent = batterySummary.append( reportContent );
 
@@ -96,7 +97,7 @@
     {
         super.testStarting( report );
 
-        reportContent.append( "[surefire] " + report.getName() );
+        reportContent.append( "[surefire] " ).append( report.getName() );
     }
 
     public void testSucceeded( ReportEntry report )
@@ -107,7 +108,7 @@
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( newLine );
+        reportContent.append( NL );
     }
 
     public void testError( ReportEntry report, String stdOut, String stdErr )
@@ -118,9 +119,9 @@
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( "  <<< ERROR!" + newLine );
+        reportContent.append( "  <<< ERROR!" ).append( NL );
 
-        reportContent.append( getStackTrace( report ) + newLine );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void testFailed( ReportEntry report, String stdOut, String stdErr )
@@ -131,9 +132,9 @@
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( "  <<< FAILURE!" + newLine );
+        reportContent.append( "  <<< FAILURE!" ).append( NL );
 
-        reportContent.append( getStackTrace( report ) + newLine );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void dispose()
@@ -147,7 +148,7 @@
 
     private void writeTimeElapsed( long sec )
     {
-        reportContent.append( "  Time elapsed: " + elapsedTimeAsString( sec ) + " sec" );
+        reportContent.append( "  Time elapsed: " ).append( elapsedTimeAsString( sec ) ).append( " sec" );
     }
 
     /**

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/FileReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/FileReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/FileReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/FileReporter.java Tue Feb 28 19:29:10 2006
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.io.FileWriter;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 
@@ -36,15 +37,10 @@
 
     private long batteryStartTime;
 
-    String newLine = System.getProperty( "line.separator" );
-
-    public void runStarting( int testCount )
-    {
-
-    }
+    private static final String NL = System.getProperty( "line.separator" );
 
     public void batteryStarting( ReportEntry report )
-        throws Exception
+        throws IOException
     {
         batteryStartTime = System.currentTimeMillis();
 
@@ -71,13 +67,13 @@
 
         StringBuffer batterySummary = new StringBuffer();
 
-        batterySummary.append( "Tests run: " + String.valueOf( this.getNbTests() ) )
-            .append( ", Failures: " + String.valueOf( this.getNbFailures() ) )
-            .append( ", Errors: " + String.valueOf( this.getNbErrors() ) )
-            .append( ", Time elapsed: " + elapsedTimeAsString( runTime ) )
-            .append( " sec" )
-            .append( newLine )
-            .append( newLine );
+        batterySummary.append( "Tests run: " ).append( String.valueOf( this.getNbTests() ) );
+        batterySummary.append( ", Failures: " ).append( String.valueOf( this.getNbFailures() ) );
+        batterySummary.append( ", Errors: " ).append( String.valueOf( this.getNbErrors() ) );
+        batterySummary.append( ", Time elapsed: " ).append( elapsedTimeAsString( runTime ) );
+        batterySummary.append( " sec" );
+        batterySummary.append( NL );
+        batterySummary.append( NL );
 
         reportContent = batterySummary.append( reportContent );
 
@@ -103,7 +99,7 @@
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( newLine );
+        reportContent.append( NL );
     }
 
     public void testError( ReportEntry report, String stdOut, String stdErr )
@@ -114,11 +110,11 @@
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( "  <<< ERROR!" + newLine );
+        reportContent.append( "  <<< ERROR!" ).append( NL );
 
         writeStdLogs( stdOut, stdErr );
 
-        reportContent.append( getStackTrace( report ) + newLine );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void testFailed( ReportEntry report, String stdOut, String stdErr )
@@ -129,11 +125,11 @@
 
         writeTimeElapsed( runTime );
 
-        reportContent.append( "  <<< FAILURE!" + newLine );
+        reportContent.append( "  <<< FAILURE!" ).append( NL );
 
         writeStdLogs( stdOut, stdErr );
 
-        reportContent.append( getStackTrace( report ) + newLine );
+        reportContent.append( getStackTrace( report ) ).append( NL );
     }
 
     public void dispose()
@@ -147,32 +143,32 @@
 
     private void writeTimeElapsed( long sec )
     {
-        reportContent.append( "  Time elapsed: " + elapsedTimeAsString( sec ) + " sec" );
+        reportContent.append( "  Time elapsed: " ).append( elapsedTimeAsString( sec ) ).append( " sec" );
     }
 
     private void writeStdLogs( String stdOut, String stdErr )
     {
-        reportContent.append( newLine );
+        reportContent.append( NL );
 
         reportContent.append( "[ stdout ] ---------------------------------------------------------------" );
 
-        reportContent.append( newLine );
+        reportContent.append( NL );
 
-        reportContent.append( stdOut + newLine );
+        reportContent.append( stdOut ).append( NL );
 
-        reportContent.append( newLine );
+        reportContent.append( NL );
 
         reportContent.append( "[ stderr ] ---------------------------------------------------------------" );
 
-        reportContent.append( newLine );
+        reportContent.append( NL );
 
-        reportContent.append( stdErr + newLine );
+        reportContent.append( stdErr ).append( NL );
 
-        reportContent.append( newLine );
+        reportContent.append( NL );
 
         reportContent.append( "[ stacktrace ] -----------------------------------------------------------" );
 
-        reportContent.append( newLine );
+        reportContent.append( NL );
     }
 
     /**

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingReport.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingReport.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingReport.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingReport.java Tue Feb 28 19:29:10 2006
@@ -22,7 +22,7 @@
  */
 public interface ForkingReport
 {
-    static final String FORKING_PREFIX_STANDARD = "@SL";
+    String FORKING_PREFIX_STANDARD = "@SL";
 
-    static final String FORKING_PREFIX_HEADING = "@HL";
+    String FORKING_PREFIX_HEADING = "@HL";
 }

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingSummaryConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingSummaryConsoleReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingSummaryConsoleReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ForkingSummaryConsoleReporter.java Tue Feb 28 19:29:10 2006
@@ -26,7 +26,6 @@
     extends ForkingConsoleReporter
 {
     public void batteryStarting( ReportEntry report )
-        throws Exception
     {
     }
 

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/SummaryConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/SummaryConsoleReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/SummaryConsoleReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/SummaryConsoleReporter.java Tue Feb 28 19:29:10 2006
@@ -26,7 +26,6 @@
     extends ConsoleReporter
 {
     public void batteryStarting( ReportEntry report )
-        throws Exception
     {
     }
 

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java Tue Feb 28 19:29:10 2006
@@ -80,8 +80,9 @@
     public void onTestStart( ITestResult result )
     {
         String rawString = Surefire.getResources().getString( "testStarting" );
+        String group = groupString( result.getMethod().getGroups(), result.getTestClass().getName() );
         ReportEntry report = new ReportEntry( surefire, result.getTestClass().getName() + "#" +
-            result.getMethod().getMethodName(), resultGroup( result ), rawString );
+            result.getMethod().getMethodName(), group, rawString );
 
         reportManager.testStarting( report );
 
@@ -148,11 +149,7 @@
     {
         String rawString = Surefire.getResources().getString( "suiteExecutionStarting" );
 
-        String group = groupString( context.getIncludedGroups() );
-        if ( group == null )
-        {
-            group = context.getName();
-        }
+        String group = groupString( context.getIncludedGroups(), context.getName() );
 
         ReportEntry report = new ReportEntry( surefire, context.getName(), group, rawString );
 
@@ -167,7 +164,7 @@
         String rawString = Surefire.getResources().getString( "suiteCompletedNormally" );
 
         ReportEntry report =
-            new ReportEntry( surefire, context.getName(), groupString( context.getIncludedGroups() ), rawString );
+            new ReportEntry( surefire, context.getName(), groupString( context.getIncludedGroups(), null ), rawString );
 
         reportManager.batteryCompleted( report );
 
@@ -189,45 +186,29 @@
      * form of <pre>"group1,group2,group3"</pre>.
      *
      * @param groups
+     * @param defaultValue
      */
-    public static String groupString( String[] groups )
+    private static String groupString( String[] groups, String defaultValue )
     {
+        String retVal;
         if ( groups != null && groups.length > 0 )
         {
             StringBuffer str = new StringBuffer();
             for ( int i = 0; i < groups.length; i++ )
             {
                 str.append( groups[i] );
-                if ( ( i + 1 ) < groups.length )
+                if ( i + 1 < groups.length )
                 {
                     str.append( "," );
                 }
             }
-            return str.toString();
+            retVal = str.toString();
         }
         else
         {
-            return null;
+            retVal = defaultValue;
         }
+        return retVal;
     }
 
-    /**
-     * Utility to report back with either the test class name
-     * run, or the group(s) method belongs to.
-     *
-     * @param result
-     * @return Valid string
-     */
-    public static String resultGroup( ITestResult result )
-    {
-        String groupStr = groupString( result.getMethod().getGroups() );
-        if ( groupStr != null )
-        {
-            return groupStr;
-        }
-        else
-        {
-            return result.getTestClass().getName();
-        }
-    }
 }

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java Tue Feb 28 19:29:10 2006
@@ -22,10 +22,12 @@
 
 import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.Enumeration;
 import java.util.Properties;
 import java.util.StringTokenizer;
@@ -58,13 +60,8 @@
         return testCase;
     }
 
-    public void runStarting( int testCount )
-    {
-
-    }
-
     public void batteryStarting( ReportEntry report )
-        throws Exception
+        throws FileNotFoundException, UnsupportedEncodingException
     {
         batteryStartTime = System.currentTimeMillis();
 
@@ -174,7 +171,7 @@
 
             String message = t.getMessage();
 
-            if ( ( message != null ) && ( message.trim().length() > 0 ) )
+            if ( message != null && message.trim().length() > 0 )
             {
                 element.setAttribute( "message", message );
 
@@ -188,12 +185,12 @@
 
         element.setValue( stackTrace );
 
-        if ( ( stdOut != null ) && ( stdOut.trim().length() > 0 ) )
+        if ( stdOut != null && stdOut.trim().length() > 0 )
         {
             createElement( testCase, "system-out" ).setValue( stdOut );
         }
 
-        if ( ( stdErr != null ) && ( stdErr.trim().length() > 0 ) )
+        if ( stdErr != null && stdErr.trim().length() > 0 )
         {
             createElement( testCase, "system-err" ).setValue( stdErr );
         }
@@ -245,8 +242,6 @@
     {
         Xpp3Dom properties = createElement( testSuite, "properties" );
 
-        Xpp3Dom property;
-
         Properties systemProperties = System.getProperties();
 
         if ( systemProperties != null )
@@ -264,7 +259,7 @@
                     value = "null";
                 }
 
-                property = createElement( properties, "property" );
+                Xpp3Dom property = createElement( properties, "property" );
 
                 property.setAttribute( "name", key );
 

Modified: maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/util/TeeStream.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/util/TeeStream.java?rev=381892&r1=381891&r2=381892&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/util/TeeStream.java (original)
+++ maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/util/TeeStream.java Tue Feb 28 19:29:10 2006
@@ -25,22 +25,22 @@
 public class TeeStream
     extends PrintStream
 {
-    PrintStream out;
+    private PrintStream tee;
 
     public TeeStream( PrintStream out1, PrintStream out2 )
     {
         super( out1 );
 
-        this.out = out2;
+        this.tee = out2;
     }
 
-    public void write( byte buf[], int off, int len )
+    public void write( byte[] buf, int off, int len )
     {
         try
         {
             super.write( buf, off, len );
 
-            out.write( buf, off, len );
+            tee.write( buf, off, len );
         }
         catch ( Exception e )
         {
@@ -51,14 +51,14 @@
     {
         super.close();
 
-        out.close();
+        tee.close();
     }
 
     public void flush()
     {
         super.flush();
 
-        out.flush();
+        tee.flush();
     }
 }
 



Mime
View raw message