Skip to content

Add WicketTester#executeBehavior(Component, Class) (#1955) - #1978

Open
aryankalantri wants to merge 4 commits into
apache:masterfrom
aryankalantri:feat/execute-behavior-by-type-1955
Open

aryankalantri wants to merge 4 commits into
apache:masterfrom
aryankalantri:feat/execute-behavior-by-type-1955

Conversation

@aryankalantri

Copy link
Copy Markdown

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WicketTester#executeBehavior(Class) to run a behavior by its type

1 participant