Skip to content

Commit 5cb5dc0

Browse files
authored
Merge pull request #34 from Nordstrom/pr/refine-byte-buddy-transform
Refine Byte Buddy transform to eliminate muddled matching
2 parents c3ce768 + 5bf5b84 commit 5cb5dc0

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ Note that the implementation in this method watcher uses the annotations attache
303303

304304
### Support for Standard JUnit RunListener Providers
305305

306-
As indicated previously, **JUnit Foundation** will automatically attach standard JUnit **RunListener** providers that are declared in the associated **ServiceLoader** provider configuration file (i.e. - **_org.junit.runner.notification.RunListener_**). Declared run listeners are attached to the **RunNotifier** supplied to the `run()` method of JUnit runners. This feature eliminates behavioral differences between the various test execution environments like Maven, Gradle, and native IDE test runners.
306+
As indicated previously, **JUnit Foundation** will automatically attach standard JUnit **`RunListener`** providers that are declared in the associated **`ServiceLoader`** provider configuration file (i.e. - **_org.junit.runner.notification.RunListener_**). Declared run listeners are attached to the **`RunNotifier`** supplied to the `run()` method of JUnit runners. This feature eliminates behavioral differences between the various test execution environments like Maven, Gradle, and native IDE test runners.
307+
308+
**JUnit Foundation** uses this feature internally; notifications sent to **`RunWatcher`** service providers are published by an auto-attached **`RunListener`**. This notification-enhancing run listener, named [RunAnnouncer](https://github.com/Nordstrom/JUnit-Foundation/blob/master/src/main/java/com/nordstrom/automation/junit/RunAnnouncer.java), is registered via the aforementioned [**ServiceLoader** provider configuration file](https://github.com/Nordstrom/JUnit-Foundation/blob/master/src/main/resources/META-INF/services/org.junit.runner.notification.RunListener).
307309

308310
### Support for Parallel Execution
309311

src/main/java/com/nordstrom/automation/junit/LifecycleHooks.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.nordstrom.common.file.PathUtils.ReportsDirectory;
2020

2121
import net.bytebuddy.agent.builder.AgentBuilder;
22-
import net.bytebuddy.description.method.MethodDescription;
2322
import net.bytebuddy.description.method.MethodDescription.SignatureToken;
2423
import net.bytebuddy.description.type.TypeDescription;
2524
import net.bytebuddy.implementation.MethodDelegation;
@@ -74,17 +73,20 @@ public static ClassFileTransformer installTransformer(Instrumentation instrument
7473
SignatureToken runToken = new SignatureToken("run", TypeDescription.VOID, Arrays.asList(runNotifier));
7574

7675
return new AgentBuilder.Default()
77-
.type(hasSuperType(named("org.junit.internal.runners.model.ReflectiveCallable"))
78-
.or(hasSuperType(named("org.junit.runners.model.RunnerScheduler")))
79-
.or(hasSuperType(named("org.junit.runners.BlockJUnit4ClassRunner")))
80-
.or(hasSuperType(named("org.junit.runners.ParentRunner"))))
76+
.type(hasSuperType(named("org.junit.internal.runners.model.ReflectiveCallable")))
8177
.transform((builder, type, classLoader, module) ->
8278
builder.method(named("runReflectiveCall")).intercept(MethodDelegation.to(runReflectiveCall))
83-
.method(named("finished")).intercept(MethodDelegation.to(finished))
84-
.method(named("createTest")).intercept(MethodDelegation.to(createTest))
79+
.implement(Hooked.class))
80+
.type(hasSuperType(named("org.junit.runners.model.RunnerScheduler")))
81+
.transform((builder, type, classLoader, module) ->
82+
builder.method(named("finished")).intercept(MethodDelegation.to(finished))
83+
.implement(Hooked.class))
84+
.type(hasSuperType(named("org.junit.runners.ParentRunner")))
85+
.transform((builder, type, classLoader, module) ->
86+
builder.method(named("createTest")).intercept(MethodDelegation.to(createTest))
8587
.method(named("runChild")).intercept(MethodDelegation.to(runChild))
8688
.method(hasSignature(runToken)).intercept(MethodDelegation.to(run))
87-
.implement(Hooked.class))
89+
.implement(Hooked.class))
8890
.installOn(instrumentation);
8991
}
9092

0 commit comments

Comments
 (0)