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


The following commit(s) were added to refs/heads/master by this push:
     new 3a81b5d2c Extract exclusion logic from MatrixTestSuiteBuilder into 
MatrixTestFilters
3a81b5d2c is described below

commit 3a81b5d2c5b80bd208f1b353f02e4e9ac983392e
Author: Andreas Veithen-Knowles <[email protected]>
AuthorDate: Sat Feb 28 20:56:04 2026 +0000

    Extract exclusion logic from MatrixTestSuiteBuilder into MatrixTestFilters
    
    Introduce MatrixTestFilters, an immutable BiPredicate that matches test
    cases by class and/or LDAP filter expressions on test parameters. The
    class follows the builder conventions from ADR 0002.
    
    MatrixTestSuiteBuilder now delegates to MatrixTestFilters instead of
    maintaining its own Exclude inner class.
---
 .../axiom/testutils/suite/MatrixTestFilters.java   | 101 +++++++++++++++++++++
 .../testutils/suite/MatrixTestSuiteBuilder.java    |  45 ++-------
 2 files changed, 109 insertions(+), 37 deletions(-)

diff --git 
a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/MatrixTestFilters.java
 
b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/MatrixTestFilters.java
new file mode 100644
index 000000000..9468f5dc9
--- /dev/null
+++ 
b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/MatrixTestFilters.java
@@ -0,0 +1,101 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.function.BiPredicate;
+
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ * An immutable set of filters that match matrix test cases by class and/or 
LDAP filter expressions
+ * on test parameters. Implements {@link BiPredicate} where {@link #test} 
returns {@code true} if
+ * the given test class and parameters match any of the configured filters.
+ */
+public final class MatrixTestFilters implements BiPredicate<Class<?>, 
Dictionary<String, String>> {
+    private static class Entry {
+        private final Class<?> testClass;
+        private final Filter filter;
+
+        Entry(Class<?> testClass, Filter filter) {
+            this.testClass = testClass;
+            this.filter = filter;
+        }
+
+        boolean matches(Class<?> clazz, Dictionary<String, String> parameters) 
{
+            return (testClass == null || clazz.equals(testClass))
+                    && (filter == null || filter.match(parameters));
+        }
+    }
+
+    public static final class Builder {
+        private final List<Entry> entries = new ArrayList<>();
+
+        private Builder() {}
+
+        public Builder add(Class<?> testClass, String filter) {
+            try {
+                entries.add(
+                        new Entry(
+                                testClass,
+                                filter == null ? null : 
FrameworkUtil.createFilter(filter)));
+            } catch (InvalidSyntaxException ex) {
+                throw new IllegalArgumentException("Invalid filter 
expression", ex);
+            }
+            return this;
+        }
+
+        public Builder add(Class<?> testClass) {
+            return add(testClass, null);
+        }
+
+        public Builder add(String filter) {
+            return add(null, filter);
+        }
+
+        public MatrixTestFilters build() {
+            return new MatrixTestFilters(entries);
+        }
+    }
+
+    private final List<Entry> entries;
+
+    private MatrixTestFilters(List<Entry> entries) {
+        this.entries = Collections.unmodifiableList(new ArrayList<>(entries));
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    @Override
+    public boolean test(Class<?> testClass, Dictionary<String, String> 
parameters) {
+        for (Entry entry : entries) {
+            if (entry.matches(testClass, parameters)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
diff --git 
a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/MatrixTestSuiteBuilder.java
 
b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/MatrixTestSuiteBuilder.java
index a43ef9f02..4ca84af81 100644
--- 
a/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/MatrixTestSuiteBuilder.java
+++ 
b/testing/matrix-testsuite/src/main/java/org/apache/axiom/testutils/suite/MatrixTestSuiteBuilder.java
@@ -18,15 +18,8 @@
  */
 package org.apache.axiom.testutils.suite;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import junit.framework.TestSuite;
 
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-
 /**
  * Builds a matrix test suite. This is an abstract class. Subclasses are 
expected to implement the
  * {@link #addTests()} method to generate a set of {@link MatrixTestCase} 
instances. For each type
@@ -34,56 +27,34 @@ import org.osgi.framework.InvalidSyntaxException;
  * parameter values. The resulting set can then be filtered using LDAP filter 
expressions.
  */
 public abstract class MatrixTestSuiteBuilder {
-    private static class Exclude {
-        private final Class<? extends MatrixTestCase> testClass;
-        private final Filter filter;
-
-        public Exclude(Class<? extends MatrixTestCase> testClass, Filter 
filter) {
-            this.testClass = testClass;
-            this.filter = filter;
-        }
-
-        public boolean accept(MatrixTestCase test) {
-            return (testClass == null || test.getClass().equals(testClass))
-                    && (filter == null || 
filter.match(test.getTestParameters()));
-        }
-    }
-
-    private final List<Exclude> excludes = new ArrayList<>();
+    private final MatrixTestFilters.Builder excludesBuilder = 
MatrixTestFilters.builder();
+    private MatrixTestFilters excludes;
     private TestSuite suite;
 
     public final void exclude(Class<? extends MatrixTestCase> testClass, 
String filter) {
-        try {
-            excludes.add(
-                    new Exclude(
-                            testClass, filter == null ? null : 
FrameworkUtil.createFilter(filter)));
-        } catch (InvalidSyntaxException ex) {
-            throw new IllegalArgumentException("Invalid filter expression", 
ex);
-        }
+        excludesBuilder.add(testClass, filter);
     }
 
     public final void exclude(Class<? extends MatrixTestCase> testClass) {
-        exclude(testClass, null);
+        excludesBuilder.add(testClass);
     }
 
     public final void exclude(String filter) {
-        exclude(null, filter);
+        excludesBuilder.add(filter);
     }
 
     protected abstract void addTests();
 
     public final TestSuite build() {
+        excludes = excludesBuilder.build();
         suite = new TestSuite();
         addTests();
         return suite;
     }
 
     protected final void addTest(MatrixTestCase test) {
-        for (Exclude exclude : excludes) {
-            if (exclude.accept(test)) {
-                return;
-            }
+        if (!excludes.test(test.getClass(), test.getTestParameters())) {
+            suite.addTest(test);
         }
-        suite.addTest(test);
     }
 }

Reply via email to