[
https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Igor Vaynberg resolved WICKET-2269.
-----------------------------------
Resolution: Won't Fix
Assignee: Igor Vaynberg
this doesnt make any sense.
your test checks for two things: that the attribute modifier was added and that
it has the correct model, but it checks this by testing the final output. this
is not *unit* testing.
you can break this test down into two tests:
* check that the attribute modifier performs the correct transformation
* check that the correct attribute modifier was added to the component
this will allow you to test things in isolation.
testing the attribute modifier is trivial, instantiate it and call
oncomponenttag() with a mock tag and check that the expectations on the mock
are met.
the other check is also trivia, simply iterate over behaviors and make sure the
right modifier is added to the component.
if you insist on cobbling up all these things into a single test that is fine,
but then you should be checking the output. parse the output html, find the tag
with the wicket id of the component that had the attribute modifier added to it
and check for the correct attribute in the tag.
> A small change would allow WicketTesting attributeModifiers
> -----------------------------------------------------------
>
> Key: WICKET-2269
> URL: https://issues.apache.org/jira/browse/WICKET-2269
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 1.4-RC2
> Reporter: Martin Makundi
> Assignee: Igor Vaynberg
> Original Estimate: 5h
> Remaining Estimate: 5h
>
> The workaround is as follows, because AttributeModifier.getReplaceModel
> -method is protected. This operation should somehow be supported in
> WicketTester:
> Workaround:
> private final static Method getReplaceModelMethod;
> static {
> try {
> getReplaceModelMethod =
> AttributeModifier.class.getDeclaredMethod("getReplaceModel");
> getReplaceModelMethod.setAccessible(true);
> } catch (Exception e) {
> e.printStackTrace();
> throw new RuntimeException(e);
> }
> }
> public void assertAttribute(String message, String expected, Component
> component, String attribute) {
> AttributeModifier behavior = getAttributeModifier(component, attribute);
> if (behavior != null) {
> try {
> IModel<?> model = (IModel<?>) getReplaceModelMethod.invoke(behavior);
> assertEquals(message, expected, model.getObject().toString());
> return;
> } catch (Exception e) {
> throw new RuntimeException(e);
> }
> }
>
> fail("Attribute not found.");
> }
> Usage example:
> assertAttribute("3", tableFooterCellWebMarkupComponent,
> WebPageConstants.COLSPAN);
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.