diff options
| author | Christian Trutz | 2011-04-20 21:27:25 +0000 |
|---|---|---|
| committer | Christian Trutz | 2011-04-20 21:27:25 +0000 |
| commit | a643de5a62bb60c825def6d1c6911863386ef538 (patch) | |
| tree | 4e1866fd96e911c7240fda3f280de65ef8efaf1b | |
| parent | 1c9e970df80170d28dc664e2085ee3552e6722ab (diff) | |
| download | egit-github-a643de5a62bb60c825def6d1c6911863386ef538.tar.gz egit-github-a643de5a62bb60c825def6d1c6911863386ef538.tar.xz egit-github-a643de5a62bb60c825def6d1c6911863386ef538.zip | |
Unit tests for GistService#getGist
Change-Id: I49cad2ab4fe81fce5e4068f1956f5ca403667a8d
Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
3 files changed, 61 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 9fcd1d6b..4153d2a6 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 @@ -44,6 +44,7 @@ public class GistService { * @throws IOException */ public Gist getGist(String id) throws IOException { + Assert.isNotNull(id, "Gist id cannot be null"); StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS); uri.append('/').append(id).append(IGitHubConstants.SUFFIX_JSON); return this.client.get(uri.toString(), Gist.class); 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 new file mode 100644 index 00000000..6f05d4b8 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistServiceTest.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * 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 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; + +/** + * Unit tests for {@link GistService} + */ +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class GistServiceTest { + + @Mock + private GitHubClient gitHubClient; + + private GistService gistService; + + @Before + public void before() { + gistService = new GistService(gitHubClient); + } + + @Test(expected = AssertionFailedException.class) + public void constructor_NullArgument() { + new GistService(null); + } + + @Test(expected = AssertionFailedException.class) + public void getGist_NullId() throws IOException { + gistService.getGist(null); + } + + @Test + public void getGist_OK() throws IOException { + gistService.getGist("1"); + verify(gitHubClient).get("/gists/1.json", Gist.class); + } + +} 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 561b4e91..c20c5eac 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 @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.github.tests; +import org.eclipse.mylyn.github.internal.GistServiceTest; import org.eclipse.mylyn.github.internal.IssueServiceTest; import org.eclipse.mylyn.github.internal.LabelServiceTest; import org.eclipse.mylyn.github.internal.MilestoneServiceTest; @@ -21,7 +22,8 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ // -IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class }) +IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class, + GistServiceTest.class }) public class AllHeadlessTests { } |
