@@ -59,7 +59,7 @@ public void testGetContent_shouldGetPreviousBuildFailures()
5959 throws Exception {
6060 AbstractBuild failureBuild = createBuild (Result .FAILURE , 41 , "Changes for a failed build." );
6161
62- AbstractBuild currentBuild = createBuild (Result .SUCCESS , 42 , "Changes for a successful build." );
62+ AbstractBuild currentBuild = createBuild4 (Result .SUCCESS , 42 , "Changes for a successful build." );
6363 when (currentBuild .getPreviousBuild ()).thenReturn (failureBuild );
6464 when (failureBuild .getNextBuild ()).thenReturn (currentBuild );
6565
@@ -82,10 +82,9 @@ public void testGetContent_whenReverseOrderIsTrueShouldReverseOrderOfChanges()
8282
8383 AbstractBuild failureBuild = createBuild (Result .FAILURE , 41 , "Changes for a failed build." );
8484
85- AbstractBuild currentBuild = createBuild (Result .SUCCESS , 42 , "Changes for a successful build." );
85+ AbstractBuild currentBuild = createBuild4 (Result .SUCCESS , 42 , "Changes for a successful build." );
8686 when (currentBuild .getPreviousBuild ()).thenReturn (failureBuild );
87- when (failureBuild .getNextBuild ()).thenReturn (currentBuild );
88-
87+
8988 String contentStr = content .evaluate (currentBuild , listener , ChangesSinceLastUnstableBuildMacro .MACRO_NAME );
9089
9190 assertEquals ("Changes for Build #42\n " + "[Ash Lux] Changes for a successful build.\n " + "\n " + "\n "
@@ -97,15 +96,12 @@ public void testGetContent_shouldGetPreviousBuildsThatArentUnstable_HUDSON3519()
9796 throws Exception {
9897 // Test for HUDSON-3519
9998
100- AbstractBuild successfulBuild = createBuild (Result .SUCCESS , 2 , "Changes for a successful build." );
99+ AbstractBuild successfulBuild = createBuild3 (Result .SUCCESS , 2 , "Changes for a successful build." );
101100
102- AbstractBuild unstableBuild = createBuild (Result .UNSTABLE , 3 , "Changes for an unstable build." );
103- when (unstableBuild .getPreviousBuild ()).thenReturn (successfulBuild );
104- when (successfulBuild .getNextBuild ()).thenReturn (unstableBuild );
101+ AbstractBuild unstableBuild = createBuild2 (Result .UNSTABLE , 3 , "Changes for an unstable build." );
105102
106103 AbstractBuild abortedBuild = createBuild (Result .ABORTED , 4 , "Changes for an aborted build." );
107104 when (abortedBuild .getPreviousBuild ()).thenReturn (unstableBuild );
108- when (unstableBuild .getNextBuild ()).thenReturn (abortedBuild );
109105
110106 AbstractBuild failureBuild = createBuild (Result .FAILURE , 5 , "Changes for a failed build." );
111107 when (failureBuild .getPreviousBuild ()).thenReturn (abortedBuild );
@@ -115,7 +111,7 @@ public void testGetContent_shouldGetPreviousBuildsThatArentUnstable_HUDSON3519()
115111 when (notBuiltBuild .getPreviousBuild ()).thenReturn (failureBuild );
116112 when (failureBuild .getNextBuild ()).thenReturn (notBuiltBuild );
117113
118- AbstractBuild currentBuild = createBuild (Result .UNSTABLE , 7 , "Changes for an unstable build." );
114+ AbstractBuild currentBuild = createBuild4 (Result .UNSTABLE , 7 , "Changes for an unstable build." );
119115 when (currentBuild .getPreviousBuild ()).thenReturn (notBuiltBuild );
120116 when (notBuiltBuild .getNextBuild ()).thenReturn (currentBuild );
121117
@@ -147,7 +143,7 @@ public void testShouldPrintDate()
147143
148144 AbstractBuild failureBuild = createBuild (Result .FAILURE , 41 , "Changes for a failed build." );
149145
150- AbstractBuild currentBuild = createBuild (Result .SUCCESS , 42 , "Changes for a successful build." );
146+ AbstractBuild currentBuild = createBuild4 (Result .SUCCESS , 42 , "Changes for a successful build." );
151147 when (currentBuild .getPreviousBuild ()).thenReturn (failureBuild );
152148 when (failureBuild .getNextBuild ()).thenReturn (currentBuild );
153149
@@ -166,7 +162,7 @@ public void testShouldPrintRevision()
166162
167163 AbstractBuild failureBuild = createBuild (Result .FAILURE , 41 , "Changes for a failed build." );
168164
169- AbstractBuild currentBuild = createBuild (Result .SUCCESS , 42 , "Changes for a successful build." );
165+ AbstractBuild currentBuild = createBuild4 (Result .SUCCESS , 42 , "Changes for a successful build." );
170166 when (currentBuild .getPreviousBuild ()).thenReturn (failureBuild );
171167 when (failureBuild .getNextBuild ()).thenReturn (currentBuild );
172168
@@ -182,7 +178,7 @@ public void testShouldPrintPath()
182178
183179 AbstractBuild failureBuild = createBuild (Result .FAILURE , 41 , "Changes for a failed build." );
184180
185- AbstractBuild currentBuild = createBuild (Result .SUCCESS , 42 , "Changes for a successful build." );
181+ AbstractBuild currentBuild = createBuild4 (Result .SUCCESS , 42 , "Changes for a successful build." );
186182 when (currentBuild .getPreviousBuild ()).thenReturn (failureBuild );
187183 when (failureBuild .getNextBuild ()).thenReturn (currentBuild );
188184
@@ -199,7 +195,7 @@ public void testWhenShowPathsIsTrueShouldPrintPath()
199195
200196 AbstractBuild failureBuild = createBuild (Result .FAILURE , 41 , "Changes for a failed build." );
201197
202- AbstractBuild currentBuild = createBuild (Result .SUCCESS , 42 , "Changes for a successful build." );
198+ AbstractBuild currentBuild = createBuild4 (Result .SUCCESS , 42 , "Changes for a successful build." );
203199 when (currentBuild .getPreviousBuild ()).thenReturn (failureBuild );
204200 when (failureBuild .getNextBuild ()).thenReturn (currentBuild );
205201
@@ -219,7 +215,7 @@ public void testRegexReplace()
219215
220216 AbstractBuild failureBuild = createBuild (Result .FAILURE , 41 , "<defectId>DEFECT-666</defectId><message>Changes for a failed build.</message>" );
221217
222- AbstractBuild currentBuild = createBuild (Result .SUCCESS , 42 , "<defectId>DEFECT-666</defectId><message>Changes for a successful build.</message>" );
218+ AbstractBuild currentBuild = createBuild4 (Result .SUCCESS , 42 , "<defectId>DEFECT-666</defectId><message>Changes for a successful build.</message>" );
223219 when (currentBuild .getPreviousBuild ()).thenReturn (failureBuild );
224220 when (failureBuild .getNextBuild ()).thenReturn (currentBuild );
225221
@@ -321,9 +317,7 @@ public void testShouldEscapeHtmlWhenArgumentEscapeHtmlSetToTrue()
321317
322318 private AbstractBuild createBuildWithNoChanges (Result result , int buildNumber ) {
323319 AbstractBuild build = mock (AbstractBuild .class );
324- when (build .getResult ()).thenReturn (result );
325320 ChangeLogSet changes1 = createEmptyChangeLog ();
326- when (build .getChangeSet ()).thenReturn (changes1 );
327321 when (build .getChangeSets ()).thenReturn (Collections .singletonList (changes1 ));
328322 when (build .getNumber ()).thenReturn (buildNumber );
329323
@@ -333,7 +327,6 @@ private AbstractBuild createBuildWithNoChanges(Result result, int buildNumber) {
333327 public ChangeLogSet createEmptyChangeLog () {
334328 ChangeLogSet changes = mock (ChangeLogSet .class );
335329 List <ChangeLogSet .Entry > entries = Collections .emptyList ();
336- when (changes .iterator ()).thenReturn (entries .iterator ());
337330 when (changes .isEmptySet ()).thenReturn (true );
338331
339332 return changes ;
@@ -406,4 +399,33 @@ public long getTimestamp() {
406399 return 1382409540000L ;
407400 }
408401 }
402+
403+ private AbstractBuild createBuild2 (Result result , int buildNumber , String message ) {
404+ AbstractBuild build = mock (AbstractBuild .class );
405+ ChangeLogSet changes1 = createChangeLog2 (message );
406+ when (build .getResult ()).thenReturn (result );
407+ return build ;
408+ }
409+
410+ private AbstractBuild createBuild3 (Result result , int buildNumber , String message ) {
411+ AbstractBuild build = mock (AbstractBuild .class );
412+ ChangeLogSet changes1 = createChangeLog2 (message );
413+ return build ;
414+ }
415+
416+ private AbstractBuild createBuild4 (Result result , int buildNumber , String message ) {
417+ AbstractBuild build = mock (AbstractBuild .class );
418+ ChangeLogSet changes1 = createChangeLog (message );
419+ when (build .getChangeSets ()).thenReturn (Collections .singletonList (changes1 ));
420+ when (build .getNumber ()).thenReturn (buildNumber );
421+ return build ;
422+ }
423+
424+ public ChangeLogSet createChangeLog2 (String message ) {
425+ ChangeLogSet changes = mock (ChangeLogSet .class );
426+ List <ChangeLogSet .Entry > entries = new LinkedList <ChangeLogSet .Entry >();
427+ ChangeLogSet .Entry entry = new ChangeLogEntry (message , "Ash Lux" );
428+ entries .add (entry );
429+ return changes ;
430+ }
409431}
0 commit comments