I'm trying to implement a link with dynamic text in Wicket, with the username as its text. My first thought was to do something like this in the markup:
<a wicket:id="somelink"><wicket:message key="some.key">bla bla</wicket:message></a>
With the properties file looking like this:
some.key=Username is: {0}
And the code:
String username = ...
add(new Link("somelink", new StringResourceModel("some.key", this, null, username)) {
...
});
The problem is that I have no idea how to test that the link's text is being set to the username (in the unit test that is).
I've tried:
- Using
WicketTester
'sassertLabel
method, but it can't cast theLink
to aLabel
- Using the
Link
'sgetModelObject()
method returns the original message (i.e. before formatting the username into it) - Adding an id to the message and accessing it directly through a path, doesn't work since I get the message that this path doesn't exist (can you even give an ID to a
wicket:message
element ?)
Any thoughts ?