Skip to content

Commit

Permalink
Merge pull request jenkinsci#627 from jenkinsci/fix-test
Browse files Browse the repository at this point in the history
Fix test GhprbSimpleStatusTest.testUseDefaultContext
  • Loading branch information
bjoernhaeuser authored Feb 9, 2018
2 parents 956862f + a560568 commit c15d510
Showing 1 changed file with 4 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,15 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.ArrayList;

import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import java.util.ArrayList;
// Needed for testing commit context
/*
import hudson.Extension;
import hudson.model.TaskListener;
import hudson.model.FreeStyleProject;
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtension;
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtensionDescriptor;
import org.jenkinsci.plugins.ghprb.extensions.GhprbGlobalExtension;
import org.jenkinsci.plugins.ghprb.extensions.GhprbProjectExtension;
import org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage;
import java.util.ArrayList;
import java.util.List;
*/

@RunWith(MockitoJUnitRunner.class)
public class GhprbSimpleStatusTest extends org.jenkinsci.plugins.ghprb.extensions.GhprbExtension {

Expand All @@ -50,8 +37,6 @@ public class GhprbSimpleStatusTest extends org.jenkinsci.plugins.ghprb.extension

private GhprbTrigger trigger;

//private FreeStyleProject project;

@Before
public void setUp() throws Exception {
trigger = GhprbTestUtil.getTrigger(null);
Expand Down Expand Up @@ -102,74 +87,24 @@ public void testDoesNotSendEmptyContext() throws Exception {
verifyNoMoreInteractions(ghprbPullRequest);
}

/*
public static final GhprbSimpleStatusDescriptor TEST_DESCRIPTOR = new DescriptorImpl();
public static final class DescriptorImpl extends GhprbSimpleStatusDescriptor
implements GhprbGlobalExtension, GhprbProjectExtension {
@Override
public String getDisplayName() {
return "Update commit status during build";
}
public String getTriggeredStatusDefault(GhprbSimpleStatus local) {
return "Build triggered. sha1 is original commit.";
}
public String getStatusUrlDefault(GhprbSimpleStatus local) {
return "http://someserver.com";
}
public String getStartedStatusDefault(GhprbSimpleStatus local) {
return "getStartedStatus";
}
public Boolean getAddTestResultsDefault(GhprbSimpleStatus local) {
return true;
}
public List<GhprbBuildResultMessage> getCompletedStatusDefault(GhprbSimpleStatus local) {
return new ArrayList<GhprbBuildResultMessage>(0);
}
public String getCommitStatusContextDefault(GhprbSimpleStatus local) {
return "testing context";
}
public Boolean getShowMatrixStatusDefault(GhprbSimpleStatus local){
return true;
}
public boolean addIfMissing() {
return false;
}
} */

@Test
public void testUseDefaultContext() throws Exception {
String mergedMessage = "Build triggered. sha1 is original commit.";
String mergedMessage = "Build triggered for original commit.";
String statusUrl = "http://someserver.com";
String context = "testing context";
given(ghprbPullRequest.getHead()).willReturn("sha");
given(ghprbPullRequest.isMergeable()).willReturn(false);

GhprbSimpleStatus globalStatus =
new GhprbSimpleStatus(true, context, statusUrl, "test1", "test2", false, new ArrayList<GhprbBuildResultMessage>(0));
new GhprbSimpleStatus(true, context, statusUrl, "test1", "test2", false, new ArrayList<GhprbBuildResultMessage>(0));
GhprbTrigger.getDscp().getExtensions().add(globalStatus);
GhprbTrigger localTrigger = GhprbTestUtil.getTrigger(null);

GhprbSimpleStatus status = new GhprbSimpleStatus("");
GhprbSimpleStatus statusSpy = spy(status);

statusSpy.onBuildTriggered(trigger.getActualProject(), "sha", false, 1, ghRepository);
//verify(ghRepository).createCommitStatus(eq("sha"), eq(GHCommitState.PENDING), eq(statusUrl), eq(mergedMessage), eq(context));
verify(ghRepository).createCommitStatus(eq("sha"), eq(GHCommitState.PENDING), eq(""), eq(mergedMessage), isNull(String.class));

//statusSpy.onBuildStart(<what goes here>, <can listener be null>, ghRepository);
//verify(ghRepository).createCommitStatus(eq("sha"), eq(GHCommitState.PENDING), eq(statusUrl), eq(mergedMessage), eq(context));

verifyNoMoreInteractions(ghRepository);

verifyNoMoreInteractions(ghprbPullRequest);
Expand Down

0 comments on commit c15d510

Please sign in to comment.