File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed
main/java/org/kohsuke/github
test/java/org/kohsuke/github Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 22
33import com .fasterxml .jackson .annotation .JsonCreator ;
44import com .fasterxml .jackson .annotation .JsonProperty ;
5+ import com .fasterxml .jackson .databind .JsonMappingException ;
56import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
67import java .io .IOException ;
78import java .net .URL ;
89import java .util .Collection ;
10+ import java .util .Objects ;
911
1012import 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 /**
Original file line number Diff line number Diff line change 99import java .util .ArrayList ;
1010import 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 ;
1414import static org .junit .Assert .*;
1515import 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
You can’t perform that action at this time.
0 commit comments