Skip to content

Commit

Permalink
Replace AtomicInteger with int in TestTemplateTestDescriptor.execute()
Browse files Browse the repository at this point in the history
An atomic integer is not really required to count the invocationIndex.
A local int variable should shuffice. Rewrite using java5 for-each and
while loop instead of lambdas to remove the need for an effectively
final mutable number.
  • Loading branch information
gaganis committed Mar 11, 2017
1 parent 0eccc25 commit 6951513
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.jupiter.api.extension.ContainerExtensionContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
Expand Down Expand Up @@ -90,16 +89,17 @@ public JupiterEngineExecutionContext execute(JupiterEngineExecutionContext conte
ContainerExtensionContext containerExtensionContext = (ContainerExtensionContext) context.getExtensionContext();
List<TestTemplateInvocationContextProvider> providers = validateProviders(containerExtensionContext,
context.getExtensionRegistry());
AtomicInteger invocationIndex = new AtomicInteger();
providers.forEach(provider -> {
int invocationIndex = 0;
for (TestTemplateInvocationContextProvider provider : providers) {
Iterator<TestTemplateInvocationContext> contextIterator = provider.provide(containerExtensionContext);
contextIterator.forEachRemaining(invocationContext -> {
int index = invocationIndex.incrementAndGet();
while (contextIterator.hasNext()) {
TestTemplateInvocationContext invocationContext = contextIterator.next();
int index = ++invocationIndex;
TestDescriptor invocationTestDescriptor = createInvocationTestDescriptor(invocationContext, index);
addChild(invocationTestDescriptor);
dynamicTestExecutor.execute(invocationTestDescriptor);
});
});
}
}
validateWasAtLeastInvokedOnce(invocationIndex);
return context;
}
Expand All @@ -126,8 +126,8 @@ private TestDescriptor createInvocationTestDescriptor(TestTemplateInvocationCont
invocationContext, index);
}

private void validateWasAtLeastInvokedOnce(AtomicInteger invocationIndex) {
if (invocationIndex.get() == 0) {
private void validateWasAtLeastInvokedOnce(int invocationIndex) {
if (invocationIndex == 0) {
throw new TestAbortedException("No supporting "
+ TestTemplateInvocationContextProvider.class.getSimpleName() + " provided an invocation context");
}
Expand Down

0 comments on commit 6951513

Please sign in to comment.