summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Trutz2011-04-26 17:47:03 (EDT)
committerChristian Trutz2011-04-26 17:51:52 (EDT)
commita3944c5d1c10a0f178ced3aa5bd3ec95f6ffd7fc (patch)
tree35ca06ed0a023684b30ce92ce0c041b005628a28
parent9e2b2c9b75ddec007dedbc5c5885be3628e3dd6b (diff)
downloadegit-github-a3944c5d1c10a0f178ced3aa5bd3ec95f6ffd7fc.zip
egit-github-a3944c5d1c10a0f178ced3aa5bd3ec95f6ffd7fc.tar.gz
egit-github-a3944c5d1c10a0f178ced3aa5bd3ec95f6ffd7fc.tar.bz2
Unit tests for GistService completedrefs/changes/57/3257/1
Change-Id: Id12bb29f606a98b21285920ffe7fa90ce93989ec Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
-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 0a2fa4c..7b301b4 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 ed2cc7d..0d95bae 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());
+ }
}