11package org .testng .xml ;
22
33import java .util .Collection ;
4+ import java .util .Collections ;
45import java .util .List ;
56import java .util .Locale ;
67import java .util .Map ;
@@ -189,8 +190,6 @@ public String toString() {
189190 public static final Boolean DEFAULT_PRESERVE_ORDER = Boolean .TRUE ;
190191 private Boolean m_preserveOrder = DEFAULT_PRESERVE_ORDER ;
191192
192- private List <String > m_includedGroups = Lists .newArrayList ();
193- private List <String > m_excludedGroups = Lists .newArrayList ();
194193 private XmlMethodSelectors m_xmlMethodSelectors ;
195194 private boolean parsed = false ;
196195
@@ -848,23 +847,39 @@ public List<String> getIncludedGroups() {
848847 } else if (m_xmlGroups != null && (m_xmlGroups .getRun () != null )) {
849848 return m_xmlGroups .getRun ().getIncludes ();
850849 } else {
851- // deprecated
852- return m_includedGroups ;
850+ // deprecated. Use mutable list because there are unit tests which modifies it
851+ return Lists .newArrayList ();
852+ }
853+ }
854+
855+ private void initGroupsRun () {
856+ if (m_xmlGroups == null ) {
857+ m_xmlGroups = new XmlGroups ();
858+ }
859+ if (m_xmlGroups .getRun () == null ) {
860+ m_xmlGroups .setRun (new XmlRun ());
853861 }
854862 }
855863
856864 public void addIncludedGroup (String g ) {
857- m_includedGroups .add (g );
865+ initGroupsRun ();
866+ m_xmlGroups .getRun ().onInclude (g );
858867 }
859868
860869 /** @param g - The list of groups to include. */
861870 public void setIncludedGroups (List <String > g ) {
862- m_includedGroups = g ;
871+ initGroupsRun ();
872+ List <String > includes = m_xmlGroups .getRun ().getIncludes ();
873+ includes .clear ();
874+ includes .addAll (g );
863875 }
864876
865877 /** @param g The excludedGrousps to set. */
866878 public void setExcludedGroups (List <String > g ) {
867- m_excludedGroups = g ;
879+ initGroupsRun ();
880+ List <String > excludes = m_xmlGroups .getRun ().getExcludes ();
881+ excludes .clear ();
882+ excludes .addAll (g );
868883 }
869884
870885 /**
@@ -877,12 +892,13 @@ public List<String> getExcludedGroups() {
877892 } else if (m_xmlGroups != null && (m_xmlGroups .getRun () != null )) {
878893 return m_xmlGroups .getRun ().getExcludes ();
879894 } else {
880- return m_excludedGroups ;
895+ return Collections . emptyList () ;
881896 }
882897 }
883898
884899 public void addExcludedGroup (String g ) {
885- m_excludedGroups .add (g );
900+ initGroupsRun ();
901+ m_xmlGroups .getRun ().onExclude (g );
886902 }
887903
888904 public Boolean getGroupByInstances () {
0 commit comments