Skip to content

Commit

Permalink
Add more Differential tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandella committed Jun 29, 2015
1 parent 905fce4 commit dd431a6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import hudson.EnvVars;
import junit.framework.TestCase;
import net.sf.json.JSONNull;
import net.sf.json.JSONObject;
import net.sf.json.groovy.JsonSlurper;
import org.junit.Test;
Expand Down Expand Up @@ -59,6 +60,40 @@ public void testGetBuildStartedMessage() throws Exception {
assertTrue(differential.getBuildStartedMessage(new EnvVars()).contains("Build started"));
}

@Test
public void testGetBranch() {
assertEquals("a-branch-name", differential.getBranch());
}

@Test
public void testGetBranchWithEmptyResponse() throws Exception {
JSONObject empty = new JSONObject();
empty.put("branch", JSONNull.getInstance());
Differential diff = new Differential(empty);
assertEquals("(none)", diff.getBranch());
}

@Test
public void testGetBranchWithInvalidResponse() throws Exception {
JSONObject invalid = new JSONObject();
invalid.put("branch", true);
Differential diff = new Differential(invalid);
assertEquals("(unknown)", diff.getBranch());
}

@Test
public void testGetBaseCommit() throws Exception {
assertEquals("aaaaaaaa", differential.getBaseCommit());
}

@Test
public void testGetSummaryMessage() throws Exception {
String message = differential.getSummaryMessage("http://example.com");
assertTrue(message.contains("ai@uber.com"));
assertTrue(message.contains("http://example.com"));
assertTrue(message.contains("aiden"));
}

private JSONObject getValidQueryResponse() throws IOException {
InputStream input = getClass().getResourceAsStream(
"validDifferentialQueryResponse.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"revisionID": "not-a-real-id"
"revisionID": "not-a-real-id",
"branch": "a-branch-name",
"sourceControlBaseRevision": "aaaaaaaa",
"authorName": "aiden",
"authorEmail": "ai@uber.com"
}

0 comments on commit dd431a6

Please sign in to comment.