/**
   * Tests run of zipalign with correct parameters as well adding aligned file to artifacts
   *
   * @throws Exception
   */
  public void testDefaultRun() throws Exception {
    ZipalignMojo mojo = createMojo("zipalign-config-project3");

    MavenProject project = Whitebox.getInternalState(mojo, "project");
    project.setPackaging(AndroidExtension.APK);

    MavenProjectHelper projectHelper = EasyMock.createNiceMock(MavenProjectHelper.class);
    Capture<File> capturedParameter = new Capture<File>();
    projectHelper.attachArtifact(
        EasyMock.eq(project),
        EasyMock.eq(AndroidExtension.APK),
        EasyMock.eq("aligned"),
        EasyMock.capture(capturedParameter));
    Whitebox.setInternalState(mojo, "projectHelper", projectHelper);

    final CommandExecutor mockExecutor = PowerMock.createMock(CommandExecutor.class);
    PowerMock.replace(
            CommandExecutor.Factory.class.getDeclaredMethod("createDefaultCommmandExecutor"))
        .with(
            new InvocationHandler() {
              @Override
              public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return mockExecutor;
              }
            });

    Capture<List<String>> capturedFile = new Capture<List<String>>();
    mockExecutor.setLogger(EasyMock.anyObject(Log.class));
    mockExecutor.executeCommand(EasyMock.anyObject(String.class), EasyMock.capture(capturedFile));

    PowerMock.mockStatic(FileUtils.class);
    EasyMock.expect(FileUtils.fileExists("app-updated.apk")).andReturn(true);

    EasyMock.replay(projectHelper);
    PowerMock.replay(mockExecutor);
    PowerMock.replay(FileUtils.class);

    mojo.execute();

    PowerMock.verify(mockExecutor);
    List<String> parameters = capturedFile.getValue();
    List<String> parametersExpected = new ArrayList<String>();
    parametersExpected.add("-v");
    parametersExpected.add("-f");
    parametersExpected.add("4");
    parametersExpected.add("app.apk");
    parametersExpected.add("app-updated.apk");
    assertEquals("Zipalign arguments aren't as expected", parametersExpected, parameters);

    PowerMock.verify(projectHelper);
    assertEquals(
        "File should be same as expected",
        new File("app-updated.apk"),
        capturedParameter.getValue());

    // verify that all method were invoked
    PowerMock.verify(FileUtils.class);
  }
  private void undeploy(MatchPatternStrategy matchPatternStrategy) throws Exception {
    final MavenProject mavenProject = new MavenProject();
    mavenProject.setPackaging("war");

    final File pom = getPom("undeploy-webarchive-match-pom.xml");

    final Undeploy undeployMojo = lookupMojoAndVerify("undeploy", pom);

    undeployMojo.project = mavenProject;
    undeployMojo.matchPatternStrategy = matchPatternStrategy.toString();
    undeployMojo.execute();
  }
  private void deploy(String deploymentName) throws Exception {
    final MavenProject mavenProject = new MavenProject();
    mavenProject.setPackaging("war");

    final File pom = getPom("deploy-webarchive-pom.xml");

    final AbstractDeployment deployMojo = lookupMojoAndVerify("deploy", pom);

    deployMojo.project = mavenProject;
    deployMojo.name = deploymentName;
    deployMojo.execute();

    // /deployment=test.war :read-attribute(name=status)
    final ModelNode address = ServerOperations.createAddress("deployment", deploymentName);
    final ModelNode op = ServerOperations.createReadAttributeOperation(address, "status");
    final ModelNode result = executeOperation(managementClient.getControllerClient(), op);

    assertEquals("OK", ServerOperations.readResultAsString(result));
  }