/** * 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()); }
/** * Tests the retriggered method of the class {@link BuildMemory}. With two started builds and the * one to be retriggered as completed already in memory. */ @Test public void testRetriggeredExistingMemory() { PatchsetCreated event = Setup.createPatchsetCreated(); BuildMemory instance = new BuildMemory(); AbstractProject project = mock(AbstractProject.class); AbstractBuild build = mock(AbstractBuild.class); when(build.getProject()).thenReturn(project); AbstractProject project2 = mock(AbstractProject.class); AbstractBuild build2 = mock(AbstractBuild.class); when(build2.getProject()).thenReturn(project2); AbstractProject project3 = mock(AbstractProject.class); AbstractBuild build3 = mock(AbstractBuild.class); when(build3.getProject()).thenReturn(project3); instance.started(event, build); instance.completed(event, build2); instance.started(event, build3); instance.retriggered(event, project2, null); MemoryImprint memory = instance.getMemoryImprint(event); assertNotNull(memory); assertEquals(3, memory.getEntries().length); MemoryImprint.Entry entry = null; for (MemoryImprint.Entry e : memory.getEntries()) { if (e.getProject().equals(project2)) { entry = e; break; } } assertNotNull(entry); assertFalse(entry.isBuildCompleted()); }
/** * Tests the retriggered method of the class {@link BuildMemory}. With no previous memory and null * list of "others". */ @Test public void testRetriggeredNoMemoryOneProjectNullOthers() { PatchsetCreated event = Setup.createPatchsetCreated(); BuildMemory instance = new BuildMemory(); AbstractProject project = mock(AbstractProject.class); instance.retriggered(event, project, null); MemoryImprint memory = instance.getMemoryImprint(event); assertNotNull(memory); assertEquals(1, memory.getEntries().length); assertEquals(project, memory.getEntries()[0].getProject()); assertFalse(memory.getEntries()[0].isBuildCompleted()); }
/** test. */ @Test public void testTriggered() { System.out.println("triggered"); PatchsetCreated event = Setup.createPatchsetCreated(); AbstractProject project = mock(AbstractProject.class); BuildMemory instance = new BuildMemory(); instance.triggered(event, project); assertNotNull(instance.getMemoryImprint(event)); assertFalse(instance.isAllBuildsStarted(event)); assertFalse(instance.isAllBuildsCompleted(event)); }
/** test. */ @Test public void testGetMemoryImprint() { System.out.println("getMemoryImprint"); BuildMemory instance = new BuildMemory(); PatchsetCreated event = Setup.createPatchsetCreated(); final AbstractProject project = mock(AbstractProject.class); instance.triggered(event, project); MemoryImprint result = instance.getMemoryImprint(event); assertNotNull(result); assertEquals(project, result.getEntries()[0].getProject()); assertEquals(event, result.getEvent()); }
/** test. */ @Test public void testForget() { System.out.println("forget"); PatchsetCreated event = Setup.createPatchsetCreated(); AbstractProject project = mock(AbstractProject.class); AbstractBuild build = mock(AbstractBuild.class); when(build.getProject()).thenReturn(project); BuildMemory instance = new BuildMemory(); instance.completed(event, build); instance.forget(event); assertNull(instance.getMemoryImprint(event)); }