Skip to content

Commit 78ab5ad

Browse files
author
Alex Taylor
committed
Changed Exception Type
Changed Exception type and added a comment
1 parent 6af796f commit 78ab5ad

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/main/java/org/kohsuke/github/GHBranch.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.databind.JsonMappingException;
56
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
67
import java.io.IOException;
78
import java.net.URL;
89
import java.util.Collection;
10+
import java.util.Objects;
911

1012
import static org.kohsuke.github.Previews.*;
1113

@@ -27,12 +29,9 @@ public class GHBranch {
2729
private String protection_url;
2830

2931
@JsonCreator
30-
GHBranch(@JsonProperty("name") String name) throws Exception {
31-
if (name != null) {
32-
this.name = name;
33-
} else {
34-
throw new GHFileNotFoundException("Branch Not Found");
35-
}
32+
GHBranch(@JsonProperty(value = "name", required = true) String name) throws Exception {
33+
Objects.requireNonNull(name);
34+
this.name = name;
3635
}
3736

3837
/**

src/test/java/org/kohsuke/github/GHRepositoryTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import java.util.ArrayList;
1010
import java.util.List;
1111

12-
import static org.hamcrest.Matchers.contains;
13-
import static org.hamcrest.Matchers.is;
12+
import static org.hamcrest.Matchers.*;
13+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
1414
import static org.junit.Assert.*;
1515
import static org.junit.Assume.assumeFalse;
1616

@@ -56,13 +56,18 @@ public void getBranchNonExistentBut200Status() throws Exception {
5656
// Manually changed the returned status to 200 so dont take a new snapshot
5757
this.snapshotNotAllowed();
5858

59+
//This should *never* happen but with mocking it was discovered
5960
GHRepository repo = getRepository();
6061
try {
6162
GHBranch branch = repo.getBranch("test/NonExistent");
6263
fail();
6364
} catch (Exception e) {
6465
// I dont really love this but I wanted to get to the root wrapped cause
65-
assertEquals("Branch Not Found", e.getCause().getCause().getCause().getMessage());
66+
assertThat(e, instanceOf(IOException.class));
67+
assertThat(e.getMessage(),
68+
equalTo("Server returned HTTP response code: 200, message: 'OK' for URL: "
69+
+ mockGitHub.apiServer().baseUrl()
70+
+ "/repos/github-api-test-org/github-api/branches/test%2FNonExistent"));
6671
}
6772
}
6873

0 commit comments

Comments
 (0)