diff options
| author | Christian Trutz | 2011-04-12 21:55:10 +0000 |
|---|---|---|
| committer | Chris Aniszczyk | 2011-04-15 15:17:22 +0000 |
| commit | 2a0c5f8949b0493b77369e4fa9d1244519982333 (patch) | |
| tree | 7e9fe50f6d2b4e80281c12b2b5ec29b433e24924 | |
| parent | 06efd7f9b306a4ed3b99057498faae21b12f1893 (diff) | |
| download | egit-github-2a0c5f8949b0493b77369e4fa9d1244519982333.tar.gz egit-github-2a0c5f8949b0493b77369e4fa9d1244519982333.tar.xz egit-github-2a0c5f8949b0493b77369e4fa9d1244519982333.zip | |
More unit tests for IssueService
Change-Id: Id74b4433756fe103ac7f368b66c2887e15f0d132
Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
3 files changed, 91 insertions, 8 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java index 6254a573..5c36136b 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java @@ -55,22 +55,22 @@ public class IssueService { /** * Issue open state filter value */ - public static final String STATE_OPEN = "open"; + public static final String STATE_OPEN = "open"; //$NON-NLS-1$ /** * Issue closed state filter value */ - public static final String STATE_CLOSED = "closed"; + public static final String STATE_CLOSED = "closed"; //$NON-NLS-1$ /** * Issue body field name */ - public static final String FIELD_BODY = "body"; + public static final String FIELD_BODY = "body"; //$NON-NLS-1$ /** * Issue title field name */ - public static final String FIELD_TITLE = "title"; + public static final String FIELD_TITLE = "title"; //$NON-NLS-1$ private GitHubClient client; @@ -118,6 +118,9 @@ public class IssueService { */ public List<Comment> getComments(String user, String repository, String id) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(id, "Id cannot be null"); //$NON-NLS-1$ StringBuilder builder = new StringBuilder( IGitHubConstants.SEGMENT_REPOS); builder.append('/').append(user).append('/').append(repository); @@ -141,6 +144,8 @@ public class IssueService { */ public List<Issue> getIssues(String user, String repository, Map<String, String> filterData) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ StringBuilder builder = new StringBuilder( IGitHubConstants.SEGMENT_REPOS); builder.append('/').append(user).append('/').append(repository); @@ -188,12 +193,14 @@ public class IssueService { */ public Issue createIssue(String user, String repository, Issue issue) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS); uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES).append( IGitHubConstants.SUFFIX_JSON); - Map<String, String> params = createIssueMap(issue); + Map<String, String> params = issue != null ? createIssueMap(issue) : null; return this.client.post(uri.toString(), params, Issue.class); } diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index b30a2264..edc0d052 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -14,5 +14,6 @@ Require-Bundle: org.junit4;bundle-version="4.5.0", org.eclipse.core.runtime;bundle-version="3.5.0" Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", + com.google.gson.reflect;version="1.6.0", org.mockito;version="1.8.4", org.mockito.runners;version="1.8.4" diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java index 2e76bd4e..3d765ee2 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java @@ -10,7 +10,10 @@ *******************************************************************************/ 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; @@ -19,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 IssueService} */ @@ -42,18 +47,88 @@ public class IssueServiceTest { } @Test(expected = AssertionFailedException.class) - public void getIssue_NullUser() throws IOException{ + public void getIssue_NullUser() throws IOException { issueService.getIssue(null, "not null", "not null"); } @Test(expected = AssertionFailedException.class) - public void getIssue_NullRepository() throws IOException{ + public void getIssue_NullRepository() throws IOException { issueService.getIssue("not null", null, "not null"); } @Test(expected = AssertionFailedException.class) - public void getIssue_NullId() throws IOException{ + public void getIssue_NullId() throws IOException { issueService.getIssue("not null", "not null", null); } + @Test + public void getIssue_OK() throws IOException { + issueService.getIssue("test_user", "test_repository", "test_id"); + verify(gitHubClient).get( + "/repos/test_user/test_repository/issues/test_id.json", + Issue.class); + } + + @Test(expected = AssertionFailedException.class) + public void getComments_NullUser() throws IOException { + issueService.getComments(null, "not null", "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void getComments_NullRepository() throws IOException { + issueService.getComments("not null", null, "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void getComments_NullId() throws IOException { + issueService.getComments("not null", "not null", null); + } + + @Test + public void getComments_OK() throws IOException { + issueService.getComments("test_user", "test_repository", "test_id"); + TypeToken<List<Comment>> commentToken = new TypeToken<List<Comment>>() { + }; + verify(gitHubClient) + .get("/repos/test_user/test_repository/issues/test_id/comments.json", + commentToken.getType()); + } + + @Test(expected = AssertionFailedException.class) + public void getIssues_NullUser() throws IOException { + issueService.getIssues(null, "not null", null); + } + + @Test(expected = AssertionFailedException.class) + public void getIssues_NullRepository() throws IOException { + issueService.getIssues("not null", null, null); + } + + @Test + public void getIssues_OK() throws IOException { + issueService.getIssues("test_user", "test_repository", null); + TypeToken<List<Issue>> issuesToken = new TypeToken<List<Issue>>() { + }; + verify(gitHubClient).get( + "/repos/test_user/test_repository/issues.json", null, + issuesToken.getType()); + } + + @Test(expected = AssertionFailedException.class) + public void createIssue_NullUser() throws IOException { + issueService.createIssue(null, "not null", null); + } + + @Test(expected = AssertionFailedException.class) + public void createIssue_NullRepository() throws IOException { + issueService.createIssue("not null", null, null); + } + + @Test + public void createIssue_NullIssue() throws IOException { + issueService.createIssue("test_user", "test_repository", null); + verify(gitHubClient).post( + "/repos/test_user/test_repository/issues.json", null, + Issue.class); + } } |
