Skip to content

Commit

Permalink
StashRepositoryTest: No need to stub getCiSkipPhrases() everywhere
Browse files Browse the repository at this point in the history
Mockito returns null for unstubbed methods on mocked classes. It's OK for
getCiSkipPhrases() to return null, as it's only used in isSkipBuild()
that can deal with null.

Stub getCiSkipPhrases() only when it's relevant to the test.
  • Loading branch information
proski authored and jakub-bochenski committed Jul 11, 2019
1 parent d56749e commit d28f5ad
Showing 1 changed file with 0 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public void getTargetPullRequests_returns_empty_list_for_no_pull_requests() thro
@Test
public void getTargetPullRequests_accepts_open_pull_requests() throws Exception {
when(stashApiClient.getPullRequests()).thenReturn(pullRequestList);
when(trigger.getCiSkipPhrases()).thenReturn("NO TEST");

assertThat(stashRepository.getTargetPullRequests(), contains(pullRequest));
}
Expand All @@ -171,7 +170,6 @@ public void getTargetPullRequests_skips_null_state_pull_requests() throws Except
@Test
public void getTargetPullRequests_accepts_matching_branches() throws Exception {
when(stashApiClient.getPullRequests()).thenReturn(pullRequestList);
when(trigger.getCiSkipPhrases()).thenReturn("NO TEST");
when(trigger.getTargetBranchesToBuild()).thenReturn("release/.*,feature/.*,testing/.*");

assertThat(stashRepository.getTargetPullRequests(), contains(pullRequest));
Expand All @@ -180,7 +178,6 @@ public void getTargetPullRequests_accepts_matching_branches() throws Exception {
@Test
public void getTargetPullRequests_accepts_matching_branches_with_padding() throws Exception {
when(stashApiClient.getPullRequests()).thenReturn(pullRequestList);
when(trigger.getCiSkipPhrases()).thenReturn("NO TEST");
when(trigger.getTargetBranchesToBuild())
.thenReturn("\trelease/.*, \n\tfeature/.* \r\n, testing/.*\r");

Expand All @@ -190,7 +187,6 @@ public void getTargetPullRequests_accepts_matching_branches_with_padding() throw
@Test
public void getTargetPullRequests_skips_mismatching_branches() throws Exception {
when(stashApiClient.getPullRequests()).thenReturn(pullRequestList);
when(trigger.getCiSkipPhrases()).thenReturn("NO TEST");
when(trigger.getTargetBranchesToBuild()).thenReturn("release/.*,testing/.*");

assertThat(stashRepository.getTargetPullRequests(), empty());
Expand All @@ -200,7 +196,6 @@ public void getTargetPullRequests_skips_mismatching_branches() throws Exception
public void getTargetPullRequests_accepts_any_branch_if_Branches_to_Build_is_empty()
throws Exception {
when(stashApiClient.getPullRequests()).thenReturn(pullRequestList);
when(trigger.getCiSkipPhrases()).thenReturn("NO TEST");
when(trigger.getTargetBranchesToBuild()).thenReturn("");

assertThat(stashRepository.getTargetPullRequests(), contains(pullRequest));
Expand All @@ -210,7 +205,6 @@ public void getTargetPullRequests_accepts_any_branch_if_Branches_to_Build_is_emp
public void getTargetPullRequests_accepts_any_branch_if_Branches_to_Build_is_null()
throws Exception {
when(stashApiClient.getPullRequests()).thenReturn(pullRequestList);
when(trigger.getCiSkipPhrases()).thenReturn("NO TEST");
when(trigger.getTargetBranchesToBuild()).thenReturn(null);

assertThat(stashRepository.getTargetPullRequests(), contains(pullRequest));
Expand Down Expand Up @@ -488,7 +482,6 @@ public void getTargetPullRequests_returns_empty_if_getPullRequests_throws() thro
public void getTargetPullRequests_skips_pull_request_if_getPullRequestComments_throws()
throws Exception {
when(stashApiClient.getPullRequests()).thenReturn(pullRequestList);
when(trigger.getCiSkipPhrases()).thenReturn("NO TEST");
when(stashApiClient.getPullRequestComments(any(), any(), any()))
.thenThrow(new StashApiException("cannot read PR comments"));

Expand Down

0 comments on commit d28f5ad

Please sign in to comment.