16
16
import static org .hamcrest .Matchers .hasSize ;
17
17
import static org .hamcrest .Matchers .is ;
18
18
import static org .hamcrest .Matchers .notNullValue ;
19
- import static org .mockito .hamcrest .MockitoHamcrest .argThat ;
20
19
import static org .mockito .Mockito .any ;
21
20
import static org .mockito .Mockito .doThrow ;
22
21
import static org .mockito .Mockito .eq ;
26
25
import static org .mockito .Mockito .times ;
27
26
import static org .mockito .Mockito .verify ;
28
27
import static org .mockito .Mockito .when ;
28
+ import static org .mockito .hamcrest .MockitoHamcrest .argThat ;
29
29
30
30
import hudson .model .BooleanParameterDefinition ;
31
31
import hudson .model .Executor ;
41
41
import hudson .model .StringParameterDefinition ;
42
42
import hudson .model .StringParameterValue ;
43
43
import hudson .util .RunList ;
44
-
45
44
import java .util .Arrays ;
46
45
import java .util .Collection ;
47
46
import java .util .Collections ;
@@ -471,8 +470,7 @@ public void getBuildTargets_onlyBuildOnComment_multiple_comments_generate_multip
471
470
}
472
471
473
472
@ Test
474
- public void getBuildTargets_onlyBuildOnComment_skip_if_build_status_message ()
475
- throws Exception {
473
+ public void getBuildTargets_onlyBuildOnComment_skip_if_build_status_message () throws Exception {
476
474
when (trigger .getOnlyBuildOnComment ()).thenReturn (true );
477
475
when (trigger .getCiBuildPhrases ()).thenReturn ("DO TEST" );
478
476
when (project .getFullName ()).thenReturn ("MyProject" );
@@ -502,15 +500,15 @@ public void getBuildTargets_onlyBuildOnComment_skip_if_build_status_message()
502
500
}
503
501
504
502
@ Test
505
- public void getBuildTargets_onlyBuildOnComment_cancelOutdatedJobsEnabled_multiple_comments_generate_single_target ()
506
- throws Exception {
507
- StashPullRequestComment comment1 =
508
- new StashPullRequestComment (1 , "DO TEST\n p:key1=value1" );
509
- StashPullRequestComment comment2 =
510
- new StashPullRequestComment (2 , "DO TEST\n p:key2=value2" );
503
+ public void
504
+ getBuildTargets_onlyBuildOnComment_cancelOutdatedJobsEnabled_multiple_comments_generate_single_target ()
505
+ throws Exception {
506
+ StashPullRequestComment comment1 = new StashPullRequestComment (1 , "DO TEST\n p:key1=value1" );
507
+ StashPullRequestComment comment2 = new StashPullRequestComment (2 , "DO TEST\n p:key2=value2" );
511
508
List <StashPullRequestComment > comments = Arrays .asList (comment1 , comment2 );
512
509
when (stashApiClient .getPullRequestComments (any (), any (), any ())).thenReturn (comments );
513
- when (stashApiClient .postPullRequestComment (any (), any (), any ())).thenReturn (new StashPullRequestComment (3 , null ));
510
+ when (stashApiClient .postPullRequestComment (any (), any (), any ()))
511
+ .thenReturn (new StashPullRequestComment (3 , null ));
514
512
when (trigger .getCiBuildPhrases ()).thenReturn ("DO TEST" );
515
513
when (trigger .getOnlyBuildOnComment ()).thenReturn (true );
516
514
when (trigger .getCancelOutdatedJobsEnabled ()).thenReturn (true );
@@ -524,29 +522,27 @@ public void getBuildTargets_onlyBuildOnComment_cancelOutdatedJobsEnabled_multipl
524
522
contains (
525
523
allOf (
526
524
hasProperty ("additionalParameters" , aMapWithSize (1 )),
527
- hasProperty (
528
- "additionalParameters" ,
529
- hasEntry ("key2" , "value2" )))
530
- ));
525
+ hasProperty ("additionalParameters" , hasEntry ("key2" , "value2" )))));
531
526
}
532
527
533
- @ Test
534
- public void getBuildTargets_onlyBuildOnComment_cancelOutdatedJobsEnabled_posts_build_cancel_comment ()
535
- throws Exception {
536
- StashPullRequestComment comment1 =
537
- new StashPullRequestComment (1 , "DO TEST\n p:key1=value1" );
538
- StashPullRequestComment comment2 =
539
- new StashPullRequestComment (2 , "DO TEST\n p:key2=value2" );
528
+ @ Test
529
+ public void
530
+ getBuildTargets_onlyBuildOnComment_cancelOutdatedJobsEnabled_posts_build_cancel_comment ()
531
+ throws Exception {
532
+ StashPullRequestComment comment1 = new StashPullRequestComment (1 , "DO TEST\n p:key1=value1" );
533
+ StashPullRequestComment comment2 = new StashPullRequestComment (2 , "DO TEST\n p:key2=value2" );
540
534
List <StashPullRequestComment > comments = Arrays .asList (comment1 , comment2 );
541
535
when (stashApiClient .getPullRequestComments (any (), any (), any ())).thenReturn (comments );
542
- when (stashApiClient .postPullRequestComment (any (), any (), any ())).thenReturn (new StashPullRequestComment (3 , null ));
536
+ when (stashApiClient .postPullRequestComment (any (), any (), any ()))
537
+ .thenReturn (new StashPullRequestComment (3 , null ));
543
538
when (trigger .getCiBuildPhrases ()).thenReturn ("DO TEST" );
544
539
when (trigger .getOnlyBuildOnComment ()).thenReturn (true );
545
540
when (trigger .getCancelOutdatedJobsEnabled ()).thenReturn (true );
546
541
547
542
stashRepository .getBuildTargets (pullRequest );
548
543
549
- verify (stashApiClient ).postPullRequestComment (any (), argThat (containsString ("BuildCanceled" )), eq (1 ));
544
+ verify (stashApiClient )
545
+ .postPullRequestComment (any (), argThat (containsString ("BuildCanceled" )), eq (1 ));
550
546
}
551
547
552
548
@ Test
@@ -585,7 +581,8 @@ public void addFutureBuildTasks_removes_outdated_jobs_if_enabled() throws Except
585
581
}
586
582
587
583
@ Test
588
- public void addFutureBuildTasks_does_not_remove_old_jobs_if_cancelOutdatedJobs_is_disabled () throws Exception {
584
+ public void addFutureBuildTasks_does_not_remove_old_jobs_if_cancelOutdatedJobs_is_disabled ()
585
+ throws Exception {
589
586
when (trigger .getCancelOutdatedJobsEnabled ()).thenReturn (false );
590
587
when (trigger .getStashHost ()).thenReturn ("StashHost" );
591
588
when (project .getFullName ()).thenReturn ("MyProject" );
@@ -598,16 +595,20 @@ public void addFutureBuildTasks_does_not_remove_old_jobs_if_cancelOutdatedJobs_i
598
595
assertThat (Jenkins .getInstance ().getQueue ().getItems (), is (arrayWithSize (2 )));
599
596
}
600
597
601
- @ Test
598
+ @ Test
602
599
public void addFutureBuildTasks_cancels_running_job_if_enabled () throws Exception {
603
600
when (trigger .getCancelOutdatedJobsEnabled ()).thenReturn (true );
604
601
when (trigger .getStashHost ()).thenReturn ("StashHost" );
605
602
StashPullRequestComment response = new StashPullRequestComment (3 , null );
606
603
when (stashApiClient .postPullRequestComment (any (), any (), any ())).thenReturn (response );
607
604
FreeStyleBuild runningBuild = mock (FreeStyleBuild .class );
608
605
when (runningBuild .isBuilding ()).thenReturn (true );
609
- when (runningBuild .getCauses ()).thenReturn (Arrays .asList (
610
- new StashCause ("" , null , null , null , null , null , null , null , null , null , null , null , null , null , null )));
606
+ when (runningBuild .getCauses ())
607
+ .thenReturn (
608
+ Arrays .asList (
609
+ new StashCause (
610
+ "" , null , null , null , null , null , null , null , null , null , null , null , null ,
611
+ null , null )));
611
612
when (project .getBuilds ()).thenReturn (RunList .fromRuns (Arrays .asList (runningBuild )));
612
613
Executor executor = mock (Executor .class );
613
614
when (runningBuild .getExecutor ()).thenReturn (executor );
@@ -618,8 +619,9 @@ public void addFutureBuildTasks_cancels_running_job_if_enabled() throws Exceptio
618
619
assertThat (Jenkins .getInstance ().getQueue ().getItems (), is (arrayWithSize (1 )));
619
620
}
620
621
621
- @ Test
622
- public void addFutureBuildTasks_does_not_cancel_running_job_if_cancelOutdatedJobs_is_disabled () throws Exception {
622
+ @ Test
623
+ public void addFutureBuildTasks_does_not_cancel_running_job_if_cancelOutdatedJobs_is_disabled ()
624
+ throws Exception {
623
625
when (trigger .getCancelOutdatedJobsEnabled ()).thenReturn (false );
624
626
when (trigger .getStashHost ()).thenReturn ("StashHost" );
625
627
StashPullRequestComment response = new StashPullRequestComment (3 , null );
0 commit comments