From 74087e9a09cec9f91d2f50bc7031456a0225a37c Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Fri, 15 Apr 2011 22:46:46 +0200 Subject: Unit tests for IssueService#editIssue Change-Id: I080a8c4ad3cf70512bc0431e6e83a0dd04aa169a Signed-off-by: Christian Trutz --- .../mylyn/github/internal/IssueService.java | 43 ++++++++++++---------- .../mylyn/github/internal/IssueServiceTest.java | 37 ++++++++++++++++++- .../.settings/egit-github.launch | 4 +- 3 files changed, 62 insertions(+), 22 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 5c36136b..8ef12472 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 @@ -22,7 +22,7 @@ import org.eclipse.core.runtime.Assert; /** * Issue service class for listing, searching, and fetching {@link Issue} * objects using a {@link GitHubClient}. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class IssueService { @@ -76,7 +76,7 @@ public class IssueService { /** * Create issue service - * + * * @param client * cannot be null */ @@ -87,7 +87,7 @@ public class IssueService { /** * Get issue - * + * * @param user * @param repository * @param id @@ -109,7 +109,7 @@ public class IssueService { /** * Get an issue's comments - * + * * @param user * @param repository * @param id @@ -135,7 +135,7 @@ public class IssueService { /** * Get a list of {@link Issue} objects that match the specified filter data - * + * * @param user * @param repository * @param filterData @@ -165,26 +165,28 @@ public class IssueService { */ protected Map createIssueMap(Issue issue) { Map params = new HashMap(); - params.put(FIELD_BODY, issue.getBody()); - params.put(FIELD_TITLE, issue.getTitle()); - User assignee = issue.getAssignee(); - if (assignee != null) - params.put(FILTER_ASSIGNEE, assignee.getName()); + if (issue != null) { + params.put(FIELD_BODY, issue.getBody()); + params.put(FIELD_TITLE, issue.getTitle()); + User assignee = issue.getAssignee(); + if (assignee != null) + params.put(FILTER_ASSIGNEE, assignee.getName()); - Milestone milestone = issue.getMilestone(); - if (milestone != null) { - int number = milestone.getNumber(); - if (number > 0) - params.put(FILTER_MILESTONE, Integer.toString(number)); - else - params.put(FILTER_MILESTONE, ""); //$NON-NLS-1$ + Milestone milestone = issue.getMilestone(); + if (milestone != null) { + int number = milestone.getNumber(); + if (number > 0) + params.put(FILTER_MILESTONE, Integer.toString(number)); + else + params.put(FILTER_MILESTONE, ""); //$NON-NLS-1$ + } } return params; } /** * Create issue - * + * * @param user * @param repository * @param issue @@ -200,7 +202,7 @@ public class IssueService { uri.append(IGitHubConstants.SEGMENT_ISSUES).append( IGitHubConstants.SUFFIX_JSON); - Map params = issue != null ? createIssueMap(issue) : null; + Map params = createIssueMap(issue); return this.client.post(uri.toString(), params, Issue.class); } @@ -215,6 +217,9 @@ public class IssueService { */ public Issue editIssue(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$ + Assert.isNotNull(issue, "Issue 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); 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 3d765ee2..a6103216 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 @@ -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; @@ -128,7 +130,40 @@ public class IssueServiceTest { public void createIssue_NullIssue() throws IOException { issueService.createIssue("test_user", "test_repository", null); verify(gitHubClient).post( - "/repos/test_user/test_repository/issues.json", null, + "/repos/test_user/test_repository/issues.json", + new HashMap(), Issue.class); + } + + @Test(expected = AssertionFailedException.class) + public void editIssue_NullUser() throws IOException { + issueService.editIssue(null, "not null", null); + } + + @Test(expected = AssertionFailedException.class) + public void editIssue_NullRepository() throws IOException { + issueService.editIssue("not null", null, null); + } + + @Test(expected = AssertionFailedException.class) + public void editIssue_NullIssue() throws IOException { + issueService.editIssue("not null", "not null", null); + } + + @Test + public void editIssue_OK() throws IOException { + Issue issue = new Issue(); + issue.setNumber(1); + issue.setTitle("test_title"); + issue.setBody("test_body"); + issue.setState("test_state"); + issueService.editIssue("test_user", "test_repository", issue); + + Map params = new HashMap(); + params.put(IssueService.FIELD_TITLE, "test_title"); + params.put(IssueService.FIELD_BODY, "test_body"); + params.put(IssueService.FILTER_STATE, "test_state"); + verify(gitHubClient).put( + "/repos/test_user/test_repository/issues/1.json", params, Issue.class); } } diff --git a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch index f26dbc81..e94fee4f 100644 --- a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch +++ b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch @@ -12,7 +12,7 @@ - + @@ -49,7 +49,7 @@ - + -- cgit v1.2.3