/**
  * Checks the list of event listeners for a single {@link
  * com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.EventListener} that points to a
  * {@link GerritTrigger} and checks if that is configured for the project pattern.
  *
  * @param gerritProjectPattern the pattern to check
  * @throws Exception if so
  */
 private void assertEventListenerWithSomeOtherProjectSet(String gerritProjectPattern)
     throws Exception {
   Collection<GerritEventListener> eventListeners = getGerritEventListeners();
   boolean found = false;
   for (GerritEventListener listener : eventListeners) {
     if (listener
         .getClass()
         .getName()
         .equals("com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.EventListener")) {
       found = true;
       GerritTrigger trigger = Whitebox.invokeMethod(listener, "getTrigger");
       assertNotNull("No Trigger for EventListener", trigger);
       assertSame(Whitebox.getInternalState(trigger, "job"), j.jenkins.getItem("testProj"));
       List<GerritProject> projectList = trigger.getGerritProjects();
       assertEquals(2, projectList.size());
       boolean foundSomeOtherProject = false;
       for (GerritProject project : projectList) {
         if (gerritProjectPattern.equals(project.getPattern())) {
           foundSomeOtherProject = true;
         }
       }
       assertTrue("Could not find " + gerritProjectPattern, foundSomeOtherProject);
     }
   }
   assertTrue("No EventListener", found);
 }
  /**
   * Tests a scenario when two builds are successful and both configured to be skipped. Expected
   * outcome is that {@link BuildMemory.MemoryImprint#wereAllBuildsSuccessful()} will return true.
   * As before the skip vote feature was implemented.
   */
  @Test
  public void testWereAllBuildsSuccessfulTwoSuccessfulBothSkipped() {
    PatchsetCreated event = Setup.createPatchsetCreated();
    BuildMemory instance = new BuildMemory();

    AbstractProject project = mock(AbstractProject.class);
    SkipVote skipVote = new SkipVote(true, false, false, false);
    GerritTrigger trigger = mock(GerritTrigger.class);
    when(trigger.getSkipVote()).thenReturn(skipVote);
    when(project.getTrigger(eq(GerritTrigger.class))).thenReturn(trigger);
    AbstractBuild build = mock(AbstractBuild.class);
    when(build.getProject()).thenReturn(project);
    when(build.getResult()).thenReturn(Result.SUCCESS);
    instance.started(event, build);

    AbstractProject project2 = mock(AbstractProject.class);
    skipVote = new SkipVote(true, false, false, false);
    trigger = mock(GerritTrigger.class);
    when(trigger.getSkipVote()).thenReturn(skipVote);
    when(project2.getTrigger(eq(GerritTrigger.class))).thenReturn(trigger);
    AbstractBuild build2 = mock(AbstractBuild.class);
    when(build2.getProject()).thenReturn(project2);
    when(build2.getResult()).thenReturn(Result.SUCCESS);
    instance.started(event, build2);

    instance.completed(event, build);
    instance.completed(event, build2);

    MemoryImprint memoryImprint = instance.getMemoryImprint(event);
    assertTrue(memoryImprint.wereAllBuildsSuccessful());
  }