Timo, Thanks alot for the feedback.
I'm getting close, but am running into a serialization problem with the
mocked IDataProvider (JMock and Mockito).
2 [class=org.apache.wicket.util.tester.DummyPanelPage, path=2]
private java.lang.Object org.apache.wicket.MarkupContainer.children
[class=org.rockcoder.scheduler.accounts.AccountListPanel, path=2:panel]
private java.lang.Object org.apache.wicket.MarkupContainer.children
[class=org.rockcoder.scheduler.accounts.AccountListPanel$$anon$1,
path=2:panel:list]
private final org.apache.wicket.markup.repeater.data.IDataProvider
org.apache.wicket.markup.repeater.data.DataViewBase.dataProvider
[class=$Proxy5]
protected java.lang.reflect.InvocationHandler
java.lang.reflect.Proxy.h [class=org.jmock.lib.JavaReflectionImposteriser$1]
<----- field that is not serializable
I know Wicket likes everything to be serializable so does this mean that
mocking frameworks are not compatible by default?
object tester extends BaseWicketTester(new MyApplication {
override val mode = "test"
})
object AccountsSpecification extends Specification with JMocker {
"given an account provider, the accounts list panel" should {
"display a list of all accounts" in {
accountProvider = mock[IDataProvider[Account]]
expect {
one(accountProvider).iterator(anyInt, anyInt)
one(accountProvider).size
one(accountProvider).detach
}
tester.startPanel(new TestPanelSource {
override def getTestPanel(id: String): Panel = new
AccountListPanel(id, accountProvider)
})
}
}
}
class AccountListPanel(id: String, accounts: IDataProvider[Account]) extends
Panel(id) {
add(new DataView[Account]("list", accounts) {
override def populateItem(item: Item[Account]) {
val account = item.getModelObject
item.add(new Label("id", account.id.toString))
item.add(new Label("name", account.name))
}
})
}
On Sun, Feb 8, 2009 at 3:54 AM, Timo Rantalaiho <[email protected]>wrote:
> On Thu, 05 Feb 2009, Erick Fleming wrote:
> > I'm new to unit testing and just trying to get my feet wet. The actual
> code
> > under test would be a panel that should display some data. I guess I
> don't
> > really care to test wicket's dataview but whether or not my panel is
> > actually displaying the data. Should I mock the IDataProvider and verify
> > that certain methods are called?
>
> Yes, and that their data is fed correctly to the items.
>
> > I'm using Scala, but this is a rough translation of the panel.
>
> Thanks, we all should learn Scala anyway so feel free to
> post in it ;)
>
> > public AccountListPanel(String id, IDataProvider provider) {
>
> Pass in a mock IDataProvider there, and then see that the
> accounts that the mock returns get listed on the page.
>
> for (Account account : accountsSuppliedByMockDataProvider) {
> assertEquals(account, findItemOf(account).getModelObject());
> assertEquals(account.getName(),
> findNameLabelOf(account).getModelObjectAsString());
> }
>
> Or something like that.
>
> If your repeater initialises lazily, you sometimes have to
> call .renderComponent() on it on the test so that its
> children get created. But if it already gets its data on
> when it's first constructed and "started" by WicketTester, it
> should be rendered and the Items should be there.
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oy <URL: http://www.ri.fi/ >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>