Skip to content

Commit

Permalink
Changed Exception Type
Browse files Browse the repository at this point in the history
Changed Exception type and added a comment
  • Loading branch information
Alex Taylor committed Nov 15, 2019
1 parent 6af796f commit 78ab5ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"));
}
}

Expand Down

0 comments on commit 78ab5ad

Please sign in to comment.