diff --git a/src/main/java/jenkins/test/RunMatchers.java b/src/main/java/jenkins/test/RunMatchers.java index 55ad11c62..9b2793d33 100644 --- a/src/main/java/jenkins/test/RunMatchers.java +++ b/src/main/java/jenkins/test/RunMatchers.java @@ -60,6 +60,13 @@ public static Matcher> logContains(String message) { return new RunLogMatcher(message); } + /** + * Creates a matcher checking whether a build has completed. + */ + public static Matcher> completed() { + return new CompletedRunMatcher(); + } + private static class RunResultMatcher extends TypeSafeMatcher> { @NonNull private final Result expectedResult; @@ -116,4 +123,16 @@ public void describeTo(Description description) { description.appendText("log containing ").appendValue(message); } } + + private static class CompletedRunMatcher extends TypeSafeMatcher> { + @Override + protected boolean matchesSafely(Run run) { + return !run.isLogUpdated(); + } + + @Override + public void describeTo(Description description) { + description.appendText("a completed build"); + } + } } diff --git a/src/test/java/jenkins/test/RunMatchersTest.java b/src/test/java/jenkins/test/RunMatchersTest.java index b46ab54ce..30c00ae32 100644 --- a/src/test/java/jenkins/test/RunMatchersTest.java +++ b/src/test/java/jenkins/test/RunMatchersTest.java @@ -23,6 +23,7 @@ */ package jenkins.test; +import static jenkins.test.RunMatchers.completed; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.not; @@ -49,7 +50,7 @@ public void buildSuccessful() throws Exception { var p = j.createFreeStyleProject(); p.getBuildersList().add(new SleepBuilder(1000)); var b = p.scheduleBuild2(0).waitForStart(); - assertThat(j.waitForCompletion(b), isSuccessful()); + assertThat(j.waitForCompletion(b), allOf(completed(), isSuccessful())); } @Test