mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-05 15:50:59 +00:00
Changed Exception Type
Changed Exception type and added a comment
This commit is contained in:
@@ -2,10 +2,12 @@ package org.kohsuke.github;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.io.IOException;
|
||||
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 class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
// 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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user