### Question:
JavaScriptDependency extends AbstractJavaScriptContribution { @Override public void renderHead(Component comp, IHeaderResponse response) { JavaScriptDependencyLocator locator = settings().getLocator(); DependencyCollection scripts = new DependencyCollection(); if(this.libraryName != null) { locator.findLibraryScripts(this.libraryName, scripts); } else if(this.fileName != null) { locator.findResourceScripts(this.clazz, this.fileName, scripts); } else { locator.findAssociatedScripts(this.clazz, scripts); } renderDependencies(response, scripts, null); } JavaScriptDependency(Class<?> cls);  JavaScriptDependency(String libraryName);  JavaScriptDependency(Class<?> cls, String fileName); @Override void renderHead(Component comp, IHeaderResponse response); static final JavaScriptDependency JQUERY_UI; static final JavaScriptDependency JQUERY; }### Answer:
@Test public void testRenderHead_library() throws Exception { JavaScriptDependency dep = new MockedJavaScriptDependency("library"); DependencyCollection expected = new DependencyCollection(); expected.setCss(this.css); expected.add(this.script1); expected.add(this.script2); expected.add(this.script3); this.locator.setLibraryScripts(expected); dep.renderHead(null, this.response); verify(this.response).renderCSSReference(this.css); InOrder inOrder = inOrder(this.response); inOrder.verify(this.response).renderJavaScriptReference(this.script1); inOrder.verify(this.response).renderJavaScriptReference(this.script2); inOrder.verify(this.response).renderJavaScriptReference(this.script3); verifyNoMoreInteractions(this.response); }
@Test public void testRenderHead_associated() throws Exception { JavaScriptDependency dep = new MockedJavaScriptDependency(getClass()); DependencyCollection expected = new DependencyCollection(); expected.add(this.script1); this.locator.setAssociatedScripts(expected); dep.renderHead(null, this.response); verify(this.response).renderJavaScriptReference(this.script1); verifyNoMoreInteractions(this.response); }
@Test public void testRenderHead_resource() throws Exception { JavaScriptDependency dep = new MockedJavaScriptDependency( getClass(), "file.js" ); DependencyCollection expected = new DependencyCollection(); expected.add(this.script1); this.locator.setResourceScripts(expected); dep.renderHead(null, this.response); verify(this.response).renderJavaScriptReference(this.script1); verifyNoMoreInteractions(this.response); }