10
10
import org .testng .ITestNGMethod ;
11
11
import org .testng .collections .Lists ;
12
12
import org .testng .collections .Maps ;
13
- import org .testng .xml .XmlTest ;
14
13
15
14
public class MethodInheritance {
16
15
@@ -135,12 +134,17 @@ public static void fixMethodInheritance(ITestNGMethod[] methods, boolean before)
135
134
ITestNGMethod m1 = l .get (i );
136
135
for (int j = i + 1 ; j < l .size (); j ++) {
137
136
ITestNGMethod m2 = l .get (j );
138
- boolean groupMode = XmlTest .isGroupBasedExecution (m2 .getXmlTest ());
139
- if (groupMode ) {
140
- // Do not resort to adding implicit depends-on if there are groups
141
- continue ;
142
- }
143
- if (!equalsEffectiveClass (m1 , m2 ) && !dependencyExists (m1 , m2 , methods )) {
137
+ boolean notEffectivelyEqual = !equalsEffectiveClass (m1 , m2 );
138
+ boolean upstreamHierarchy = hasUpstreamHierarchy (m1 , m2 );
139
+ boolean shouldConsider =
140
+ before ? notEffectivelyEqual && upstreamHierarchy : notEffectivelyEqual ;
141
+ boolean hasGroupDependencies =
142
+ m2 .getGroupsDependedUpon ().length == 0
143
+ && m1 .getGroupsDependedUpon ().length == 0 ;
144
+
145
+ if (shouldConsider
146
+ && !dependencyExists (m1 , m2 , methods )
147
+ && hasGroupDependencies ) {
144
148
Utils .log ("MethodInheritance" , 4 , m2 + " DEPENDS ON " + m1 );
145
149
m2 .addMethodDependedUpon (MethodHelper .calculateMethodCanonicalName (m1 ));
146
150
}
@@ -149,6 +153,15 @@ public static void fixMethodInheritance(ITestNGMethod[] methods, boolean before)
149
153
});
150
154
}
151
155
156
+ private static boolean hasUpstreamHierarchy (ITestNGMethod m1 , ITestNGMethod m2 ) {
157
+ Class <?> c1 = m1 .getRealClass ();
158
+ Class <?> c2 = m2 .getRealClass ();
159
+ if (c1 .equals (c2 )) {
160
+ return false ;
161
+ }
162
+ return c1 .isAssignableFrom (c2 );
163
+ }
164
+
152
165
private static boolean dependencyExists (
153
166
ITestNGMethod m1 , ITestNGMethod m2 , ITestNGMethod [] methods ) {
154
167
return internalDependencyExists (m1 , m2 , methods ) || internalDependencyExists (m2 , m1 , methods );
0 commit comments