diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 0cc9cdbdb3..c6b0cc1fd6 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -2,10 +2,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonMappingException; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.net.URL; import java.util.Collection; +import java.util.Objects; import static org.kohsuke.github.Previews.*; @@ -27,12 +29,9 @@ public class GHBranch { 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"); - } + GHBranch(@JsonProperty(value = "name", required = true) String name) throws Exception { + Objects.requireNonNull(name); + this.name = name; } /** diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index f72e99c976..306d4e0183 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -9,8 +9,8 @@ import java.util.ArrayList; import java.util.List; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.*; import static org.junit.Assume.assumeFalse; @@ -56,13 +56,18 @@ public void getBranchNonExistentBut200Status() throws Exception { // Manually changed the returned status to 200 so dont take a new snapshot this.snapshotNotAllowed(); + //This should *never* happen but with mocking it was discovered GHRepository repo = getRepository(); try { GHBranch branch = repo.getBranch("test/NonExistent"); fail(); } 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()); + assertThat(e, instanceOf(IOException.class)); + assertThat(e.getMessage(), + equalTo("Server returned HTTP response code: 200, message: 'OK' for URL: " + + mockGitHub.apiServer().baseUrl() + + "/repos/github-api-test-org/github-api/branches/test%2FNonExistent")); } }