Skip to content

Commit

Permalink
Merge pull request #167 from slonopotamus/build-and-assert-status
Browse files Browse the repository at this point in the history
Introduce new `JenkinsRule#buildAndAssertStatus()` method
  • Loading branch information
oleg-nenashev committed Oct 9, 2019
2 parents 013740e + 908a21d commit 0d21041
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1368,22 +1368,30 @@ public <R extends Run> R assertBuildStatusSuccess(Future<? extends R> r) throws
return assertBuildStatus(Result.SUCCESS, r);
}

public <J extends Job<J,R>,R extends Run<J,R>> R buildAndAssertSuccess(final J job) throws Exception {
assertThat(job, IsInstanceOf.instanceOf(ParameterizedJobMixIn.ParameterizedJob.class));
QueueTaskFuture f = new ParameterizedJobMixIn() {
@Override protected Job asJob() {
@Nonnull
public <J extends Job<J,R> & ParameterizedJobMixIn.ParameterizedJob,R extends Run<J,R> & Queue.Executable> R buildAndAssertSuccess(@Nonnull J job) throws Exception {
return buildAndAssertStatus(Result.SUCCESS, job);
}

/**
* Runs specified job and asserts that in finished with given build result.
* @since TODO
*/
@Nonnull
public <J extends Job<J,R> & ParameterizedJobMixIn.ParameterizedJob,R extends Run<J,R> & Queue.Executable> R buildAndAssertStatus(@Nonnull Result status, @Nonnull J job) throws Exception {
final QueueTaskFuture<R> f = new ParameterizedJobMixIn<J, R>() {
@Override protected J asJob() {
return job;
}
}.scheduleBuild2(0);
@SuppressWarnings("unchecked") // no way to make this compile checked
Future<R> f2 = f;
return assertBuildStatusSuccess(f2);
return assertBuildStatus(status, f);
}

/**
* Avoids need for cumbersome {@code this.<J,R>buildAndAssertSuccess(...)} type hints under JDK 7 javac (and supposedly also IntelliJ).
*/
public FreeStyleBuild buildAndAssertSuccess(FreeStyleProject job) throws Exception {
@Nonnull
public FreeStyleBuild buildAndAssertSuccess(@Nonnull FreeStyleProject job) throws Exception {
return assertBuildStatusSuccess(job.scheduleBuild2(0));
}

Expand Down

0 comments on commit 0d21041

Please sign in to comment.