### Question:
GenerateMojo extends AbstractMojo { protected String generateCode(Collection<Table> tables, Template template) { try { VelocityContext context = new VelocityContext(); context.put("package", template.getPackage()); context.put("className", template.getClassName()); context.put("tables", tables); context.put("stringUtils", new databaseadapter.StringUtils()); StringWriter writer = new StringWriter(); Velocity.evaluate(context, writer, "databaseadapter-" + template.getClassName(), new FileReader(template.getSource())); return writer.toString(); } catch (ParseErrorException e) { throw new RuntimeException("unexpected error", e); } catch (MethodInvocationException e) { throw new RuntimeException("unexpected error", e); } catch (ResourceNotFoundException e) { throw new RuntimeException("unexpected error", e); } catch (FileNotFoundException e) { throw new RuntimeException("unexpected error", e); } } GenerateMojo();   GenerateMojo(String driverClass, String url, String username, String password, String schemaPattern, String[] includes, String[] excludes, Template[] templates); void execute();  }### Answer:
@Test public void generateCode_returnsAText() throws MojoExecutionException, IOException { File source = new File(SystemUtils.JAVA_IO_TMPDIR, "my-template.vm"); if (source.exists()) source.delete(); FileUtils.writeStringToFile(source, "package ${package};\n\npublic class ${className} {\n\n}"); Table table = new Table("CDC_CROCIERA"); table.setColumns(Arrays.asList(new Column("NAME", 3, 20, 2, true))); GenerateMojo generateMojo = new GenerateMojo("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@10.0.0.46:1551:ORA10A", "DIPMASTER", "DIPMASTER", "DIPMASTER", new String[]{ "CDC_CROCIERA", "CDC_DEPLOYMENT" }, null, USELESS_TEMPLATES_FOR_TEST_PURPOSE); String code = generateMojo.generateCode(Arrays.asList(table), new Template("testingapp", "DB", source, null)); assertTrue(code.contains("testingapp")); assertTrue(code.contains("DB")); }
@Test public void generateCode_whitASingleTableReturnsATextContainingAFormattedClassname() throws MojoExecutionException, IOException { File source = new File(SystemUtils.JAVA_IO_TMPDIR, "my-template.vm"); if (source.exists()) source.delete(); FileUtils.writeStringToFile(source, "package ${package};\n\npublic class ${className} {\n\n}"); Table table = new Table("CDC_CROCIERA"); table.setColumns(Arrays.asList(new Column("NAME", 3, 20, 2, true))); GenerateMojo generateMojo = new GenerateMojo("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@10.0.0.46:1551:ORA10A", "DIPMASTER", "DIPMASTER", "DIPMASTER", new String[]{ "CDC_CROCIERA", "CDC_DEPLOYMENT" }, null, USELESS_TEMPLATES_FOR_TEST_PURPOSE); String code = generateMojo.generateCode(table, new Template(true , "testingapp", "${tableNameAsCamelCase}Table", source, null)); System.out.println(code); assertTrue(code.contains("CdcCrocieraTable")); }