### Question:
DomReadyScript extends AbstractJavaScriptContribution { @Override public void renderHead(Component comp, IHeaderResponse response) { if(this.readyScript != null) { renderDomReady(response, this.readyScript.getObject()); } } DomReadyScript(String readyScript);  DomReadyScript(IModel<String> readyScript); @Override void detach(Component component); @Override void renderHead(Component comp, IHeaderResponse response);  }### Answer:
@Test public void testRenderHead_wasRendered() throws Exception { final String js = "alert('ready!')"; when(this.response.wasRendered(js)).thenReturn(true); mockedDomReadyScript(js).renderHead(null, this.response); verify(this.response).wasRendered(js); verifyNoMoreInteractions(this.response); }
@Test public void testRenderHead_null() throws Exception { mockedDomReadyScript(null).renderHead(null, this.response); verifyNoMoreInteractions(this.response); }
@Test public void testRenderHead_nonAjax() throws Exception { final String js = "alert('ready!')"; when(this.response.wasRendered(js)).thenReturn(false); when(this.request.isAjax()).thenReturn(false); mockedDomReadyScript(js).renderHead(null, this.response); InOrder inOrder = inOrder(this.response); inOrder.verify(this.response).renderJavaScriptReference(this.jquery); inOrder.verify(this.response).renderJavaScript( "jQuery(function(){" + js + ";});", null ); verify(this.response).wasRendered(js); verify(this.response).markRendered(js); verifyNoMoreInteractions(this.response); }
@Test public void testRenderHead_ajax() throws Exception { final String js = "alert('ready!')"; when(this.response.wasRendered(js)).thenReturn(false); when(this.request.isAjax()).thenReturn(true); mockedDomReadyScript(js).renderHead(null, this.response); InOrder inOrder = inOrder(this.response); inOrder.verify(this.response).renderJavaScriptReference(this.jquery); inOrder.verify(this.response).renderOnDomReadyJavaScript(js); verify(this.response).wasRendered(js); verify(this.response).markRendered(js); verifyNoMoreInteractions(this.response); }