@Before
  public void setup() {
    ApplicationPreferences.setUp(new HashMap<String, String>());

    // The BuildOptions widget is manipulated in the Presenter so we need some nasty mocking
    when(view.getBuildOptionsButton()).thenReturn(buildOptions);
    when(buildOptions.getWidget(eq(0))).thenReturn(buildOptionsButton1);
    when(buildOptions.getWidget(eq(1))).thenReturn(buildOptionsMenu);
    when(buildOptionsMenu.getWidget(eq(0))).thenReturn(buildOptionsMenuButton1);
    when(buildOptionsMenu.getWidget(eq(1))).thenReturn(buildOptionsMenuButton1);

    constructProjectScreenPresenter(
        new CallerMock<BuildService>(buildService),
        new CallerMock<AssetManagementService>(assetManagementServiceMock));

    // Mock ProjectScreenService
    final POM pom = new POM(new GAV("groupId", "artifactId", "version"));
    model = new ProjectScreenModel();
    model.setPOM(pom);
    when(projectScreenService.load(any(org.uberfire.backend.vfs.Path.class))).thenReturn(model);

    // Mock BuildService
    when(buildService.buildAndDeploy(any(Project.class))).thenReturn(new BuildResults());

    // Mock LockManager initialisation
    final Path path = mock(Path.class);
    final Metadata pomMetadata = mock(Metadata.class);
    model.setPOMMetaData(pomMetadata);
    when(pomMetadata.getPath()).thenReturn(path);
    final Metadata kmoduleMetadata = mock(Metadata.class);
    model.setKModuleMetaData(kmoduleMetadata);
    when(kmoduleMetadata.getPath()).thenReturn(path);
    final Metadata importsMetadata = mock(Metadata.class);
    model.setProjectImportsMetaData(importsMetadata);
    when(importsMetadata.getPath()).thenReturn(path);

    // Mock ProjectContext
    final Repository repository = mock(Repository.class);
    when(context.getActiveRepository()).thenReturn(repository);
    when(repository.getAlias()).thenReturn("repository");
    when(repository.getCurrentBranch()).thenReturn("master");

    final Project project = mock(Project.class);
    when(project.getProjectName()).thenReturn("project");

    when(context.getActiveProject()).thenReturn(project);

    // Trigger initialisation of view. Unfortunately this is the only way to initialise a Project in
    // the Presenter
    context.onProjectContextChanged(
        new ProjectContextChangeEvent(mock(OrganizationalUnit.class), repository, project));

    verify(view, times(1)).showBusyIndicator(eq(CommonConstants.INSTANCE.Loading()));
    verify(view, times(1)).hideBusyIndicator();
  }
  @Test
  public void testPOMSave() throws Exception {

    final ProjectScreenModel model = new ProjectScreenModel();
    final POM pom = new POM();
    model.setPOM(pom);
    final Metadata pomMetaData = new Metadata();
    model.setPOMMetaData(pomMetaData);

    saver.save(pathToPom, model, "message");

    verify(pomService).save(eq(pathToPom), eq(pom), eq(pomMetaData), eq("message"));
  }
  @Test
  public void testWhiteListSave() throws Exception {

    final ProjectScreenModel model = new ProjectScreenModel();
    final WhiteList whiteList = new WhiteList();
    model.setWhiteList(whiteList);
    final Path pathToWhiteList = mock(Path.class);
    model.setPathToWhiteList(pathToWhiteList);
    final Metadata metadata = new Metadata();
    model.setWhiteListMetaData(metadata);

    saver.save(pathToPom, model, "message white list");

    verify(whiteListService)
        .save(eq(pathToWhiteList), eq(whiteList), eq(metadata), eq("message white list"));
  }
  @Test
  public void testImportsSave() throws Exception {

    final ProjectScreenModel model = new ProjectScreenModel();
    final ProjectImports projectImports = new ProjectImports();
    model.setProjectImports(projectImports);
    final Path pathToImports = mock(Path.class);
    model.setPathToImports(pathToImports);
    final Metadata metadata = new Metadata();
    model.setProjectImportsMetaData(metadata);

    saver.save(pathToPom, model, "message imports");

    verify(importsService)
        .save(eq(pathToImports), eq(projectImports), eq(metadata), eq("message imports"));
  }
  @Test
  public void testKModuleSave() throws Exception {

    final ProjectScreenModel model = new ProjectScreenModel();
    final KModuleModel kModule = new KModuleModel();
    model.setKModule(kModule);
    final Path pathToKModule = mock(Path.class);
    model.setPathToKModule(pathToKModule);
    final Metadata metadata = new Metadata();
    model.setKModuleMetaData(metadata);

    saver.save(pathToPom, model, "message kmodule");

    verify(kModuleService)
        .save(eq(pathToKModule), eq(kModule), eq(metadata), eq("message kmodule"));
  }
  @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);
  }
  @Before
  public void setup() {
    ApplicationPreferences.setUp(new HashMap<String, String>());

    mockBuildOptions();

    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOMMetaData(new Metadata());
    model.setKModuleMetaData(new Metadata());
    model.setProjectImportsMetaData(new Metadata());
    mockProjectScreenService(model);

    mockProjectContext(new POM(), repository, project, pomPath);

    constructProjectScreenPresenter(
        project,
        new CallerMock<BuildService>(buildService),
        new CallerMock<SpecManagementService>(specManagementServiceMock));
    presenter.setupPathToPomXML();
  }
  @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();
  }