summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Trutz2011-04-26 15:29:47 (EDT)
committer Christian Trutz2011-04-26 15:29:47 (EDT)
commit9e2b2c9b75ddec007dedbc5c5885be3628e3dd6b (patch)
treee2705947ed41d31392cc8a5c6dab53d5eb586fe6
parent6fead739c1c3ba4fba54aba78050ddeaf7f4fa4d (diff)
downloadegit-github-9e2b2c9b75ddec007dedbc5c5885be3628e3dd6b.zip
egit-github-9e2b2c9b75ddec007dedbc5c5885be3628e3dd6b.tar.gz
egit-github-9e2b2c9b75ddec007dedbc5c5885be3628e3dd6b.tar.bz2
Unit tests for GistServicerefs/changes/56/3256/1
Change-Id: I74702f0208baed0dd7903bd6bbfbffb28a54283d Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java6
-rw-r--r--org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistServiceTest.java49
2 files changed, 54 insertions, 1 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 4153d2a..0a2fa4c 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
@@ -58,6 +58,7 @@ public class GistService {
* @throws IOException
*/
public List<Gist> getGists(String user) throws IOException {
+ Assert.isNotNull(user, "User cannot be null");
StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_USERS);
uri.append('/').append(user);
uri.append(IGitHubConstants.SEGMENT_GISTS).append(
@@ -75,11 +76,14 @@ public class GistService {
* @throws IOException
*/
public Gist createGist(Gist gist) throws IOException {
+ Assert.isNotNull(gist, "Gist cannot be null");
StringBuilder uri = new StringBuilder();
User user = gist.getUser();
if (user != null) {
+ String login = user.getLogin();
+ Assert.isNotNull(login, "User login name cannot be null");
uri.append(IGitHubConstants.SEGMENT_USERS);
- uri.append('/').append(user.getLogin());
+ uri.append('/').append(login);
}
uri.append(IGitHubConstants.SEGMENT_GISTS).append(
IGitHubConstants.SUFFIX_JSON);
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 6f05d4b..ed2cc7d 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,6 +13,7 @@ package org.eclipse.mylyn.github.internal;
import static org.mockito.Mockito.verify;
import java.io.IOException;
+import java.util.List;
import org.eclipse.core.runtime.AssertionFailedException;
import org.junit.Before;
@@ -21,6 +22,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import com.google.gson.reflect.TypeToken;
+
/**
* Unit tests for {@link GistService}
*/
@@ -54,4 +57,50 @@ public class GistServiceTest {
verify(gitHubClient).get("/gists/1.json", Gist.class);
}
+ @Test(expected = AssertionFailedException.class)
+ public void getGists_NullUser() throws IOException {
+ gistService.getGists(null);
+ }
+
+ @Test
+ public void getGists_OK() throws IOException {
+ gistService.getGists("test_user");
+ TypeToken<List<Gist>> gistsToken = new TypeToken<List<Gist>>() {
+ };
+ verify(gitHubClient).get("/users/test_user/gists.json",
+ gistsToken.getType());
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void createGist_NullGist() throws IOException {
+ gistService.createGist(null);
+ }
+
+ @Test
+ public void createGist_NullUser() throws IOException {
+ Gist gist = new Gist();
+ gist.setUser(null);
+ gistService.createGist(gist);
+ verify(gitHubClient).post("/gists.json", gist, Gist.class);
+ }
+
+ @Test
+ public void createGist_NonNullUser() throws IOException {
+ Gist gist = new Gist();
+ User user = new User();
+ user.setLogin("test_user");
+ gist.setUser(user);
+ gistService.createGist(gist);
+ verify(gitHubClient).post("/users/test_user/gists.json", gist,
+ Gist.class);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void createGist_NonNullUser_NullLogin() throws IOException {
+ Gist gist = new Gist();
+ User user = new User();
+ user.setLogin(null);
+ gist.setUser(user);
+ gistService.createGist(gist);
+ }
}