Skip to content

Commit

Permalink
fix equals implementation for WrappedTestNGMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
velma authored and krmahadevan committed Apr 28, 2022
1 parent 28d0fd4 commit ec49a13
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public String getQualifiedName() {

@Override
public boolean equals(Object o) {
return testNGMethod.equals(o);
return o == this || (o instanceof ITestNGMethod && testNGMethod.equals(o));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

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

import java.util.ArrayList;
import java.util.List;
import org.testng.IMethodInstance;
import org.testng.ITestResult;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.internal.MethodInstance;
import org.testng.internal.WrappedTestNGMethod;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlSuite.FailurePolicy;
import test.SimpleBaseTest;
import test.aftergroups.issue165.TestclassSampleWithFailedMember;
import test.aftergroups.issue165.TestclassSampleWithSkippedMember;
import test.aftergroups.issue1880.LocalConfigListener;
import test.aftergroups.issue1880.TestClassSample;
import test.aftergroups.samples.AfterGroupsSample;
import test.aftergroups.samples.MultipleGroupsSample;
import test.beforegroups.issue2359.ListenerAdapter;

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

@Test
public void ensureAfterGroupsInvokedWhenTestMethodIsWrappedWithWrappedTestNGMethod() {
TestNG tng = new TestNG();
tng.setTestClasses(new Class[] {AfterGroupsSample.class});

tng.setMethodInterceptor(
(methods, context) -> {
List<IMethodInstance> result = new ArrayList<>(methods);
result.add(new MethodInstance(new WrappedTestNGMethod(result.get(0).getMethod())));
return result;
});

ListenerAdapter adapter = new ListenerAdapter();
tng.addListener(adapter);

tng.run();

assertThat(adapter.getPassedConfiguration()).hasSize(1);
}

private static void runTest(
Class<?> clazz, String groups, boolean shouldContinue, String expected) {
XmlSuite xmlsuite = createXmlSuite("sample_suite", "sample_test", clazz);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test.aftergroups.samples;

import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test;

public class AfterGroupsSample {

@Test(groups = "group-1")
public void someTest() {}

@AfterGroups(groups = "group-1")
public void afterGroupMethod() {}
}

0 comments on commit ec49a13

Please sign in to comment.