/*
 * The MIT License
 *
 * Copyright (c) 2013-2014, CloudBees, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.jenkinsci.plugins.workflow.job;

import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.test.RestartableJenkinsRule;
import org.jenkinsci.plugins.workflow.test.steps.WatchYourStep;
import hudson.model.Result;
import hudson.model.queue.QueueTaskFuture;
import hudson.slaves.DumbSlave;
import org.junit.Assert;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;

import javax.inject.Inject;

/**
 * Base class for tests that interacts with a single workflow job.
 *
 * @author Kohsuke Kawaguchi
 */
public abstract class SingleJobTestBase extends Assert {
    @Rule
    public RestartableJenkinsRule story = new RestartableJenkinsRule();


    @Inject
    WatchYourStep.DescriptorImpl watchDescriptor;

    // currently executing workflow and its build
    public WorkflowJob p;
    public WorkflowRun b;
    public CpsFlowExecution e;

    /**
     * Updates p, b, and e variables from the given JenkinsRule
     */
    public void rebuildContext(JenkinsRule j) throws Exception {
        WorkflowJob p2 = (WorkflowJob) j.jenkins.getItem("demo");
        assert p!=p2;  // make sure Jenkins was restarted
        p = p2;

        WorkflowRun b2 = p.getLastBuild();
        assert b!=b2;
        b = b2;

        e = (CpsFlowExecution) b.getExecution();
    }

    /**
     * Asserts that {@link #e} is in the suspended state and has nothing more to execute.
     */
    public void assertThatWorkflowIsSuspended() throws Exception {
        assertThatWorkflowIsSuspended(b, e);
    }

    public void assertThatWorkflowIsSuspended(WorkflowRun b, CpsFlowExecution e) throws Exception {
        e.waitForSuspension();  // it should be in the suspended state
        assert b.isBuilding() : JenkinsRule.getLog(b);
    }

    public void waitForWorkflowToSuspend() throws Exception {
        waitForWorkflowToSuspend(e);
    }

    public void waitForWorkflowToSuspend(CpsFlowExecution e) throws Exception {
        e.waitForSuspension();
    }

    /**
     * Gets the build going and waits for the workflow to be fully running
     */
    public QueueTaskFuture<WorkflowRun> startBuilding() throws Exception {
        QueueTaskFuture<WorkflowRun> f = p.scheduleBuild2(0);
        b = f.waitForStart();
        e = (CpsFlowExecution) b.getExecutionPromise().get();
        return f;
    }

    public DumbSlave createSlave(JenkinsRule j) throws Exception {
        DumbSlave s = j.createSlave();
        s.getComputer().connect(false).get(); // wait for the slave to fully get connected
        return s;
    }

    /**
     * Verifies that 'b' has completed successfully.
     */
    public void assertBuildCompletedSuccessfully() throws Exception {
        assertBuildCompletedSuccessfully(b);
    }

    public void assertBuildCompletedSuccessfully(WorkflowRun b) throws Exception {
        assert !b.isBuilding(): JenkinsRule.getLog(b);
        Result r = b.getResult();
        assert r == Result.SUCCESS: "Result is "+r+"\n"+JenkinsRule.getLog(b);
    }
}

@@ -4060,108 +4060,40 @@
     
-Result r = b.getResult();%0A        assert r == Result.SUCCESS: %22Result is %22+r+%22%5Cn%22+JenkinsRule.getLog
+story.j.assertBuildStatusSuccess
 (b);

Use standard JenkinsRule.assertBuildStatusSuccess.