### Question:
SummaryGenerator extends AbstractVelocityGenerator { public void generate(final MavenProject project, final List<Documentation> documentation, final File cssDirectory, final Writer destination) throws MavenReportException { if (project == null) { throw new IllegalArgumentException("Maven project cannot be null."); } if (documentation == null) { throw new IllegalArgumentException("Documentation cannot be null."); } if (cssDirectory == null) { throw new IllegalArgumentException("CSS directory cannot be null."); } if (destination == null) { throw new IllegalArgumentException("Destination writer cannot be null."); } final VelocityContext context = new VelocityContext(); context.put("projectName", project.getName()); context.put("projectVersion", project.getVersion()); context.put("docs", documentation); try { context.put("cssDirectory", cssDirectory.toURI().toURL().toExternalForm()); } catch (final MalformedURLException e) { throw new MavenReportException("Failed to convert CSS directory to URL.", e); } final VelocityEngine engine = getEngine(); try { final Template template = engine.getTemplate("/velocity/script-doc-summary.vm", "utf-8"); template.merge(context, destination); } catch (final Exception e) { throw new MavenReportException("Failed to initialize and merge template.", e); } }  void generate(final MavenProject project, final List<Documentation> documentation, final File cssDirectory,
            final Writer destination);  }### Answer:
@Test public void testGenerate() throws Exception { final String projectName = "a-project-name"; final String projectVersion = "1.374783937467-beta-1"; when(project.getName()).thenReturn(projectName); when(project.getVersion()).thenReturn(projectVersion); final File tempCssDirectory = File.createTempFile("testGenerate", null).getParentFile(); final VelocityContext context = mock(VelocityContext.class); whenNew(VelocityContext.class).withNoArguments().thenReturn(context); final Template template = mock(Template.class); when(engine.getTemplate("/velocity/script-doc-summary.vm", "utf-8")).thenReturn(template); generator.generate(project, documentation, tempCssDirectory, writer); verify(context).put("projectName", projectName); verify(context).put("projectVersion", projectVersion); verify(context).put("docs", documentation); verify(context).put("cssDirectory", tempCssDirectory.toURI().toURL().toExternalForm()); verify(template).merge(context, writer); }
@Test public void testGenerateNullCssDirectory() throws Exception { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { generator.generate(project, documentation, null, writer); }); assertThat(e.getMessage()).isEqualTo("CSS directory cannot be null."); }
@Test public void testGenerateNullDocumentation() throws Exception { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { generator.generate(project, null, cssDirectory, writer); }); assertThat(e.getMessage()).isEqualTo("Documentation cannot be null."); }
@Test public void testGenerateNullProject() throws Exception { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { generator.generate(null, documentation, cssDirectory, writer); }); assertThat(e.getMessage()).isEqualTo("Maven project cannot be null."); }
@Test public void testGenerateNullWriter() throws Exception { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { generator.generate(project, documentation, cssDirectory, null); }); assertThat(e.getMessage()).isEqualTo("Destination writer cannot be null."); }