GenerateMojo extends AbstractMojo { @VisibleForTesting Optional<String> optionalJavaPackage(String line) { if (line.startsWith(PACKAGE_DEFINITION)) { int endOfLine = line.indexOf(";"); if (endOfLine > -1) { String javaPackage = line.substring(PACKAGE_DEFINITION.length(), endOfLine); javaPackage = javaPackage.trim(); return Optional.of(javaPackage); } } return Optional.absent(); } @SuppressWarnings("WeakerAccess")  GenerateMojo(); @VisibleForTesting  GenerateMojo(CliCupInvoker cupInvoker, Log logger); @Override void execute();  }
@Test public void optionalJavaPackage() { assertThat(mojo.optionalJavaPackage("package foo.bar;")).hasValue("foo.bar"); }
@Test public void optionalJavaPackage_spaces() { assertThat(mojo.optionalJavaPackage("package foo.bar ;")).hasValue("foo.bar"); }
@Test public void optionalJavaPackage_noPackage() { assertThat(mojo.optionalJavaPackage("hello world foo.bar;")).isAbsent(); assertThat(mojo.optionalJavaPackage("package foo.bar")).isAbsent(); }