Skip to content

Commit ec49a13

Browse files
velmakrmahadevan
authored andcommitted
fix equals implementation for WrappedTestNGMethod
1 parent 28d0fd4 commit ec49a13

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

testng-core/src/main/java/org/testng/internal/WrappedTestNGMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public String getQualifiedName() {
366366

367367
@Override
368368
public boolean equals(Object o) {
369-
return testNGMethod.equals(o);
369+
return o == this || (o instanceof ITestNGMethod && testNGMethod.equals(o));
370370
}
371371

372372
@Override

testng-core/src/test/java/test/aftergroups/AfterGroupsBehaviorTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import org.testng.IMethodInstance;
58
import org.testng.ITestResult;
69
import org.testng.TestNG;
710
import org.testng.annotations.DataProvider;
811
import org.testng.annotations.Test;
12+
import org.testng.internal.MethodInstance;
13+
import org.testng.internal.WrappedTestNGMethod;
914
import org.testng.xml.XmlSuite;
1015
import org.testng.xml.XmlSuite.FailurePolicy;
1116
import test.SimpleBaseTest;
1217
import test.aftergroups.issue165.TestclassSampleWithFailedMember;
1318
import test.aftergroups.issue165.TestclassSampleWithSkippedMember;
1419
import test.aftergroups.issue1880.LocalConfigListener;
1520
import test.aftergroups.issue1880.TestClassSample;
21+
import test.aftergroups.samples.AfterGroupsSample;
1622
import test.aftergroups.samples.MultipleGroupsSample;
1723
import test.beforegroups.issue2359.ListenerAdapter;
1824

@@ -54,6 +60,26 @@ public void ensureAfterGroupsInvokedAfterAllTestsWhenMultipleGroupsDefined() {
5460
t -> assertThat(t.getEndMillis()).isLessThanOrEqualTo(afterGroup.getStartMillis()));
5561
}
5662

63+
@Test
64+
public void ensureAfterGroupsInvokedWhenTestMethodIsWrappedWithWrappedTestNGMethod() {
65+
TestNG tng = new TestNG();
66+
tng.setTestClasses(new Class[] {AfterGroupsSample.class});
67+
68+
tng.setMethodInterceptor(
69+
(methods, context) -> {
70+
List<IMethodInstance> result = new ArrayList<>(methods);
71+
result.add(new MethodInstance(new WrappedTestNGMethod(result.get(0).getMethod())));
72+
return result;
73+
});
74+
75+
ListenerAdapter adapter = new ListenerAdapter();
76+
tng.addListener(adapter);
77+
78+
tng.run();
79+
80+
assertThat(adapter.getPassedConfiguration()).hasSize(1);
81+
}
82+
5783
private static void runTest(
5884
Class<?> clazz, String groups, boolean shouldContinue, String expected) {
5985
XmlSuite xmlsuite = createXmlSuite("sample_suite", "sample_test", clazz);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test.aftergroups.samples;
2+
3+
import org.testng.annotations.AfterGroups;
4+
import org.testng.annotations.Test;
5+
6+
public class AfterGroupsSample {
7+
8+
@Test(groups = "group-1")
9+
public void someTest() {}
10+
11+
@AfterGroups(groups = "group-1")
12+
public void afterGroupMethod() {}
13+
}

0 commit comments

Comments
 (0)