-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
testng-core/src/main/java/org/testng/internal/ClassBasedWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.testng.internal; | ||
|
||
import java.util.Objects; | ||
|
||
public final class ClassBasedWrapper<T> { | ||
|
||
private final T object; | ||
|
||
private ClassBasedWrapper(T object) { | ||
this.object = object; | ||
} | ||
|
||
public static <T> ClassBasedWrapper<T> wrap(T object) { | ||
return new ClassBasedWrapper<>(object); | ||
} | ||
|
||
public T unWrap() { | ||
return object; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ClassBasedWrapper<?> wrapper = (ClassBasedWrapper<?>) o; | ||
return object.getClass().equals(wrapper.getClass()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
testng-core/src/test/java/test/listeners/issue2752/ListenerSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package test.listeners.issue2752; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.testng.IClassListener; | ||
import org.testng.ITestClass; | ||
import org.testng.ITestContext; | ||
import org.testng.ITestListener; | ||
import org.testng.ITestResult; | ||
|
||
public class ListenerSample implements IClassListener, ITestListener { | ||
|
||
private static final Map<String, List<String>> logs = new ConcurrentHashMap<>(); | ||
|
||
public ListenerSample() { | ||
logs.clear(); | ||
} | ||
|
||
public static Map<String, List<String>> getLogs() { | ||
return logs; | ||
} | ||
|
||
@Override | ||
public void onBeforeClass(ITestClass testClass) { | ||
String key = testClass.getXmlTest().getName(); | ||
logs.computeIfAbsent(key, k -> new ArrayList<>()).add("onBeforeClass"); | ||
} | ||
|
||
@Override | ||
public void onAfterClass(ITestClass testClass) { | ||
String key = testClass.getXmlTest().getName(); | ||
logs.computeIfAbsent(key, k -> new ArrayList<>()).add("onAfterClass"); | ||
} | ||
|
||
@Override | ||
public void onTestStart(ITestResult result) { | ||
String key = result.getTestContext().getName(); | ||
logs.computeIfAbsent(key, k -> new ArrayList<>()).add("onTestStart"); | ||
} | ||
|
||
@Override | ||
public void onTestSuccess(ITestResult result) { | ||
String key = result.getTestContext().getName(); | ||
logs.computeIfAbsent(key, k -> new ArrayList<>()).add("onTestSuccess"); | ||
} | ||
|
||
@Override | ||
public void onFinish(ITestContext context) { | ||
String key = context.getName(); | ||
logs.computeIfAbsent(key, k -> new ArrayList<>()).add("onFinish"); | ||
} | ||
|
||
@Override | ||
public void onStart(ITestContext context) { | ||
String key = context.getName(); | ||
logs.computeIfAbsent(key, k -> new ArrayList<>()).add("onStart"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
testng-core/src/test/java/test/listeners/issue2752/TestClassSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package test.listeners.issue2752; | ||
|
||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners(ListenerSample.class) | ||
public class TestClassSample { | ||
|
||
@Test | ||
public void testMethod() {} | ||
|
||
@BeforeClass | ||
public void beforeClass() {} | ||
} |