WebsterMojo extends AbstractMojo { void addTargets(final @NotNull WebsterPlan.Builder builder, final @NotNull Fun.ThrowingBiFunction<File, JsonObject, List<WebsterTarget>> parser) throws MojoFailureException { try { builder.withTargets(parser.tryApply(baseDir, websterTargets)); } catch (Exception e) { throw new MojoFailureException("Failed to parse websterTargets", e); } }  @Override final void execute(); static final String PARAM_REPOSITORY_HOME; static final String PARAM_OAK_RUN_ARGS; static final String PARAM_TMPDIR; }
@Test public void testAddTargets() throws Exception { final File testOutDir = new File(testOutBaseDir, "testAddTargets"); FileUtils.deleteDirectory(testOutDir); testOutDir.mkdirs(); WebsterMojo mojo = newMojo(); mojo.baseDir = new File(testOutDir, "baseDir"); mojo.websterTargets = obj() .key("nodetypes", obj()) .key("privileges", obj()) .get(); final WebsterTarget fakeTarget = mock(WebsterTarget.class); final CompletableFuture<Boolean> performed = new CompletableFuture<>(); doAnswer(call -> performed.complete(true)).when(fakeTarget).perform(any(Session.class)); final WebsterPlan.Builder builder = new WebsterPlan.Builder(); mojo.addTargets(builder, (basedir, config) -> Collections.singletonList(fakeTarget)); final File segmentStore = new File(testOutDir, "segmentstore"); builder.withFixtureProvider(() -> JcrFactory.getReadWriteFixture(segmentStore)); builder.build().perform(); assertTrue("should be performed", performed.getNow(false)); }
@Test(expected = MojoFailureException.class) public void testAddTargets_throws() throws Exception { WebsterMojo mojo = newMojo(); mojo.baseDir = new File("."); mojo.websterTargets = obj().get(); mojo.addTargets(new WebsterPlan.Builder(), (baseDir, targets) -> { throw new IOException("failed yo"); }); }