diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index e457fc243d..e594b8fbea 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -1,8 +1,8 @@ package org.kohsuke.github; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - import java.io.IOException; import java.net.URL; import java.util.Collection; @@ -26,7 +26,15 @@ public class GHBranch { private boolean protection; private String protection_url; - + @JsonCreator + GHBranch(@JsonProperty("name") String name) throws Exception{ + if (name != null) { + this.name = name; + } + else{ + throw new GHFileNotFoundException("Branch Not Found"); + } + } public static class Commit { String sha; diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index bfcad7a3bf..c245b5cd4b 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -60,8 +60,9 @@ public void getBranchNonExistentBut200Status() throws Exception { GHBranch branch = repo.getBranch("test/NonExistent"); fail(); } - catch(GHFileNotFoundException e){ - assertEquals("{\"message\":\"Branch not found\",\"documentation_url\":\"https://developer.github.com/v3/repos/branches/#get-branch\"}", e.getMessage()); + catch(Exception e){ + //I dont really love this but I wanted to get to the root wrapped cause + assertEquals("Branch Not Found", e.getCause().getCause().getCause().getMessage()); } }