How to mock a Wicket component <p>I am trying to unittest a wicket panel with the help of WicketTester and Spock/Mockito.</p> <p>In this panel, a <code>ModalWindow</code> (confirmation dialog) is show in a good case scenario.</p> <p>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 <code>show</code> method is called. This won't work, as Wicket throws the following error:</p> <pre><code>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 </code></pre> <p>It's not suprising a mock can not call the <code>onDetach</code> method on it's super class.</p> <p>I've tried stubbing the <code>ModalWindow</code> and using a spy to verify if the <code>show</code> method is called, but the implementation of that method has dependencies / external calls that are hard to mock.</p> <p>Which way should I approach this problem? Or shouldn't I even try to make this kind of test work?</p>