vendredi 2 septembre 2016

How to mock a Wicket component

I am trying to unittest a wicket panel with the help of WicketTester and Spock/Mockito.

In this panel, a ModalWindow (confirmation dialog) is show in a good case scenario.

I want to validate this dialog will be shown, so I tried to mock the component, inject it into the panel and test if the show method is called. This won't work, as Wicket throws the following error:

java.lang.IllegalStateException: org.apache.wicket.Component has not been properly detached. 
Something in the hierarchy of X has not called super.onDetach() in the override of onDetach() method

It's not suprising a mock can not call the onDetach method on it's super class.

I've tried stubbing the ModalWindow and using a spy to verify if the show method is called, but the implementation of that method has dependencies / external calls that are hard to mock.

Which way should I approach this problem? Or shouldn't I even try to make this kind of test work?

Aucun commentaire:

Enregistrer un commentaire