GitHubBranchCreatedEvent extends GitHubBranchEvent { @Override public GitHubBranchCause check(@Nonnull GitHubBranchDecisionContext context) throws IOException { GHBranch remoteBranch = context.getRemoteBranch(); GitHubBranch localBranch = context.getLocalBranch(); TaskListener listener = context.getListener(); if (isNull(remoteBranch) && isNull(localBranch)) { LOG.debug("Remote and local branch are null"); return null; } else if (isNull(remoteBranch)) { LOG.debug("Remote branch is null for localBranch '{}'. Branch can't be 'created'", localBranch.getName()); return null; } GitHubBranchCause cause = null; if (isNull(localBranch)) { final PrintStream logger = listener.getLogger(); logger.println(DISPLAY_NAME + ": '" + remoteBranch.getName() + "'"); LOG.debug("{}: '{}'", DISPLAY_NAME, remoteBranch.getName()); cause = context.newCause(DISPLAY_NAME, false); } return cause; } @DataBoundConstructor  GitHubBranchCreatedEvent(); @Override GitHubBranchCause check(@Nonnull GitHubBranchDecisionContext context);  }
@Test public void branchCreated() throws IOException { commonExpectations(); assertThat( event.check(newGitHubBranchDecisionContext() .withLocalBranch(null) .withBranchTrigger(trigger) .withLocalRepo(localRepo) .withRemoteBranch(remoteBranch) .withListener(listener) .build()), notNullValue() ); }
@Test public void branchNotChangedExisted() throws IOException { commonExpectations(); assertThat( event.check(newGitHubBranchDecisionContext() .withLocalBranch(localBranch) .withBranchTrigger(trigger) .withLocalRepo(localRepo) .withRemoteBranch(remoteBranch) .withListener(listener) .build()), nullValue() ); }
@Test public void branchNotChangedNotExisted() throws IOException { commonExpectations(); assertThat( event.check(newGitHubBranchDecisionContext() .withLocalBranch(null) .withBranchTrigger(trigger) .withLocalRepo(localRepo) .withRemoteBranch(null) .withListener(listener) .build()), nullValue() ); }
@Test public void branchDeleted() throws IOException { commonExpectations(); assertThat( event.check(newGitHubBranchDecisionContext() .withLocalBranch(localBranch) .withBranchTrigger(trigger) .withLocalRepo(localRepo) .withRemoteBranch(null) .withListener(listener) .build()), nullValue() ); }