Skip to content

Commit

Permalink
Process outer test instances in clientFactoryForContext (#7444)
Browse files Browse the repository at this point in the history
* Process outer test instances in clientFactoryForContext

Make NessieClientResolver.clientFactoryForContext() invoke configuration
callbacks on all test instances (inner as well as outer).
  • Loading branch information
dimas-b authored Aug 29, 2023
1 parent 67c03b5 commit 946d426
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import java.io.Serializable;
import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
Expand Down Expand Up @@ -88,7 +91,16 @@ public Object resolveParameter(
private NessieClientFactory clientFactoryForContext(ExtensionContext extensionContext) {
NessieApiVersion apiVersion = apiVersion(extensionContext);
URI uri = resolvedNessieUri(extensionContext);
Object testInstance = extensionContext.getTestInstance().orElse(null);
List<NessieClientCustomizer> customizers =
extensionContext
.getTestInstances()
.map(
i ->
i.getAllInstances().stream()
.filter(ti -> ti instanceof NessieClientCustomizer)
.map(ti -> (NessieClientCustomizer) ti)
.collect(Collectors.toList()))
.orElse(Collections.emptyList());

Class<? extends HttpResponseFactory> responseFactoryClass =
extensionContext
Expand All @@ -97,8 +109,15 @@ private NessieClientFactory clientFactoryForContext(ExtensionContext extensionCo
.map(NessieClientResponseFactory::value)
.orElse(null);

if (testInstance instanceof NessieClientCustomizer) {
NessieClientCustomizer testCustomizer = (NessieClientCustomizer) testInstance;
if (!customizers.isEmpty()) {
NessieClientCustomizer testCustomizer =
(builder, version) -> {
for (NessieClientCustomizer customizer : customizers) {
builder = customizer.configure(builder, version);
}
return builder;
};

return new ClientFactory(uri, apiVersion, responseFactoryClass) {
@Nonnull
@jakarta.annotation.Nonnull
Expand Down

0 comments on commit 946d426

Please sign in to comment.