SortMojo extends AbstractParentMojo { public void setup() throws MojoFailureException { new ExceptionConverter(() -> { PluginParameters pluginParameters = PluginParameters.builder() .setPomFile(pomFile) .setFileOutput(createBackupFile, backupFileExtension, null, keepTimestamp) .setEncoding(encoding) .setFormatting(lineSeparator, expandEmptyElements, spaceBeforeCloseEmptyElement, keepBlankLines) .setIndent(nrOfIndentSpace, indentBlankLines) .setSortOrder(sortOrderFile, predefinedSortOrder) .setSortEntities(sortDependencies, sortPlugins, sortProperties, sortModules) .setTriggers(ignoreLineSeparators) .build(); sortPomImpl.setup(new MavenLogger(getLog()), pluginParameters); }).executeAndConvertException(); }  void setup();  }
@Test void thrownExceptionShouldBeConvertedToMojoExceptionInSetup() { doThrow(new FailureException("Gurka")).when(sortPom).setup(any(SortPomLogger.class), any(PluginParameters.class)); final Executable testMethod = () -> sortMojo.setup(); final MojoFailureException thrown = assertThrows(MojoFailureException.class, testMethod); assertThat("Unexpected message", thrown.getMessage(), is(equalTo("Gurka"))); }