@Test
  public void last_plugin_is_always_right() throws ProjectNotFoundException {
    QualityConnectionPlugin qualityPlugin1 = Mockito.mock(QualityConnectionPlugin.class);
    QualityConnectionPlugin qualityPlugin2 = Mockito.mock(QualityConnectionPlugin.class);

    QualityResult qualityResult1 = new QualityResult();
    QualityMeasure coverage = new QualityMeasure();
    coverage.setName("coverage");
    coverage.setValue(29D);
    coverage.setFormattedValue("29%");
    qualityResult1.add("coverage", coverage);

    QualityResult qualityResult2 = new QualityResult();
    QualityMeasure coverage2 = new QualityMeasure();
    coverage2.setName("coverage");
    coverage2.setValue(1D);
    coverage2.setFormattedValue("1%");
    qualityResult2.add("coverage", coverage2);

    ProjectId projectId = projectToEnhance.getProjectId();
    when(qualityPlugin1.analyzeQuality(projectId)).thenReturn(qualityResult1);
    when(qualityPlugin2.analyzeQuality(projectId)).thenReturn(qualityResult2);
    projectEnhancerService.enhanceWithQualityAnalysis(projectToEnhance, qualityPlugin1);
    projectEnhancerService.enhanceWithQualityAnalysis(projectToEnhance, qualityPlugin2);

    assertEquals(coverage2, projectToEnhance.getQualityResult().getMeasure("coverage"));
  }
  @Test
  public void should_merge_with_two_build_plugins() throws ProjectNotFoundException {
    QualityConnectionPlugin qualityPlugin1 = Mockito.mock(QualityConnectionPlugin.class);
    QualityConnectionPlugin qualityPlugin2 = Mockito.mock(QualityConnectionPlugin.class);

    QualityResult qualityResult1 = new QualityResult();
    QualityMeasure coverage = new QualityMeasure();
    coverage.setName("coverage");
    coverage.setValue(29D);
    coverage.setFormattedValue("29%");
    qualityResult1.add("coverage", coverage);

    QualityResult qualityResult2 = new QualityResult();
    QualityMeasure violations = new QualityMeasure();
    violations.setName("violations");
    violations.setValue(1D);
    violations.setFormattedValue("1%");
    qualityResult2.add("violations", violations);

    ProjectId projectId = projectToEnhance.getProjectId();
    when(qualityPlugin1.analyzeQuality(projectId)).thenReturn(qualityResult1);
    when(qualityPlugin2.analyzeQuality(projectId)).thenReturn(qualityResult2);
    projectEnhancerService.enhanceWithQualityAnalysis(projectToEnhance, qualityPlugin1);
    projectEnhancerService.enhanceWithQualityAnalysis(projectToEnhance, qualityPlugin2);

    assertEquals(coverage, projectToEnhance.getQualityResult().getMeasure("coverage"));
    assertEquals(violations, projectToEnhance.getQualityResult().getMeasure("violations"));
  }
  @Test
  public void should_merge_with_one_build_plugin() throws ProjectNotFoundException {
    QualityConnectionPlugin qualityPlugin = Mockito.mock(QualityConnectionPlugin.class);

    QualityResult qualityResult = new QualityResult();
    QualityMeasure coverage = new QualityMeasure();
    coverage.setName("coverage");
    coverage.setValue(29D);
    coverage.setFormattedValue("29%");
    qualityResult.add("coverage", coverage);

    ProjectId projectId = projectToEnhance.getProjectId();
    when(qualityPlugin.analyzeQuality(projectId)).thenReturn(qualityResult);
    projectEnhancerService.enhanceWithQualityAnalysis(projectToEnhance, qualityPlugin);

    assertEquals(coverage, projectToEnhance.getQualityResult().getMeasure("coverage"));
  }
  @Test
  public void should_enhance_unit_test_results() {
    TestResult testResult = new TestResult();
    testResult.setCoverage(4);
    testResult.setFailCount(1);
    testResult.setPassCount(2);
    testResult.setSkipCount(3);

    QualityConnectionPlugin qualityPlugin = Mockito.mock(QualityConnectionPlugin.class);
    when(qualityPlugin.analyzeUnitTests(projectToEnhance.getProjectId())).thenReturn(testResult);

    projectEnhancerService.enhanceWithQualityAnalysis(projectToEnhance, qualityPlugin);

    Build build = projectToEnhance.getCompletedBuild();

    TestResult enhancedTestResult = build.getUnitTestResult();
    assertEquals(1, enhancedTestResult.getFailCount());
    assertEquals(2, enhancedTestResult.getPassCount());
    assertEquals(3, enhancedTestResult.getSkipCount());
    assertEquals(4.0, enhancedTestResult.getCoverage(), 0);
  }