You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/03/02 00:18:59 UTC

[GitHub] [maven-surefire] josephlbarnett commented on a change in pull request #339: [SUREFIRE-1890] Support TestNG 7.4.0

josephlbarnett commented on a change in pull request #339:
URL: https://github.com/apache/maven-surefire/pull/339#discussion_r585149747



##########
File path: surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG740Configurator.java
##########
@@ -0,0 +1,72 @@
+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 org.apache.maven.surefire.api.testset.TestSetFailedException;
+import org.testng.xml.XmlSuite;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import static java.lang.Integer.parseInt;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.PARALLEL_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.THREADCOUNT_PROP;
+
+/**
+ * TestNG 7.4.0 configurator. Changed setParallel type to enum value.
+ * Uses reflection since ParallelMode enum doesn't exist in supported
+ * TestNG 5.x versions.
+ *
+ * @since 3.0.0-M6
+ */
+public class TestNG740Configurator extends TestNG60Configurator
+{
+    @Override
+    public void configure( XmlSuite suite, Map<String, String> options )
+        throws TestSetFailedException
+    {
+        String threadCountAsString = options.get( THREADCOUNT_PROP );
+        int threadCount = threadCountAsString == null ? 1 : parseInt( threadCountAsString );
+        suite.setThreadCount( threadCount );
+
+        String parallel = options.get( PARALLEL_PROP );
+        if ( parallel != null )
+        {
+            try
+            {
+                Class enumClass = Class.forName( "org.testng.xml.XmlSuite$ParallelMode" );
+                Method resolverMethod = enumClass.getMethod( "getValidParallel", String.class );

Review comment:
       ok, I can update this to use `Enum.valueOf()`, restrict the allowable values and update the javadoc.
   Is the `Class.forName` ok to get `enumClass`?  If not, how should this work given the class doesn't exist in TestNG < 6.9.7?
   I can also use `ReflectionUtils` to call the appropriate `setParallel` method instead of raw reflection, is that ok or is there a better way?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org