You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by br...@apache.org on 2006/03/01 17:15:31 UTC

svn commit: r382071 - 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-booter/src/main/java/org/apache/maven/surefire/ surefire-prov...

Author: brett
Date: Wed Mar  1 08:15:30 2006
New Revision: 382071

URL: http://svn.apache.org/viewcvs?rev=382071&view=rev
Log:
[MSUREFIRE-23] continue towards getting test ng working. This is not the right location to run the suites from, but its a start

Removed:
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/SurefireUtils.java
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/AbstractTextReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
    maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/pom.xml
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.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=382071&r1=382070&r2=382071&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 Wed Mar  1 08:15:30 2006
@@ -17,11 +17,15 @@
  */
 
 import org.apache.maven.surefire.battery.Battery;
+import org.apache.maven.surefire.battery.JUnitBattery;
 import org.apache.maven.surefire.battery.assertion.BatteryTestFailedException;
 import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.Reporter;
 import org.apache.maven.surefire.report.ReporterManager;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -47,8 +51,6 @@
 
     private String testSourceDirectory;
 
-    private boolean forceTestNG;
-
     private String groups;
 
     private String excludedGroups;
@@ -68,13 +70,13 @@
     public boolean run( List reports, List batteryHolders, ClassLoader classLoader, String reportsDirectory )
         throws Exception
     {
-        return run( reports, batteryHolders, classLoader, reportsDirectory, Boolean.FALSE, null, null, new Integer( 0 ),
-                    Boolean.FALSE, null );
+        return run( reports, batteryHolders, classLoader, reportsDirectory, null, null, new Integer( 0 ), Boolean.FALSE,
+                    null );
     }
 
     public boolean run( List reports, List batteryHolders, ClassLoader classLoader, String reportsDirectory,
-                        Boolean forceTestNG, String groups, String excludedGroups, Integer threadCount,
-                        Boolean parallel, String testSourceDirectory )
+                        String groups, String excludedGroups, Integer threadCount, Boolean parallel,
+                        String testSourceDirectory )
         throws Exception
     {
         if ( reports == null || batteryHolders == null || classLoader == null )
@@ -95,8 +97,6 @@
 
         this.reportsDirectory = reportsDirectory;
 
-        this.forceTestNG = forceTestNG.booleanValue();
-
         this.groups = groups;
 
         this.excludedGroups = excludedGroups;
@@ -125,14 +125,6 @@
 
         reporterManager = new ReporterManager( instantiateReports( reports, classLoader ), reportsDirectory );
 
-/* TODO: new, remove
-        boolean jvm15 = false;
-        if ( System.getProperty( "java.version" ).indexOf( "1.5" ) > -1 )
-        {
-            jvm15 = true;
-        }
-*/
-
         try
         {
             reporterManager.runStarting( 100 );
@@ -170,12 +162,13 @@
                         xbat.execute( reporterManager );
                         nbTests += xbat.getTestCount();
                     }
-                    else */if ( testCount > 0 )
-                {
-                    executeBattery( battery, reporterManager );
+                    else */
+                    if ( testCount > 0 )
+                    {
+                        executeBattery( battery, reporterManager );
 
-                    nbTests += testCount;
-                }
+                        nbTests += testCount;
+                    }
 
                     List list = new ArrayList();
 
@@ -189,65 +182,6 @@
 
                     List subBatteries = instantiateBatteries( list, classLoader );
 
-/* TODO
-                    //Handle testng tests
-                    if ( forceTestNG || isTestNG( subBatteries ) )
-                    {
-                        TestNG testNG = new TestNG();
-                        List classes = new ArrayList();
-                        for ( Iterator j = subBatteries.iterator(); j.hasNext(); )
-                        {
-                            Battery b = (Battery) j.next();
-                            if ( b instanceof TestNGBattery )
-                            {
-                                TestNGBattery tb = (TestNGBattery) b;
-                                classes.add( tb.getTestClass() );
-                                j.remove();
-                            }
-                            else if ( forceTestNG && b instanceof JUnitBattery )
-                            {
-                                JUnitBattery jb = (JUnitBattery) b;
-                                classes.add( jb.getTestClass() );
-                                j.remove();
-                            }
-                        }
-
-                        //configure testng parameters
-                        ClassSuite classSuite = new ClassSuite( groups != null ? groups : "TestNG Suite",
-                                                                Utils.classesToXmlClasses( (Class[]) classes.toArray(
-                                                                    new Class[classes.size()] ) ) );
-                        testNG.setCommandLineSuite( classSuite );
-                        testNG.setOutputDirectory( reportsDirectory );
-                        TestNGReporter testngReporter = new TestNGReporter( reporterManager, this );
-                        testNG.addListener( (ITestListener) testngReporter );
-                        testNG.addListener( (ISuiteListener) testngReporter );
-                        // TODO: bring back when TestNG returns the method
-//                        testNG.setReportResults(false);
-                        testNG.setThreadCount( threadCount );
-                        testNG.setParallel( parallel );
-
-                        if ( groups != null )
-                        {
-                            testNG.setGroups( groups );
-                        }
-                        if ( excludedGroups != null )
-                        {
-                            testNG.setExcludedGroups( excludedGroups );
-                        }
-
-                        //set source path so testng can find javadoc
-                        //annotations if not in 1.5 jvm
-                        if ( !jvm15 && testSourceDirectory != null )
-                        {
-                            testNG.setSourcePath( testSourceDirectory );
-                        }
-
-                        //actually runs all the tests
-                        List result = testNG.runSuitesLocally();
-                        nbTests += result.size();
-                    }
-*/
-
                     //continue normal mode
                     for ( Iterator j = subBatteries.iterator(); j.hasNext(); )
                     {
@@ -271,7 +205,6 @@
 
                         if ( testCount > 0 )
                         {
-
                             executeBattery( b, reporterManager );
 
                             nbTests += testCount;
@@ -309,32 +242,6 @@
     }
 
     /**
-     * Determines if <i>any</i> of the batteries specified
-     * is an instance of {@link TestNGBattery}.
-     *
-     * @param batteries     The batteries to check
-     * @param battery
-     * @param reportManager
-     * @return True, if any of the objects are an instanceof {@link TestNGBattery}
-     *         TODO
-     *         public boolean isTestNG( List batteries )
-     *         {
-     *         if ( batteries.size() > 0 )
-     *         {
-     *         for ( int i = 0; i < batteries.size(); i++ )
-     *         {
-     *         Object obj = batteries.get( i );
-     *         if ( obj instanceof TestNGBattery )
-     *         {
-     *         return true;
-     *         }
-     *         }
-     *         }
-     *         <p/>
-     *         return false;
-     *         }
-     *         <p/>
-     *         /**
      * @throws Exception
      */
     public void executeBattery( Battery battery, ReporterManager reportManager )
@@ -397,7 +304,7 @@
         {
             Object[] holder = (Object[]) batteryHolders.get( i );
 
-            Object battery = SurefireUtils.instantiateBattery( holder, loader );
+            Object battery = instantiateBattery( holder, loader );
 
             if ( battery != null )
             {
@@ -451,5 +358,85 @@
     public static String getResourceString( String key )
     {
         return resources.getString( key );
+    }
+
+    private static Object instantiateBattery( Object[] holder, ClassLoader loader )
+        throws Exception
+    {
+        Class testClass;
+
+        Class batteryClass;
+
+        try
+        {
+            testClass = loader.loadClass( (String) holder[0] );
+
+            batteryClass = loader.loadClass( "org.apache.maven.surefire.battery.Battery" );
+        }
+        catch ( Exception e )
+        {
+            return null;
+        }
+
+        if ( Modifier.isAbstract( testClass.getModifiers() ) )
+        {
+            return null;
+        }
+
+        Object battery = null;
+
+        if ( batteryClass.isAssignableFrom( testClass ) )
+        {
+            if ( holder[1] != null )
+            {
+                Object[] params = (Object[]) holder[1];
+
+                Class[] paramTypes = new Class[params.length];
+
+                for ( int j = 0; j < params.length; j++ )
+                {
+                    paramTypes[j] = params[j].getClass();
+                }
+
+                Constructor constructor = testClass.getConstructor( paramTypes );
+
+                battery = constructor.newInstance( params );
+            }
+            else
+            {
+                battery = testClass.newInstance();
+            }
+        }
+
+        if ( battery == null )
+        {
+            // TODO: this hard coding should be removed. Would be real nice to just use Plexus :)
+            //   We could probably have BatteryFactory instances in each provider that say canInstantiate(), and instantiate()
+
+            try
+            {
+                batteryClass = loader.loadClass( "org.apache.maven.surefire.testng.TestNGBattery" );
+
+                Method m = batteryClass.getMethod( "canInstantiate", new Class[]{Class.class} );
+                Boolean b = (Boolean) m.invoke( null, new Object[]{testClass} );
+                if ( b.booleanValue() )
+                {
+                    Constructor constructor =
+                        batteryClass.getConstructor( new Class[]{Class.class, ClassLoader.class} );
+                    battery = constructor.newInstance( new Object[]{testClass, loader} );
+                }
+            }
+            catch ( ClassNotFoundException e )
+            {
+                // ignore
+            }
+        }
+
+        if ( battery == null )
+        {
+            battery = new JUnitBattery( testClass, loader );
+        }
+
+        return battery;
     }
 }

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=382071&r1=382070&r2=382071&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 Wed Mar  1 08:15:30 2006
@@ -42,7 +42,12 @@
     {
         super.batteryStarting( report );
 
-        writeMessage( "Running " + report.getName() );
+        String message = "Running " + report.getName();
+        if ( !report.getGroup().equals( report.getName() ) )
+        {
+            message = message + " (of " + report.getGroup() + ")";
+        }
+        writeMessage( message );
     }
 
     public void runStarting( int testCount )

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=382071&r1=382070&r2=382071&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 Wed Mar  1 08:15:30 2006
@@ -63,5 +63,7 @@
         writer.flush();
 
         writer.close();
+
+        writer = null;
     }
 }

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=382071&r1=382070&r2=382071&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 Wed Mar  1 08:15:30 2006
@@ -61,9 +61,12 @@
 
     public void writeMessage( String message )
     {
-        writer.println( message );
+        if ( writer != null )
+        {
+            writer.println( message );
 
-        writer.flush();
+            writer.flush();
+        }
     }
 
     public void testSucceeded( ReportEntry report )

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=382071&r1=382070&r2=382071&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 Wed Mar  1 08:15:30 2006
@@ -429,4 +429,9 @@
 
         e.printStackTrace( System.err );
     }
