You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2026/03/15 19:14:50 UTC
(ws-axiom) 02/02: Make AbstractFanOutNode more flexible
This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
commit c89b2893d981ad8ebd52505986b15fb2eac30ec4
Author: Andreas Veithen-Knowles <an...@gmail.com>
AuthorDate: Sun Mar 15 19:10:58 2026 +0000
Make AbstractFanOutNode more flexible
---
.../axiom/testutils/suite/AbstractFanOutNode.java | 32 +++++-----------------
.../org/apache/axiom/testutils/suite/Binding.java | 25 +++++++++++++++++
.../axiom/testutils/suite/DimensionFanOutNode.java | 2 +-
.../axiom/testutils/suite/ParameterFanOutNode.java | 20 +++++---------
4 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/AbstractFanOutNode.java b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/AbstractFanOutNode.java
index f20d8b44b..ea18396aa 100644
--- a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/AbstractFanOutNode.java
+++ b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/AbstractFanOutNode.java
@@ -28,16 +28,12 @@ import org.junit.jupiter.api.DynamicContainer;
import org.junit.jupiter.api.DynamicNode;
import com.google.common.collect.ImmutableList;
-import com.google.inject.AbstractModule;
import com.google.inject.Injector;
-import com.google.inject.Module;
/**
* Abstract base class for fan-out nodes that iterate over a list of values, creating one {@link
* DynamicContainer} per value. For each value, a child Guice injector is created that binds the
- * value type to the specific instance. The binding is created by {@link
- * #createBindingModule(Object)}, which subclasses may override (e.g. {@link ParameterFanOutNode}
- * adds a {@code @Named} annotation).
+ * value type to the specific instance.
*
* <p>Subclasses define how test parameters (used for display names and LDAP filter matching) are
* extracted from each value:
@@ -54,13 +50,14 @@ import com.google.inject.Module;
* @param <T> the value type
*/
public abstract class AbstractFanOutNode<T> extends MatrixTestNode {
- protected final Class<T> type;
private final ImmutableList<T> values;
+ private final Binding<T> binding;
private final MatrixTestNode child;
- protected AbstractFanOutNode(Class<T> type, ImmutableList<T> values, MatrixTestNode child) {
- this.type = type;
+ protected AbstractFanOutNode(
+ ImmutableList<T> values, Binding<T> binding, MatrixTestNode child) {
this.values = values;
+ this.binding = binding;
this.child = child;
}
@@ -70,22 +67,6 @@ public abstract class AbstractFanOutNode<T> extends MatrixTestNode {
*/
protected abstract Map<String, String> extractParameters(T value);
- /**
- * Creates the Guice module that binds the value for a given fan-out iteration. Subclasses may
- * override this to customise the binding (e.g. adding a binding annotation).
- *
- * @param value the current iteration value
- * @return a module that provides the binding for {@code value}
- */
- protected Module createBindingModule(T value) {
- return new AbstractModule() {
- @Override
- protected void configure() {
- bind(type).toInstance(value);
- }
- };
- }
-
@Override
Stream<DynamicNode> toDynamicNodes(
Injector parentInjector,
@@ -95,7 +76,8 @@ public abstract class AbstractFanOutNode<T> extends MatrixTestNode {
.map(
value -> {
Injector childInjector =
- parentInjector.createChildInjector(createBindingModule(value));
+ parentInjector.createChildInjector(
+ binder -> binding.configure(binder, value));
Map<String, String> parameters = extractParameters(value);
HashMap<String, String> params = new HashMap<>(inheritedParameters);
diff --git a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/Binding.java b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/Binding.java
new file mode 100644
index 000000000..deb65746b
--- /dev/null
+++ b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/Binding.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.testutils.suite;
+
+import com.google.inject.Binder;
+
+public interface Binding<T> {
+ void configure(Binder binder, T value);
+}
diff --git a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/DimensionFanOutNode.java b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/DimensionFanOutNode.java
index 1cecbda3a..8f3edc655 100644
--- a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/DimensionFanOutNode.java
+++ b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/DimensionFanOutNode.java
@@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableList;
public class DimensionFanOutNode<D extends Dimension> extends AbstractFanOutNode<D> {
public DimensionFanOutNode(
Class<D> dimensionType, ImmutableList<D> dimensions, MatrixTestNode child) {
- super(dimensionType, dimensions, child);
+ super(dimensions, (binder, value) -> binder.bind(dimensionType).toInstance(value), child);
}
@Override
diff --git a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/ParameterFanOutNode.java b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/ParameterFanOutNode.java
index a0c0d6127..15fa595d1 100644
--- a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/ParameterFanOutNode.java
+++ b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/ParameterFanOutNode.java
@@ -22,8 +22,6 @@ import java.util.Map;
import java.util.function.Function;
import com.google.common.collect.ImmutableList;
-import com.google.inject.AbstractModule;
-import com.google.inject.Module;
import com.google.inject.name.Names;
/**
@@ -43,21 +41,17 @@ public class ParameterFanOutNode<T> extends AbstractFanOutNode<T> {
String parameterName,
Function<T, String> parameterValueFunction,
MatrixTestNode child) {
- super(type, values, child);
+ super(
+ values,
+ (binder, value) ->
+ binder.bind(type)
+ .annotatedWith(Names.named(parameterName))
+ .toInstance(value),
+ child);
this.parameterName = parameterName;
this.parameterValueFunction = parameterValueFunction;
}
- @Override
- protected Module createBindingModule(T value) {
- return new AbstractModule() {
- @Override
- protected void configure() {
- bind(type).annotatedWith(Names.named(parameterName)).toInstance(value);
- }
- };
- }
-
@Override
protected Map<String, String> extractParameters(T value) {
return Map.of(parameterName, parameterValueFunction.apply(value));