diff options
author | Christian Trutz | 2011-04-29 18:06:40 +0000 |
---|---|---|
committer | Chris Aniszczyk | 2011-05-03 16:50:11 +0000 |
commit | f6cf2b0b4621e01b5909280b1b42256a0710afef (patch) | |
tree | bbe0ef4a1a1d392a76c6503ab9a3bdaaf12feb99 | |
parent | fbc0628fe40135927c0c5c397918654211614cda (diff) | |
download | egit-github-f6cf2b0b4621e01b5909280b1b42256a0710afef.tar.gz egit-github-f6cf2b0b4621e01b5909280b1b42256a0710afef.tar.xz egit-github-f6cf2b0b4621e01b5909280b1b42256a0710afef.zip |
Unit tests for PullRequestService
Change-Id: Idca802fadabb7489e13250361c48a57dfb8003d6
Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
6 files changed, 115 insertions, 10 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java index 57ccf496..8507280d 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java @@ -10,11 +10,6 @@ *******************************************************************************/ package org.eclipse.mylyn.github.internal; -import com.google.gson.FieldNamingPolicy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; - import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -38,6 +33,12 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.protocol.Protocol; +import org.eclipse.core.runtime.Assert; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; /** * Client class for interacting with GitHub HTTP/JSON API. @@ -76,6 +77,7 @@ public class GitHubClient { * @param configuration */ public GitHubClient(HostConfiguration configuration) { + Assert.isNotNull(configuration, "Configuration cannot be null"); //$NON-NLS-1$ this.hostConfig = configuration; } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java index c22219f3..37622ada 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java @@ -71,9 +71,11 @@ public class PullRequestService { throws IOException { Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ Assert.isNotNull(id, "Id cannot be null"); //$NON-NLS-1$ + String repositoryId = repository.getId(); + Assert.isNotNull(repositoryId, "Repository id cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_V2_API); uri.append(IGitHubConstants.SEGMENT_PULLS); - uri.append('/').append(repository.getId()); + uri.append('/').append(repositoryId); uri.append('/').append(id); PullRequestWrapper wrapper = this.client.get(uri.toString(), PullRequestWrapper.class); diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index 5f1f7e71..16d752dc 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -17,5 +17,7 @@ Require-Bundle: org.eclipse.mylyn.github.core;bundle-version="0.1.0", Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", com.google.gson.reflect;version="1.6.0", + org.apache.commons.httpclient;version="3.1.0", org.mockito;version="1.8.4", - org.mockito.runners;version="1.8.4" + org.mockito.runners;version="1.8.4", + org.mockito.stubbing;version="1.8.4" diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GitHubClientTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GitHubClientTest.java new file mode 100755 index 00000000..088adb9f --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GitHubClientTest.java @@ -0,0 +1,27 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Christian Trutz
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Trutz - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.github.internal;
+
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class GitHubClientTest {
+
+ @Test(expected = AssertionFailedException.class)
+ public void constructor_NullArgument() {
+ new GitHubClient(null);
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java new file mode 100755 index 00000000..2b0b78c3 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java @@ -0,0 +1,70 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Christian Trutz
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Trutz - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.github.internal;
+
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * Tests for {@link PullRequestServiceTest}
+ */
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class PullRequestServiceTest {
+
+ @Mock
+ private GitHubClient gitHubClient;
+
+ @Mock
+ private Repository repository;
+
+ private PullRequestService pullRequestService;
+
+ @Before
+ public void before() {
+ pullRequestService = new PullRequestService(gitHubClient);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void constructor_NullArgument() {
+ new PullRequestService(null);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void getPullRequest_NullRepository() throws IOException {
+ pullRequestService.getPullRequest(null, "not null");
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void getPullRequest_NullId() throws IOException {
+ pullRequestService.getPullRequest(repository, null);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void getPullRequest_NullRepositoryId() throws IOException {
+ when(repository.getId()).thenReturn(null);
+ pullRequestService.getPullRequest(repository, "test_id");
+ }
+
+ @Test
+ public void getPullRequest_OK() throws IOException {
+ // the OK unit test is not possible with Mockito, but with JMOckit
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java index c20c5eac..cf4c4e93 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java @@ -13,17 +13,19 @@ package org.eclipse.mylyn.github.tests; import org.eclipse.mylyn.github.internal.GistServiceTest; +import org.eclipse.mylyn.github.internal.GitHubClientTest; import org.eclipse.mylyn.github.internal.IssueServiceTest; import org.eclipse.mylyn.github.internal.LabelServiceTest; import org.eclipse.mylyn.github.internal.MilestoneServiceTest; +import org.eclipse.mylyn.github.internal.PullRequestServiceTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ // -IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class, - GistServiceTest.class }) +@SuiteClasses({ GitHubClientTest.class, IssueServiceTest.class, + LabelServiceTest.class, MilestoneServiceTest.class, + GistServiceTest.class, PullRequestServiceTest.class }) public class AllHeadlessTests { } |