+
+    public String getReportsDirectory()
+    {
+        return reportsDirectory;
+    }
 }

Modified: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java?rev=382071&r1=382070&r2=382071&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java Wed Mar  1 08:15:30 2006
@@ -82,8 +82,6 @@
 
     private boolean debug;
 
-    private boolean forceTestNG;
-
     private String groups;
 
     private String excludedGroups;
@@ -188,11 +186,6 @@
         this.jvm = jvm;
     }
 
-    public void setForceTestNG( boolean forceTestNG )
-    {
-        this.forceTestNG = forceTestNG;
-    }
-
     public void setGroups( String groups )
     {
         this.groups = groups;
@@ -341,15 +334,15 @@
         Object batteryExecutor = batteryExecutorClass.newInstance();
 
         Method run = batteryExecutorClass.getMethod( "run", new Class[]{List.class, List.class, ClassLoader.class,
-            String.class, Boolean.class, String.class, String.class, Integer.class, Boolean.class, String.class} );
+            String.class, String.class, String.class, Integer.class, Boolean.class, String.class} );
 
         ClassLoader oldContextClassLoader = Thread.currentThread() .getContextClassLoader();
 
         Thread.currentThread().setContextClassLoader( surefireClassLoader );
 
         Boolean result = (Boolean) run.invoke( batteryExecutor, new Object[]{reports, batteries, surefireClassLoader,
-            reportsDirectory, new Boolean( forceTestNG ), groups, excludedGroups, new Integer( threadCount ),
-            new Boolean( parallel ), testSourceDirectory} );
+            reportsDirectory, groups, excludedGroups, new Integer( threadCount ),
+            parallel ? Boolean.TRUE : Boolean.FALSE, testSourceDirectory} );
 
         Thread.currentThread().setContextClassLoader( oldContextClassLoader );
 
