Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java9
-rw-r--r--org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistServiceTest.java58
2 files changed, 65 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java
index 0a2fa4cf..7b301b4f 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java
@@ -98,9 +98,11 @@ public class GistService {
* @throws IOException
*/
public Gist updateGist(Gist gist) throws IOException {
+ Assert.isNotNull(gist, "Gist cannot be null");
+ String repo = gist.getRepo();
+ Assert.isNotNull(repo, "Repository cannot be null");
StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS);
- uri.append('/').append(gist.getRepo())
- .append(IGitHubConstants.SUFFIX_JSON);
+ uri.append('/').append(repo).append(IGitHubConstants.SUFFIX_JSON);
return this.client.put(uri.toString(), gist, Gist.class);
}
@@ -114,6 +116,8 @@ public class GistService {
*/
public Comment createComment(String gistId, String comment)
throws IOException {
+ Assert.isNotNull(gistId, "Gist id cannot be null");
+ Assert.isNotNull(comment, "Gist comment cannot be null");
StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS);
uri.append('/').append(gistId);
uri.append(IGitHubConstants.SEGMENT_COMMENTS).append(
@@ -132,6 +136,7 @@ public class GistService {
* @throws IOException
*/
public List<Comment> getComments(String gistId) throws IOException {
+ Assert.isNotNull(gistId, "Gist id cannot be null");
StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS);
uri.append('/').append(gistId);
uri.append(IGitHubConstants.SEGMENT_COMMENTS).append(
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistServiceTest.java
index ed2cc7d7..0d95bae3 100644
--- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistServiceTest.java
+++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistServiceTest.java
@@ -13,7 +13,9 @@ package org.eclipse.mylyn.github.internal;
import static org.mockito.Mockito.verify;
import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.AssertionFailedException;
import org.junit.Before;
@@ -103,4 +105,60 @@ public class GistServiceTest {
gist.setUser(user);
gistService.createGist(gist);
}
+
+ @Test(expected = AssertionFailedException.class)
+ public void updateGist_NullGist() throws IOException {
+ gistService.updateGist(null);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void updateGist_NullRepository() throws IOException {
+ Gist gist = new Gist();
+ gist.setRepo(null);
+ gistService.updateGist(gist);
+ }
+
+ @Test
+ public void updateGist_OK() throws IOException {
+ Gist gist = new Gist();
+ gist.setRepo("test_repository");
+ gistService.updateGist(gist);
+ verify(gitHubClient).put("/gists/test_repository.json", gist,
+ Gist.class);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void createComment_NullGistId() throws IOException {
+ gistService.createComment(null, "not null");
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void createComment_NullComment() throws IOException {
+ gistService.createComment("not null", null);
+ }
+
+ @Test
+ public void createComment_OK() throws IOException {
+ gistService.createComment("1", "test_comment");
+
+ Map<String, String> params = new HashMap<String, String>(1, 1);
+ params.put(IssueService.FIELD_BODY, "test_comment");
+ verify(gitHubClient).post("/gists/1/comments.json", params,
+ Comment.class);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void getComments_NullGistId() throws IOException {
+ gistService.getComments(null);
+ }
+
+ @Test
+ public void getComments_OK() throws IOException {
+ gistService.getComments("1");
+
+ TypeToken<List<Comment>> commentsToken = new TypeToken<List<Comment>>() {
+ };
+ verify(gitHubClient).get("/gists/1/comments.json",
+ commentsToken.getType());
+ }
}

Back to the top