private void doTriggerTest(boolean evenWhenUnstable, Result triggerResult,
Result dontTriggerResult) throws Exception {
FreeStyleProject p = createFreeStyleProject(),
dp = createDownstreamProject();
p.getPublishersList().add(new BuildTrigger("downstream", evenWhenUnstable));
p.getBuildersList().add(new MockBuilder(dontTriggerResult));
hudson.rebuildDependencyGraph();
// First build should not trigger downstream job
FreeStyleBuild b = p.scheduleBuild2(0).get();
assertNoDownstreamBuild(dp, b);
// Next build should trigger downstream job
p.getBuildersList().replace(new MockBuilder(triggerResult));
b = p.scheduleBuild2(0).get();
assertDownstreamBuild(dp, b);
}