ImportsWriter { public static void write(final StringBuilder sb, final HasImports model) { final Imports imports = model.getImports(); if (imports == null) { return; } sb.append(imports.toString()); if (imports.getImports().size() > 0) { sb.append("\n"); } }  static void write(final StringBuilder sb,
                             final HasImports model);  }
@Test public void testNullModel() { final HasImports model = new HasImports() { private Imports imports = null; @Override public Imports getImports() { return imports; } @Override public void setImports(final Imports imports) { } }; final StringBuilder sb = new StringBuilder(); ImportsWriter.write(sb, model); final String drl = sb.toString(); assertNotNull(drl); assertTrue(drl.isEmpty()); }
@Test public void testEmptyModel() { final HasImports model = new HasImports() { private Imports imports = new Imports(); @Override public Imports getImports() { return imports; } @Override public void setImports(final Imports imports) { } }; final StringBuilder sb = new StringBuilder(); ImportsWriter.write(sb, model); final String drl = sb.toString(); assertNotNull(drl); assertTrue(drl.isEmpty()); }
@Test public void testSingleImportModel() { final String expectedDrl = "import java.lang.String;\n\n"; final HasImports model = new HasImports() { private Imports imports = new Imports(); { imports.addImport(new Import("java.lang.String")); } @Override public Imports getImports() { return imports; } @Override public void setImports(final Imports imports) { } }; final StringBuilder sb = new StringBuilder(); ImportsWriter.write(sb, model); final String drl = sb.toString(); assertNotNull(drl); assertEquals(expectedDrl, drl); }
@Test public void testMultipleImportsModel() { final String expectedDrl = "" + "import java.lang.String;\n" + "import java.lang.Double;\n\n"; final HasImports model = new HasImports() { private Imports imports = new Imports(); { imports.addImport(new Import("java.lang.String")); imports.addImport(new Import("java.lang.Double")); } @Override public Imports getImports() { return imports; } @Override public void setImports(final Imports imports) { } }; final StringBuilder sb = new StringBuilder(); ImportsWriter.write(sb, model); final String drl = sb.toString(); assertNotNull(drl); assertEquals(expectedDrl, drl); }