Skip to content

Commit 8ff8aa1

Browse files
committed
Add JavaDoc
1 parent cdb46e7 commit 8ff8aa1

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,23 @@ private LifecycleHooks() {
5656
}
5757
}
5858

59-
public static void premain(String args, Instrumentation instrumentation) {
59+
/**
60+
* This is the main entry point for the Java agent used to transform {@code ParentRunner} and
61+
* {@code BlockJUnit4ClassRunner}.
62+
*
63+
* @param agentArgs agent options
64+
* @param instrumentation {@link Instrumentation} object used to transform JUnit core classes
65+
*/
66+
public static void premain(String agentArgs, Instrumentation instrumentation) {
6067
installTransformer(instrumentation);
6168
}
6269

70+
/**
71+
* Install the {@code Byte Buddy} byte code transformations that provide test fine-grained test lifecycle hooks.
72+
*
73+
* @param instrumentation {@link Instrumentation} object used to transform JUnit core classes
74+
* @return The installed class file transformer
75+
*/
6376
public static ClassFileTransformer installTransformer(Instrumentation instrumentation) {
6477
TypeDescription type1 = TypePool.Default.ofClassPath().describe("org.junit.runners.ParentRunner").resolve();
6578
TypeDescription type2 = TypePool.Default.ofClassPath().describe("org.junit.runners.BlockJUnit4ClassRunner").resolve();
@@ -105,6 +118,10 @@ static synchronized JUnitConfig getConfig() {
105118
return config;
106119
}
107120

121+
/**
122+
* This class declares the interceptor for the {@link org.junit.runners.ParentRunner#createTestClass
123+
* createTestClass} method.
124+
*/
108125
@SuppressWarnings("squid:S1118")
109126
public static class CreateTestClass {
110127
static final ServiceLoader<TestClassWatcher> classWatcherLoader;
@@ -114,6 +131,14 @@ public static class CreateTestClass {
114131
classWatcherLoader = ServiceLoader.load(TestClassWatcher.class);
115132
}
116133

134+
/**
135+
* Interceptor for the {@link org.junit.runners.ParentRunner#createTestClass createTestClass} method.
136+
*
137+
* @param runner underlying test runner
138+
* @param proxy callable proxy for the intercepted method
139+
* @return new {@link TestClass} object
140+
* @throws Exception if something goes wrong
141+
*/
117142
public static TestClass intercept(@This Object runner, @SuperCall Callable<?> proxy) throws Exception {
118143
TestClass testClass = (TestClass) proxy.call();
119144
CLASS_TO_RUNNER.put(testClass, runner);
@@ -126,6 +151,9 @@ public static TestClass intercept(@This Object runner, @SuperCall Callable<?> pr
126151
}
127152
}
128153

154+
/**
155+
* This class declares the interceptor for the {@link org.junit.runners.ParentRunner#run run} method.
156+
*/
129157
@SuppressWarnings("squid:S1118")
130158
public static class Run {
131159
static final ServiceLoader<RunListener> runListenerLoader;
@@ -135,6 +163,14 @@ public static class Run {
135163
runListenerLoader = ServiceLoader.load(RunListener.class);
136164
}
137165

166+
/**
167+
* Interceptor for the {@link org.junit.runners.ParentRunner#run run} method.
168+
*
169+
* @param runner underlying test runner
170+
* @param proxy callable proxy for the intercepted method
171+
* @param notifier run notifier through which events are published
172+
* @throws Exception if something goes wrong
173+
*/
138174
public static void intercept(@This Object runner, @SuperCall Callable<?> proxy, @Argument(0) RunNotifier notifier) throws Exception {
139175
if (NOTIFIERS.add(notifier)) {
140176
Description description = invoke(runner, "getDescription");
@@ -210,6 +246,13 @@ public static Object getRunnerFor(TestClass testClass) {
210246
throw new IllegalStateException("No associated runner was for for specified test class");
211247
}
212248

249+
/**
250+
* Get the description of the indicated child object from the runner for the specified test class instance.
251+
*
252+
* @param instance test class instance
253+
* @param child child object
254+
* @return {@link Description} object for the indicated child
255+
*/
213256
public static Description describeChild(Object instance, Object child) {
214257
TestClass testClass = getTestClassFor(instance);
215258
Object runner = getRunnerFor(testClass);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ private MethodInterceptor() {
4949
*/
5050
@RuntimeType
5151
@BindingPriority(1)
52-
public static void intercept(@Origin Class<?> clazz, @Origin Method method, @SuperCall Callable<?> proxy) throws Exception {
52+
public static void intercept(@Origin Class<?> clazz, @Origin Method method, @SuperCall Callable<?> proxy)
53+
throws Exception {
5354
attachWatchers(clazz);
5455

5556
Throwable thrown = null;
@@ -87,8 +88,8 @@ public static void intercept(@Origin Class<?> clazz, @Origin Method method, @Sup
8788
*/
8889
@RuntimeType
8990
@BindingPriority(2)
90-
public static void intercept(@This Object obj, @Origin Method method, @SuperCall Callable<?> proxy) throws Exception
91-
{
91+
public static void intercept(@This Object obj, @Origin Method method, @SuperCall Callable<?> proxy)
92+
throws Exception {
9293
Throwable thrown = null;
9394
FrameworkMethod member = new FrameworkMethod(method);
9495
synchronized(methodWatchers) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
import com.nordstrom.automation.junit.JUnitConfig.JUnitSettings;
1818

19+
/**
20+
* This class provided the utility methods used by the <b>JUnit Foundation</b> automatic retry feature.
21+
*/
1922
public class RetryHandler {
2023

2124
private static final ServiceLoader<JUnitRetryAnalyzer> retryAnalyzerLoader;
@@ -25,6 +28,10 @@ public class RetryHandler {
2528
retryAnalyzerLoader = ServiceLoader.load(JUnitRetryAnalyzer.class);
2629
}
2730

31+
private RetryHandler() {
32+
throw new AssertionError("RetryHandler is a static utility class that cannot be instantiated");
33+
}
34+
2835
/**
2936
* Run the specified method, retrying on failure.
3037
*

0 commit comments

Comments
 (0)