Skip to content

Commit

Permalink
fix: aligns lifecycle calls in JUnit 5 with JUnit 4 behavior (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak authored Feb 23, 2021
1 parent 5995ed3 commit 17963c1
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ public void interceptTestTemplateMethod(Invocation<Void> invocation, ReflectiveI
// run inside arquillian
invocation.proceed();
} else {
RunModeEvent runModeEvent = new RunModeEvent(extensionContext.getRequiredTestInstance(), extensionContext.getRequiredTestMethod());
final JUnitJupiterTestClassLifecycleManager manager = getManager(extensionContext);
manager.getAdaptor().fireCustomLifecycle(runModeEvent);
if (runModeEvent.isRunAsClient()) {
if (isRunAsClient(extensionContext)) {
// Run as client
interceptInvocation(invocationContext, extensionContext);
} else {
Expand All @@ -95,44 +92,44 @@ public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocatio
.ifPresent(ExceptionUtils::throwAsUncheckedException);
}
}

@Override
public void interceptBeforeEachMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
if (isInsideArquillian.test(extensionContext)) {
if (isInsideArquillian.test(extensionContext) || isRunAsClient(extensionContext)) {
invocation.proceed();
} else {
invocation.skip();
}
}

@Override
public void interceptAfterEachMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
if (isInsideArquillian.test(extensionContext)) {
if (isInsideArquillian.test(extensionContext) || isRunAsClient(extensionContext)) {
invocation.proceed();
} else {
invocation.skip();
}
}

@Override
public void interceptBeforeAllMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
if (isInsideArquillian.test(extensionContext)) {
invocation.proceed();
} else {
invocation.skip();
} else {
invocation.proceed();
}
}

@Override
public void interceptAfterAllMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
if (isInsideArquillian.test(extensionContext)) {
invocation.proceed();
} else {
invocation.skip();
} else {
invocation.proceed();
}
}

Expand Down Expand Up @@ -182,4 +179,11 @@ private void populateResults(TestResult result, ExtensionContext context) {
}
}
}

private boolean isRunAsClient(ExtensionContext extensionContext) throws Exception {
RunModeEvent runModeEvent = new RunModeEvent(extensionContext.getRequiredTestInstance(), extensionContext.getRequiredTestMethod());
final JUnitJupiterTestClassLifecycleManager manager = getManager(extensionContext);
manager.getAdaptor().fireCustomLifecycle(runModeEvent);
return runModeEvent.isRunAsClient();
}
}

0 comments on commit 17963c1

Please sign in to comment.