AbstractReloadMojo extends AbstractSpeedmentMojo { @Override protected void execute(Speedment speedment) throws MojoExecutionException, MojoFailureException { getLog().info("Saving default configuration from database to '" + configLocation().toAbsolutePath() + "'."); final ConfigFileHelper helper = speedment.getOrThrow(ConfigFileHelper.class); try { helper.setCurrentlyOpenFile(configLocation().toFile()); helper.loadFromDatabaseAndSaveToFile(); } catch (final Exception ex) { final String err = "An error occured while reloading."; getLog().error(err); throw new MojoExecutionException(err, ex); } } protected  AbstractReloadMojo(); protected  AbstractReloadMojo(Consumer<ApplicationBuilder<?, ?>> configurer); String getConfigFile();  }
@Test public void execute() throws Exception { when(mockedMavenProject.getBasedir()).thenReturn(new File("baseDir")); when(mockedSpeedment.getOrThrow(ConfigFileHelper.class)).thenReturn(mockedConfigFileHelper); mojo.setConfigFile(mockedConfigLocation); assertDoesNotThrow(()->mojo.execute(mockedSpeedment)); verify(mockedConfigFileHelper).setCurrentlyOpenFile(Paths.get("baseDir", mockedConfigLocation).toFile()); verify(mockedConfigFileHelper).loadFromDatabaseAndSaveToFile(); }
@Test public void executeException() throws Exception { when(mockedMavenProject.getBasedir()).thenReturn(new File("baseDir")); when(mockedSpeedment.getOrThrow(ConfigFileHelper.class)).thenReturn(mockedConfigFileHelper); doThrow(new RuntimeException("test Exception")).when(mockedConfigFileHelper).loadFromDatabaseAndSaveToFile(); mojo.setConfigFile(mockedConfigLocation); assertThrows(MojoExecutionException.class, () -> mojo.execute(mockedSpeedment)); }