Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix equals implementation for WrappedTestNGMethod #2755

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}
}