aryankalantri opened a new pull request, #1978:
URL: https://github.com/apache/wicket/pull/1978

   Fixes #1955.
   
   `WicketTester#executeBehavior(AbstractAjaxBehavior)` needs the behavior 
instance. A behavior added inside the tested component is usually not reachable 
from the test, so the test has to dig it out first:
   
   ```java
   MyPanel panel = tester.startComponentInPage(new MyPanel());
   
panel.getBehaviors(AbstractDefaultAjaxBehavior.class).forEach(tester::executeBehavior);
   ```
   
   ## What changed
   
   New overload `executeBehavior(Component, Class<B extends 
AbstractAjaxBehavior>)` in `BaseWicketTester`.
   
   Scope decision (from the issue): the method takes a **component** and a 
behavior class, not a page-wide search. A page usually has many behaviors of 
the same type on different components, so a page-wide search could not pick 
one. Subtypes of the given type match (`Component#getBehaviors(Class)` uses 
`isInstance`). The test fails with a clear message when the component has no 
behavior of the given type, or more than one (in the latter case it tells the 
caller to execute one of them directly with 
`executeBehavior(AbstractAjaxBehavior)`).
   
   This is new public API, so it has Javadoc and `@since 12.0.0`.
   
   ## How tested
   
   New fixture `ExecuteBehaviorTestPanel`: its link carries a 
`CountingBehavior` (an `AjaxEventBehavior` that increments a counter) added 
inside the panel, so the test never holds the behavior instance. Three new 
tests in `BaseWicketTesterTest`:
   
   - found by type: the behavior executes (counter goes 0 to 1);
   - no behavior of the type: fails with "has no behavior of type";
   - two behaviors of the type: fails with "has 2 behaviors of type".
   
   Results, run locally with a manual `javac` build (JDK 21): 
`BaseWicketTesterTest` 14/14 pass (11 pre-existing + 3 new). All 3 new tests 
fail against unmodified `master` (the overload does not exist there), so they 
exercise the new API.
   
   Tests were run locally with a manual `javac` build because Maven cannot 
download dependencies in this environment: Java TLS through the egress proxy is 
reset, while `curl` works. The full `mvn verify` run is left to CI as arbiter.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to