@Test
  public void testAlreadyRunningBuildAndInstall() {
    constructProjectScreenPresenter(
        new CallerMock<BuildService>(buildService), assetManagementCaller());
    presenter.onStartup(mock(PlaceRequest.class));

    presenter.triggerBuildAndInstall();
    presenter.triggerBuildAndInstall();

    verify(view, times(1)).showABuildIsAlreadyRunning();
    verify(notificationEvent, never()).fire(any(NotificationEvent.class));
    verifyBusyShowHideAnyString(2, 2);
  }
  @Test
  public void testOnDependenciesSelected() throws Exception {

    when(lockManagerInstanceProvider.get()).thenReturn(mock(LockManager.class));

    Path pathToPOM = mock(Path.class);
    model.setPathToPOM(pathToPOM);

    when(view.getDependenciesPart()).thenReturn(dependenciesPart);

    presenter.onStartup(mock(PlaceRequest.class));

    presenter.onDependenciesSelected();

    verify(view).showDependenciesPanel();
  }
  @Test
  public void testBuildCommandFail() {
    BuildMessage message = mock(BuildMessage.class);
    List<BuildMessage> messages = new ArrayList<BuildMessage>();
    messages.add(message);

    BuildResults results = mock(BuildResults.class);
    when(results.getErrorMessages()).thenReturn(messages);

    when(buildService.buildAndDeploy(any(Project.class))).thenReturn(results);

    presenter.triggerBuild();

    verify(notificationEvent)
        .fire(
            argThat(
                new ArgumentMatcher<NotificationEvent>() {
                  @Override
                  public boolean matches(final Object argument) {
                    final NotificationEvent event = (NotificationEvent) argument;
                    final String notification = event.getNotification();
                    final NotificationEvent.NotificationType type = event.getType();

                    return notification.equals(ProjectEditorResources.CONSTANTS.BuildFailed())
                        && type.equals(NotificationEvent.NotificationType.ERROR);
                  }
                }));

    verify(view, times(1)).showBusyIndicator(eq(ProjectEditorResources.CONSTANTS.Building()));
    // There are two calls to "hide" by this stage; one from the view initialisation one for the
    // build
    verify(view, times(2)).hideBusyIndicator();
  }
  @Test
  public void testIsDirtyBuildAndDeploy() {
    model.setPOM(mock(POM.class)); // causes isDirty evaluates as true
    presenter.triggerBuildAndDeploy("usr", "psw", "url");

    verify(view, times(1))
        .showSaveBeforeContinue(any(Command.class), any(Command.class), any(Command.class));
    verify(notificationEvent, never()).fire(any(NotificationEvent.class));
    verifyBusyShowHideAnyString(1, 1);
  }
  @Test
  public void testAlreadyRunningBuild() {
    constructProjectScreenPresenter(
        buildServiceCaller(), new CallerMock<AssetManagementService>(assetManagementServiceMock));

    presenter.triggerBuild();
    presenter.triggerBuild();

    verify(view, times(1)).showABuildIsAlreadyRunning();
    verify(notificationEvent, never()).fire(any(NotificationEvent.class));
    verifyBusyShowHideAnyString(2, 1);
  }
  @Test
  public void testBuildAndDeployCommandFail() {
    doThrow(new RuntimeException())
        .when(assetManagementServiceMock)
        .buildProject(
            anyString(),
            anyString(),
            anyString(),
            anyString(),
            anyString(),
            anyString(),
            anyBoolean());

    presenter.triggerBuildAndDeploy("user", "password", "url");

    verify(notificationEvent, never()).fire(any(NotificationEvent.class));
    verify(view, times(1)).showUnexpectedErrorPopup(anyString());

    verifyBusyShowHideAnyString(1, 1);
  }
  @Test
  public void testBuildAndDeployCommand() {
    presenter.triggerBuildAndDeploy("user", "password", "url");

    verify(notificationEvent)
        .fire(
            argThat(
                new ArgumentMatcher<NotificationEvent>() {
                  @Override
                  public boolean matches(final Object argument) {
                    final NotificationEvent event = (NotificationEvent) argument;
                    final String notification = event.getNotification();
                    final NotificationEvent.NotificationType type = event.getType();

                    return notification.equals(
                            ProjectEditorResources.CONSTANTS.BuildProcessStarted())
                        && type.equals(NotificationEvent.NotificationType.SUCCESS);
                  }
                }));

    verify(notificationEvent, times(1)).fire(any(NotificationEvent.class));
    verifyBusyShowHideAnyString(1, 1);
  }
  @Test
  public void testBuildCommand() {
    presenter.triggerBuild();

    verify(notificationEvent)
        .fire(
            argThat(
                new ArgumentMatcher<NotificationEvent>() {
                  @Override
                  public boolean matches(final Object argument) {
                    final NotificationEvent event = (NotificationEvent) argument;
                    final String notification = event.getNotification();
                    final NotificationEvent.NotificationType type = event.getType();

                    return notification.equals(ProjectEditorResources.CONSTANTS.BuildSuccessful())
                        && type.equals(NotificationEvent.NotificationType.SUCCESS);
                  }
                }));

    verify(view, times(1)).showBusyIndicator(eq(ProjectEditorResources.CONSTANTS.Building()));
    // There are two calls to "hide" by this stage; one from the view initialisation one for the
    // build
    verify(view, times(2)).hideBusyIndicator();
  }