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

bitstorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new e24eaba42e Let the negative WicketTester tests fail (#1883)
e24eaba42e is described below

commit e24eaba42e0f2164378c541f59d1f178fbadf876
Author: Sharang Gupta <[email protected]>
AuthorDate: Mon Nov 16 10:16:09 2026 +0000

    Let the negative WicketTester tests fail (#1883)
    
    Eight negative checks in TesterTest, WicketTesterTest and AutoLabelTest
    called fail() inside a try whose catch (AssertionError) swallowed it,
    and a ninth had no fail() at all. They passed whether or not the tester
    assertion failed. They now use assertThrows, so a tester assertion
    that wrongly passes fails the test.
---
 .../test/java/org/apache/wicket/TesterTest.java    | 16 ++-----
 .../wicket/core/util/tester/WicketTesterTest.java  | 51 +++++-----------------
 .../wicket/markup/html/form/AutoLabelTest.java     | 43 ++++++------------
 3 files changed, 29 insertions(+), 81 deletions(-)

diff --git a/wicket-core-tests/src/test/java/org/apache/wicket/TesterTest.java 
b/wicket-core-tests/src/test/java/org/apache/wicket/TesterTest.java
index 64bc26ff67..378673b295 100644
--- a/wicket-core-tests/src/test/java/org/apache/wicket/TesterTest.java
+++ b/wicket-core-tests/src/test/java/org/apache/wicket/TesterTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.wicket;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.markup.html.basic.Label;
@@ -36,18 +36,8 @@ class TesterTest extends WicketTestCase
        {
                tester.startPage(new MyPage());
                tester.debugComponentTrees();
-               try
-               {
-                       tester.assertVisible("label");
-                       fail("Should fail, because label is invisible");
-               }
-               catch (AssertionError e)
-               {
-               }
-               catch (NullPointerException e)
-               {
-                       fail("NullPointerException shouldn't be thrown, instead 
it must fail.");
-               }
+               assertThrows(AssertionError.class, () -> 
tester.assertVisible("label"),
+                       "Should fail, because label is invisible");
        }
 
        private static class MyPage extends WebPage
diff --git 
a/wicket-core-tests/src/test/java/org/apache/wicket/core/util/tester/WicketTesterTest.java
 
b/wicket-core-tests/src/test/java/org/apache/wicket/core/util/tester/WicketTesterTest.java
index c6a73a6afe..f08e54f5ed 100644
--- 
a/wicket-core-tests/src/test/java/org/apache/wicket/core/util/tester/WicketTesterTest.java
+++ 
b/wicket-core-tests/src/test/java/org/apache/wicket/core/util/tester/WicketTesterTest.java
@@ -22,7 +22,6 @@ import static 
org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import java.util.List;
 import java.util.Locale;
@@ -298,15 +297,9 @@ class WicketTesterTest extends WicketTestCase
 
                
tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass")
                        .setEnabled(false);
-               try
-               {
-                       
tester.assertEnabled("ajaxLinkWithSetResponsePageClass");
-                       fail("The link must not be enabled.");
-               }
-               catch (AssertionError ex)
-               {
-
-               }
+               assertThrows(AssertionError.class,
+                       () -> 
tester.assertEnabled("ajaxLinkWithSetResponsePageClass"),
+                       "The link must not be enabled.");
        }
 
        /**
@@ -322,15 +315,9 @@ class WicketTesterTest extends WicketTestCase
 
                
tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass")
                        .setEnabled(true);
-               try
-               {
-                       
tester.assertDisabled("ajaxLinkWithSetResponsePageClass");
-                       fail("The link must not be disabled.");
-               }
-               catch (AssertionError ex)
-               {
-
-               }
+               assertThrows(AssertionError.class,
+                       () -> 
tester.assertDisabled("ajaxLinkWithSetResponsePageClass"),
+                       "The link must not be disabled.");
        }
 
        /**
@@ -349,27 +336,13 @@ class WicketTesterTest extends WicketTestCase
 
                FormComponent<?> bookId = (FormComponent<?>)tester
                        .getComponentFromLastRenderedPage("createForm:id");
-               try
-               {
-                       // test #2: set it manually to not required
-                       bookId.setRequired(false);
-                       tester.assertRequired("createForm:id");
-                       fail("Book ID component must not be required anymore!");
-               }
-               catch (AssertionError ex)
-               {
-
-               }
+               // test #2: set it manually to not required
+               bookId.setRequired(false);
+               assertThrows(AssertionError.class, () -> 
tester.assertRequired("createForm:id"),
+                       "Book ID component must not be required anymore!");
 
-               try
-               {
-                       // test #3: "createForm" is not a FormComponent
-                       tester.assertRequired("createForm");
-               }
-               catch (AssertionError ex)
-               {
-
-               }
+               // test #3: "createForm" is not a FormComponent
+               assertThrows(AssertionError.class, () -> 
tester.assertRequired("createForm"));
        }
 
        /**
diff --git 
a/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/AutoLabelTest.java
 
b/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/AutoLabelTest.java
index 7880c21f15..0edf2e62b1 100644
--- 
a/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/AutoLabelTest.java
+++ 
b/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/AutoLabelTest.java
@@ -18,8 +18,8 @@ package org.apache.wicket.markup.html.form;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import org.apache.wicket.Page;
 import org.apache.wicket.ajax.AjaxRequestTarget;
@@ -221,25 +221,13 @@ class AutoLabelTest extends WicketTestCase
        @Test
        void 
labelTagClassesAreNotUpdatedWhenRelatedFormComponentIsUpdatedExplicitAutoAttributeIsSetToFalse()
        {
-               try {
-                       
labelTagClassesAreUpdatedWhenRelatedFormComponentIsUpdated("<label 
wicket:for='t' wicket:auto='false'><span 
class='label-text'>field</span></label>");
-                       fail("Auto-label auto refresh should fave failed");
-               } catch (AssertionError e) {
-                       // ok
-               }
-
+               assertAutoLabelIsNotRefreshed("<label wicket:for='t' 
wicket:auto='false'><span class='label-text'>field</span></label>");
        }
 
        @Test
        void 
labelTagClassesAreNotUpdatedWhenRelatedFormComponentIsUpdatedWhenNoAutoAttributeIsSet()
        {
-               try
-               {
-                       
labelTagClassesAreUpdatedWhenRelatedFormComponentIsUpdated("<label 
wicket:for='t'><span class='label-text'>field</span></label>");
-                       fail("Auto-label auto refresh should fave failed");
-               } catch (AssertionError e) {
-                       // ok
-               }
+               assertAutoLabelIsNotRefreshed("<label wicket:for='t'><span 
class='label-text'>field</span></label>");
        }
 
        @Test
@@ -252,21 +240,18 @@ class AutoLabelTest extends WicketTestCase
        @Test
        void 
labelTagClassesAreNotUpdatedWhenRelatedFormComponentIsUpdatedWhenRelatedMarkupSettingsIsSetToFalseOrNotSet()
        {
-               try {
-                       // updateAutoLabelsTogetherWithFormComponent is set to 
false by default
-                       
labelTagClassesAreUpdatedWhenRelatedFormComponentIsUpdated("<label 
wicket:for='t'><span class='label-text'>field</span></label>");
-                       fail("Auto-label auto refresh should fave failed");
-               } catch (AssertionError e) {
-                       //ok.
-               }
+               // updateAutoLabelsTogetherWithFormComponent is set to false by 
default
+               assertAutoLabelIsNotRefreshed("<label wicket:for='t'><span 
class='label-text'>field</span></label>");
 
-               try {
-                       
tester.getApplication().getMarkupSettings().setUpdateAutoLabelsTogetherWithFormComponent(false);
-                       
labelTagClassesAreUpdatedWhenRelatedFormComponentIsUpdated("<label 
wicket:for='t'><span class='label-text'>field</span></label>");
-                       fail("Auto-label auto refresh should fave failed");
-               } catch (AssertionError e) {
-                       // ok
-               }
+               
tester.getApplication().getMarkupSettings().setUpdateAutoLabelsTogetherWithFormComponent(false);
+               assertAutoLabelIsNotRefreshed("<label wicket:for='t'><span 
class='label-text'>field</span></label>");
+       }
+
+       private void assertAutoLabelIsNotRefreshed(String autoLabelMarkup)
+       {
+               assertThrows(AssertionError.class,
+                       () -> 
labelTagClassesAreUpdatedWhenRelatedFormComponentIsUpdated(autoLabelMarkup),
+                       "Auto-label auto refresh should have failed");
        }
 
        private String toggleString(FormComponent<?> component, String 
cssClass, boolean flag) {

Reply via email to