GitHubBranchHashChangedEvent extends GitHubBranchEvent { @Override public GitHubBranchCause check(@Nonnull GitHubBranchDecisionContext context) throws IOException { GHBranch remoteBranch = context.getRemoteBranch(); GitHubBranch localBranch = context.getLocalBranch(); TaskListener listener = context.getListener(); GitHubBranchCause cause = null; if (nonNull(localBranch) && nonNull(remoteBranch)) { final String localBranchSHA1 = localBranch.getCommitSha(); final String remoteBranchSHA1 = remoteBranch.getSHA1(); if (!localBranchSHA1.equals(remoteBranchSHA1)) { final PrintStream logger = listener.getLogger(); logger.printf("%s: hash has changed '%s' -> '%s'%n", DISPLAY_NAME, localBranchSHA1, remoteBranchSHA1); LOG.debug("{}: hash has changed '{}' -> '{}'", DISPLAY_NAME, localBranchSHA1, remoteBranchSHA1); cause = context.newCause(DISPLAY_NAME, false); } } return cause; } @DataBoundConstructor  GitHubBranchHashChangedEvent(); @Override GitHubBranchCause check(@Nonnull GitHubBranchDecisionContext context);  }
@Test public void branchChanged() throws IOException { commonExpectations(); when(remoteBranch.getSHA1()).thenReturn("57uy57u57u57u57u"); assertThat( event.check(newGitHubBranchDecisionContext() .withLocalBranch(localBranch) .withBranchTrigger(trigger) .withLocalRepo(localRepo) .withRemoteBranch(remoteBranch) .withListener(listener) .build()), notNullValue() ); }
@Test public void branchCreated() throws IOException { commonExpectations(); assertThat( event.check(newGitHubBranchDecisionContext() .withLocalBranch(null) .withBranchTrigger(trigger) .withLocalRepo(localRepo) .withRemoteBranch(remoteBranch) .withListener(listener) .build()), nullValue() ); }
@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() ); }