ValidateMojo extends AbstractMuleMojo { protected void validateMavenEnvironment() throws ValidationException { getLog().debug("Validating Maven environment..."); String mavenVersion = (String) session.getRequest().getSystemProperties().get("maven.version"); if (!VersionUtils.isVersionGreaterOrEquals(mavenVersion, MIN_MAVEN_VERSION)) { throw new ValidationException("Your Maven installation version is: " + mavenVersion + " We require at least:" + MIN_MAVEN_VERSION); } }  @Override void doExecute(); @Override String getPreviousRunPlaceholder();  }
@Test public void executeDoNotVerify() throws MojoFailureException, MojoExecutionException, IOException, ValidationException { mojoMock.skipValidation = true; doCallRealMethod().when(mojoMock).execute(); mojoMock.execute(); verify(mojoMock, times(0)).validateMavenEnvironment(); }
@Test public void validateMavenEnvironmentValid() throws MojoFailureException, MojoExecutionException, IOException, ValidationException { Properties systemProperties = new Properties(); systemProperties.put("maven.version", "3.3.3"); when(mavenExecutionRequestMock.getSystemProperties()).thenReturn(systemProperties); when(mavenSessionMock.getRequest()).thenReturn(mavenExecutionRequestMock); doCallRealMethod().when(mojoMock).validateMavenEnvironment(); mojoMock.validateMavenEnvironment(); }
@Test(expected = ValidationException.class) public void validateMavenEnvironmentInvalid() throws MojoFailureException, MojoExecutionException, IOException, ValidationException { Properties systemProperties = new Properties(); systemProperties.put("maven.version", "3.3.2"); when(mavenExecutionRequestMock.getSystemProperties()).thenReturn(systemProperties); when(mavenSessionMock.getRequest()).thenReturn(mavenExecutionRequestMock); doCallRealMethod().when(mojoMock).validateMavenEnvironment(); mojoMock.validateMavenEnvironment(); }