@@ -526,7 +519,6 @@
             String url = (String) classpathUrls.get( i );
 
             // Exclude the surefire booter
-            // Exclude the surefire booter
             if ( url.indexOf( "surefire-booter" ) > 0 )
             {
                 surefireBooterJar = url;
@@ -550,7 +542,7 @@
 
         p.setProperty( "classpath", cp );
 
-        p.setProperty( "childDelegation", "" + childDelegation );
+        p.setProperty( "childDelegation", String.valueOf( childDelegation ) );
 
         FileOutputStream fos = new FileOutputStream( new File( basedir, CLASSLOADER_PROPERTIES ) );
 
@@ -581,7 +573,7 @@
 
         p.setProperty( "batteryConfig", batteryConfig );
 
-        p.setProperty( "debug", "" + debug );
+        p.setProperty( "debug", String.valueOf( debug ) );
 
         fos = new FileOutputStream( new File( basedir, SUREFIRE_PROPERTIES ) );
 

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/pom.xml
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/pom.xml?rev=382071&r1=382070&r2=382071&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/pom.xml (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/pom.xml Wed Mar  1 08:15:30 2006
@@ -1,5 +1,5 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.apache.maven.surefire</groupId>
@@ -8,18 +8,34 @@
   </parent>
   <artifactId>surefire-testng</artifactId>
   <name>SureFire TestNG Runner</name>
-  <dependencies>
-    <dependency>
-      <groupId>org.testng</groupId>
-      <artifactId>testng</artifactId>
-      <version>4.6.1-SNAPSHOT</version>
-      <classifier>jdk15</classifier>
-    </dependency>
-    <dependency>
-      <groupId>org.testng</groupId>
-      <artifactId>testng</artifactId>
-      <version>4.6.1-SNAPSHOT</version>
-      <classifier>jdk14</classifier>
-    </dependency>
-  </dependencies>
+  <profiles>
+    <profile>
+      <id>jdk14</id>
+      <activation>
+        <jdk>1.4</jdk>
+      </activation>
+      <dependencies>
+        <dependency>
+          <groupId>org.testng</groupId>
+          <artifactId>testng</artifactId>
+          <version>4.6.1-SNAPSHOT</version>
+          <classifier>jdk14</classifier>
+        </dependency>
+      </dependencies>
+    </profile>
+    <profile>
+      <id>jdk15</id>
+      <activation>
+        <jdk>!1.4</jdk>
+      </activation>
+      <dependencies>
+        <dependency>
+          <groupId>org.testng</groupId>
+          <artifactId>testng</artifactId>
+          <version>4.6.1-SNAPSHOT</version>
+          <classifier>jdk15</classifier>
+        </dependency>
+      </dependencies>
+    </profile>
+  </profiles>
 </project>

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.java?rev=382071&r1=382070&r2=382071&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.java Wed Mar  1 08:15:30 2006
@@ -16,11 +16,22 @@
  * limitations under the License.
  */
 
+import org.apache.maven.surefire.Surefire;
 import org.apache.maven.surefire.battery.AbstractBattery;
 import org.apache.maven.surefire.report.ReporterManager;
+import org.testng.ISuiteListener;
+import org.testng.ITestListener;
+import org.testng.TestNG;
+import org.testng.internal.TestNGClassFinder;
+import org.testng.internal.Utils;
+import org.testng.internal.annotations.IAnnotationFinder;
+import org.testng.internal.annotations.JDK14AnnotationFinder;
+import org.testng.internal.annotations.JDK15AnnotationFinder;
+import org.testng.xml.ClassSuite;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Main plugin point for running testng tests within the Surefire runtime
@@ -31,8 +42,11 @@
 public class TestNGBattery
     extends AbstractBattery
 {
+    // TODO: is this needed?
     private Class testClass;
 
+    private static IAnnotationFinder annotationFinder;
+
     /**
      * Creates a new test battery that will process the class being
      * passed in to determine the testing configuration.
@@ -101,6 +115,50 @@
 
     public void execute( ReporterManager reportManager )
     {
+        // TODO: maybe don't execute this for every battery
+
+        TestNG testNG = new TestNG();
+        List classes = new ArrayList();
+
+        String groups = null; // TODO :remove
+
+        //configure testng parameters
+        ClassSuite classSuite = new ClassSuite( groups != null ? groups : "TestNG Suite", Utils.classesToXmlClasses(
+            (Class[]) classes.toArray( new Class[classes.size()] ) ) );
+        testNG.setCommandLineSuite( classSuite );
+        testNG.setOutputDirectory( reportManager.getReportsDirectory() );
+        Surefire surefire = new Surefire(); // TODO: blatently wrong
+        TestNGReporter testngReporter = new TestNGReporter( reportManager, surefire );
+        testNG.addListener( (ITestListener) testngReporter );
+        testNG.addListener( (ISuiteListener) testngReporter );
+        // TODO: bring back when TestNG returns the method
+//                        testNG.setReportResults(false);
+
+        // TODO: maybe this was running junit tests for us so that parallel would work
+//        testNG.setThreadCount( threadCount );
+//        testNG.setParallel( parallel );
+//
+//        if ( groups != null )
+//        {
+//            testNG.setGroups( groups );
+//        }
+//        if ( excludedGroups != null )
+//        {
+//            testNG.setExcludedGroups( excludedGroups );
+//        }
+
+        //set source path so testng can find javadoc
+        //annotations if not in 1.5 jvm
+/* TODO
+        if ( !jvm15 && testSourceDirectory != null )
+        {
+            testNG.setSourcePath( testSourceDirectory );
+        }
+*/
+
+        //actually runs all the tests
+        List result = testNG.runSuitesLocally();
+//        nbTests += result.size(); TODO
     }
 
     public String getBatteryName()
@@ -108,4 +166,34 @@
         return testClass.getName();
     }
 
+    /**
+     * @todo belongs in a factory. This is reflected only.
+     */
+    public static Boolean canInstantiate( Class testClass )
+    {
+        if ( TestNGClassFinder.isTestNGClass( testClass, getAnnotationFinder() ) )
+        {
+            return Boolean.TRUE;
+        }
+        else
+        {
+            return Boolean.FALSE;
+        }
+    }
+
+    public static IAnnotationFinder getAnnotationFinder()
+    {
+        if ( annotationFinder == null )
+        {
+            if ( System.getProperty( "java.version" ).indexOf( "1.5" ) > -1 )
+            {
+                annotationFinder = new JDK15AnnotationFinder();
+            }
+            else
+            {
+                annotationFinder = new JDK14AnnotationFinder();
+            }
+        }
+        return annotationFinder;
+    }
 }