aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Trutz2011-04-19 18:13:07 (EDT)
committerChris Aniszczyk2011-04-19 18:46:36 (EDT)
commit76aaa01c65e8067327500ef3642b1a031c15b959 (patch)
treeb91e79d7956fefccdba01491c5a82e342e3b519c
parentd690df7fb5377a5760a62d7fd5a2ae6f2a65b6f9 (diff)
downloadegit-github-76aaa01c65e8067327500ef3642b1a031c15b959.zip
egit-github-76aaa01c65e8067327500ef3642b1a031c15b959.tar.gz
egit-github-76aaa01c65e8067327500ef3642b1a031c15b959.tar.bz2
Unit tests for MilestoneServicerefs/changes/75/3175/2
Change-Id: Ida629fecce02698eabb983cbc70cc38ca183160d Signed-off-by: Christian Trutz <christian.trutz@gmail.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java2
-rw-r--r--org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneServiceTest.java82
-rw-r--r--org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java3
3 files changed, 86 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java
index b9149a2..f61422e 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java
@@ -49,6 +49,8 @@ public class MilestoneService {
*/
public List<Milestone> getMilestones(String user, String repository,
String state) 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_MILESTONES).append(
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneServiceTest.java
new file mode 100644
index 0000000..d959a8e
--- /dev/null
+++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneServiceTest.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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.verify;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+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;
+
+import com.google.gson.reflect.TypeToken;
+
+/**
+ * Unit tests for {@link MilestoneService}
+ */
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class MilestoneServiceTest {
+
+ @Mock
+ private GitHubClient gitHubClient;
+
+ private MilestoneService milestoneService;
+
+ @Before
+ public void before() {
+ milestoneService = new MilestoneService(gitHubClient);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void constructor_NullArgument() {
+ new MilestoneService(null);
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void getMilestones_NullUser() throws IOException {
+ milestoneService.getMilestones(null, "not null", "not null");
+ }
+
+ @Test(expected = AssertionFailedException.class)
+ public void getMilestones_NullRepository() throws IOException {
+ milestoneService.getMilestones("not null", null, "not null");
+ }
+
+ @Test
+ public void getMilestones_NullState() throws IOException {
+ milestoneService.getMilestones("test_user", "test_repository", null);
+ TypeToken<List<Milestone>> milestonesToken = new TypeToken<List<Milestone>>() {
+ };
+ verify(gitHubClient).get(
+ "/repos/test_user/test_repository/milestones.json", null,
+ milestonesToken.getType());
+ }
+
+ @Test
+ public void getMilestones_OK() throws IOException {
+ milestoneService.getMilestones("test_user", "test_repository",
+ "test_state");
+ TypeToken<List<Milestone>> milestonesToken = new TypeToken<List<Milestone>>() {
+ };
+ verify(gitHubClient).get(
+ "/repos/test_user/test_repository/milestones.json",
+ Collections.singletonMap(IssueService.FILTER_STATE,
+ "test_state"), milestonesToken.getType());
+ }
+
+}
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 f782f2f..561b4e9 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
@@ -14,13 +14,14 @@ package org.eclipse.mylyn.github.tests;
import org.eclipse.mylyn.github.internal.IssueServiceTest;
import org.eclipse.mylyn.github.internal.LabelServiceTest;
+import org.eclipse.mylyn.github.internal.MilestoneServiceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ //
-IssueServiceTest.class, LabelServiceTest.class })
+IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class })
public class AllHeadlessTests {
}