All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testng.internal.GroupsHelper Maven / Gradle / Ivy

There is a newer version: 7.10.1
Show newest version
package org.testng.internal;

import org.testng.collections.Lists;
import org.testng.collections.Maps;

import java.util.List;
import java.util.Map;

public final class GroupsHelper {

  private GroupsHelper() {
    // Utility class. Defeat instantiation.
  }

  /**
   * Helps create a map of groups (key/value = groupName/groupName) which takes into consideration
   * the included/excluded group in conjunction with a possible group definition that a user may
   * have created via their suite xml file.
   *
   * @param metaGroups Represents a Key/Value pair of dynamically defined groups by the user. For
   *     e.g.,
   *     
   *                                     <groups> 
* <define name="dynamicGroup">
* <include name="regressionMethod"/>
* </define>
* </groups>
*
* * @param groups A {@link List} of groups that are included/excluded in a given <test> * @return a map that represents the computed group names. */ public static Map createGroups( Map> metaGroups, List groups) { Map result = Maps.newHashMap(); // Groups that were passed on the command line for (String group : groups) { result.put(group, group); } if (metaGroups.isEmpty()) { return result; } List unfinishedGroups = Lists.newLinkedList(); collectGroups(groups, unfinishedGroups, metaGroups, result); while (!unfinishedGroups.isEmpty()) { List uGroups = Lists.newLinkedList(unfinishedGroups); unfinishedGroups = Lists.newLinkedList(); collectGroups(uGroups, unfinishedGroups, metaGroups, result); } return result; } private static void collectGroups( List groups, List unfinishedGroups, Map> metaGroups, Map result) { for (String gn : groups) { List subGroups = metaGroups.get(gn); if (subGroups == null) { continue; } for (String sg : subGroups) { if (null == result.get(sg)) { result.put(sg, sg); unfinishedGroups.add(sg); } } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy