This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch 
feature/WW-5695-html5-constraint-validation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit ee8c25a340a26460321daa219d9f43a74825991c
Author: Lukasz Lenart <[email protected]>
AuthorDate: Mon Aug 24 23:09:03 2026 +0200

    WW-5695 test(components): make FormFieldValidatorsTest prove memoisation
    
    testRepeatedCallsAreConsistent only compared list sizes across two calls to
    the same field, which a non-memoised implementation would also satisfy since
    resolution is deterministic -- it never observed how many times resolution
    actually ran.
    
    Replace it with a test that mocks ActionValidatorManager and asserts
    getValidators(...) is invoked exactly once across lookups of two different
    fields on the same Form instance, which is the actual behaviour
    getFieldValidators promises. Verified the new test fails (2 invocations
    instead of 1) when the resolveActionValidators() early-return is temporarily
    neutralised, then passes again with it restored.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
---
 .../components/FormFieldValidatorsTest.java        | 23 +++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git 
a/core/src/test/java/org/apache/struts2/components/FormFieldValidatorsTest.java 
b/core/src/test/java/org/apache/struts2/components/FormFieldValidatorsTest.java
index b12df9293..a03dca297 100644
--- 
a/core/src/test/java/org/apache/struts2/components/FormFieldValidatorsTest.java
+++ 
b/core/src/test/java/org/apache/struts2/components/FormFieldValidatorsTest.java
@@ -20,13 +20,22 @@ package org.apache.struts2.components;
 
 import org.apache.struts2.TestConfigurationProvider;
 import org.apache.struts2.mock.MockActionProxy;
+import org.apache.struts2.validator.ActionValidatorManager;
 import org.apache.struts2.validator.Validator;
 import org.apache.struts2.views.jsp.AbstractUITagTest;
 import org.apache.struts2.views.jsp.ui.FormTag;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
 public class FormFieldValidatorsTest extends AbstractUITagTest {
 
     public void testFindsTheFieldsValidators() throws Exception {
@@ -44,11 +53,19 @@ public class FormFieldValidatorsTest extends 
AbstractUITagTest {
         assertTrue(form.getFieldValidators("noSuchField").isEmpty());
     }
 
-    public void testRepeatedCallsAreConsistent() throws Exception {
+    public void testResolvesTheActionsValidatorsOnlyOnceAcrossFields() throws 
Exception {
         Form form = formForDoubleValidationAction();
 
-        assertEquals(form.getFieldValidators("myUpDownSelectTag").size(),
-            form.getFieldValidators("myUpDownSelectTag").size());
+        ActionValidatorManager manager = mock(ActionValidatorManager.class);
+        when(manager.getValidators(any(Class.class), anyString(), 
nullable(String.class)))
+            .thenReturn(Collections.emptyList());
+        form.setActionValidatorManager(manager);
+
+        form.getFieldValidators("myUpDownSelectTag");
+        form.getFieldValidators("someOtherField");
+
+        org.mockito.Mockito.verify(manager, times(1))
+            .getValidators(any(Class.class), anyString(), 
nullable(String.class));
     }
 
     private Form formForDoubleValidationAction() throws Exception {

Reply via email to