PackageNameWriter { public static void write(final StringBuilder sb, final HasPackageName model) { final String packageName = model.getPackageName(); if (!(packageName == null || packageName.isEmpty())) { sb.append("package ").append(packageName).append(";\n\n"); } }  static void write(final StringBuilder sb,
                             final HasPackageName model);  }
@Test public void testNullModel() { final HasPackageName model = new HasPackageName() { private String packageName = null; @Override public String getPackageName() { return packageName; } @Override public void setPackageName(final String packageName) { this.packageName = packageName; } }; final StringBuilder sb = new StringBuilder(); PackageNameWriter.write(sb, model); final String drl = sb.toString(); assertNotNull(drl); assertTrue(drl.isEmpty()); }
@Test public void testEmptyModel() { final HasPackageName model = new HasPackageName() { private String packageName = ""; @Override public String getPackageName() { return packageName; } @Override public void setPackageName(final String packageName) { this.packageName = packageName; } }; final StringBuilder sb = new StringBuilder(); PackageNameWriter.write(sb, model); final String drl = sb.toString(); assertNotNull(drl); assertTrue(drl.isEmpty()); }
@Test public void testModel() { final String expectedDrl = "package org.drools.guvnor.models.commons.backend.packages;\n\n"; final HasPackageName model = new HasPackageName() { private String packageName = "org.drools.guvnor.models.commons.backend.packages"; @Override public String getPackageName() { return packageName; } @Override public void setPackageName(final String packageName) { this.packageName = packageName; } }; final StringBuilder sb = new StringBuilder(); PackageNameWriter.write(sb, model); final String drl = sb.toString(); assertNotNull(drl); assertEquals(expectedDrl, drl); }