Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-880

ObjectFactory no longer works with TestNG 6.5.2

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.12
    • 2.12.1
    • TestNG support
    • None
    • Patch

    Description

      Hello,

      While running test with TestNG + powermock I found the following exception:

      java.lang.reflect.InvocationTargetException
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
              at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
              at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
              at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
              at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
      Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String
              at org.testng.TestNG.configure(TestNG.java:1564)
              at org.apache.maven.surefire.testng.conf.TestNGMapConfigurator.configure(TestNGMapConfigurator.java:95)
              at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:73)
              at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:112)
              at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:115)
              ... 9 more
      

      The following patch corrects the problem:

      Index: pom.xml
      ===================================================================
      --- pom.xml	(revision 1354455)
      +++ pom.xml	(working copy)
      @@ -49,6 +49,10 @@
               <role>Java Developer</role>
             </roles>
           </contributor>
      +    <contributor>
      +      <name>Marvin Froeder</name>
      +      <email>marvin@marvinformatics.com</email>
      +    </contributor>
         </contributors>
       
         <mailingLists>
      
      Property changes on: surefire-grouper
      ___________________________________________________________________
      Added: svn:ignore
         + .classpath
      .project
      .settings
      target
      
      
      Index: surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG652Configurator.java
      ===================================================================
      --- surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG652Configurator.java	(revision 0)
      +++ surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG652Configurator.java	(revision 0)
      @@ -0,0 +1,54 @@
      +package org.apache.maven.surefire.testng.conf;
      +
      +/*
      + * Licensed to the Apache Software Foundation (ASF) under one
      + * or more contributor license agreements.  See the NOTICE file
      + * distributed with this work for additional information
      + * regarding copyright ownership.  The ASF licenses this file
      + * to you under the Apache License, Version 2.0 (the
      + * "License"); you may not use this file except in compliance
      + * with the License.  You may obtain a copy of the License at
      + *
      + *     http://www.apache.org/licenses/LICENSE-2.0
      + *
      + * Unless required by applicable law or agreed to in writing,
      + * software distributed under the License is distributed on an
      + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
      + * KIND, either express or implied.  See the License for the
      + * specific language governing permissions and limitations
      + * under the License.
      + */
      +
      +import java.util.Iterator;
      +import java.util.Map;
      +import java.util.Map.Entry;
      +
      +import org.apache.maven.surefire.testset.TestSetFailedException;
      +
      +/**
      + * TestNG 6.5.2 configurator. Changed objectFactory type to String
      + * 
      + * @author <a href='mailto:marvin[at]marvinformatics[dot]com'>Marvin Froeder</a>
      + */
      +public class TestNG652Configurator
      +    extends TestNGMapConfigurator
      +{
      +
      +    Map getConvertedOptions( Map options )
      +        throws TestSetFailedException
      +    {
      +        Map convertedOptions = super.getConvertedOptions( options );
      +        for ( Iterator iterator = convertedOptions.entrySet().iterator(); iterator.hasNext(); )
      +        {
      +            Entry entry = (Entry) iterator.next();
      +            String key = (String) entry.getKey();
      +            if ( "-objectfactory".equals( key ) )
      +            {
      +                Class value = (Class) entry.getValue();
      +                convertedOptions.put( key, value.getName() );
      +                break;
      +            }
      +        }
      +        return convertedOptions;
      +    }
      +}
      \ No newline at end of file
      Index: surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
      ===================================================================
      --- surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java	(revision 1354455)
      +++ surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java	(working copy)
      @@ -33,6 +33,7 @@
       import org.apache.maven.surefire.testng.conf.Configurator;
       import org.apache.maven.surefire.testng.conf.TestNG4751Configurator;
       import org.apache.maven.surefire.testng.conf.TestNG52Configurator;
      +import org.apache.maven.surefire.testng.conf.TestNG652Configurator;
       import org.apache.maven.surefire.testng.conf.TestNGMapConfigurator;
       import org.apache.maven.surefire.testset.TestSetFailedException;
       import org.apache.maven.surefire.util.NestedRuntimeException;
      @@ -192,11 +193,16 @@
                   {
                       return new TestNG52Configurator();
                   }
      -            range = VersionRange.createFromVersionSpec( "[5.3,)" );
      +            range = VersionRange.createFromVersionSpec( "[5.3,6.4]" );
                   if ( range.containsVersion( version ) )
                   {
                       return new TestNGMapConfigurator();
                   }
      +            range = VersionRange.createFromVersionSpec( "[6.5,)" );
      +            if ( range.containsVersion( version ) )
      +            {
      +                return new TestNG652Configurator();
      +            }
       
                   throw new TestSetFailedException( "Unknown TestNG version " + version );
               }
      Index: surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG652ConfiguratorTest.java
      ===================================================================
      --- surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG652ConfiguratorTest.java	(revision 0)
      +++ surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG652ConfiguratorTest.java	(revision 0)
      @@ -0,0 +1,44 @@
      +package org.apache.maven.surefire.testng.conf;
      +
      +/*
      + * Licensed to the Apache Software Foundation (ASF) under one
      + * or more contributor license agreements.  See the NOTICE file
      + * distributed with this work for additional information
      + * regarding copyright ownership.  The ASF licenses this file
      + * to you under the Apache License, Version 2.0 (the
      + * "License"); you may not use this file except in compliance
      + * with the License.  You may obtain a copy of the License at
      + *
      + *     http://www.apache.org/licenses/LICENSE-2.0
      + *
      + * Unless required by applicable law or agreed to in writing,
      + * software distributed under the License is distributed on an
      + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
      + * KIND, either express or implied.  See the License for the
      + * specific language governing permissions and limitations
      + * under the License.
      + */
      +
      +import junit.framework.TestCase;
      +
      +import java.util.HashMap;
      +import java.util.Map;
      +
      +/**
      + * @author <a href='mailto:marvin[at]marvinformatics[dot]com'>Marvin Froeder</a>
      + */
      +public class TestNG652ConfiguratorTest
      +    extends TestCase
      +{
      +
      +    public void testGetConvertedOptions()
      +        throws Exception
      +    {
      +        TestNGMapConfigurator testNGMapConfigurator = new TestNG652Configurator();
      +        Map raw = new HashMap();
      +        raw.put( "objectfactory", "java.lang.String" );
      +        Map convertedOptions = testNGMapConfigurator.getConvertedOptions( raw );
      +        String objectfactory = (String) convertedOptions.get( "-objectfactory" );
      +        assertNotNull( objectfactory );
      +    }
      +}
      

      Attachments

        Activity

          People

            olamy Olivier Lamy
            velo velo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: