diff options
author | Kevin Sawicki | 2012-12-03 21:35:04 +0000 |
---|---|---|
committer | Kevin Sawicki | 2013-04-30 15:00:59 +0000 |
commit | 76a5242f8971f7649ab44422b5dd11aa9cad3a3a (patch) | |
tree | 488e07e5670fe41ca0207706c6ae5b08ebe0f54a /org.eclipse.egit.github.core.tests | |
parent | 7717433453a8572834091cc1a530298a810f1016 (diff) | |
download | egit-github-76a5242f8971f7649ab44422b5dd11aa9cad3a3a.tar.gz egit-github-76a5242f8971f7649ab44422b5dd11aa9cad3a3a.tar.xz egit-github-76a5242f8971f7649ab44422b5dd11aa9cad3a3a.zip |
Add service support for contents API
Change-Id: Ia4d927b0e33fa9a1d5432d304513a79c20882669
Diffstat (limited to 'org.eclipse.egit.github.core.tests')
4 files changed, 173 insertions, 2 deletions
diff --git a/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF b/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF index 9fefe3d2..fdc29ed4 100644 --- a/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF @@ -5,8 +5,8 @@ Bundle-SymbolicName: org.eclipse.egit.github.core.tests Bundle-Version: 2.4.0.qualifier Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: com.google.gson;version="[1.6.0,2.0.0)", - com.google.gson.reflect;version="[1.6.0,2.0.0)", +Import-Package: com.google.gson;version="[1.6.0,2.2.0]", + com.google.gson.reflect;version="[1.6.0,2.2.0]", org.eclipse.egit.github.core;version="[2.4.0,2.5.0)", org.eclipse.egit.github.core.client;version="[2.4.0,2.5.0)", org.eclipse.egit.github.core.event;version="[2.4.0,2.5.0)", diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java index 9808ae6c..d6a2c49f 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java @@ -32,6 +32,7 @@ import org.junit.runners.Suite.SuiteClasses; CommitStatusTest.class, // CommitTest.class, // CommitUserTest.class, // + ContentsServiceTest.class, // ContributorTest.class, // DataServiceTest.class, // DateFormatterTest.class, // @@ -79,6 +80,7 @@ import org.junit.runners.Suite.SuiteClasses; RepositoryBranchTest.class, // RepositoryCommitCompareTest.class, // RepositoryCommitTest.class, // + RepositoryContentsTest.class, // RepositoryHookResponseTest.class, // RepositoryHookTest.class, // RepositoryIdTest.class, // diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContentsServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContentsServiceTest.java new file mode 100644 index 00000000..a1771446 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContentsServiceTest.java @@ -0,0 +1,116 @@ +/****************************************************************************** + * Copyright (c) 2012 GitHub Inc. + * 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: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; + +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.service.ContentsService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +/** + * Unit tests of {@link ContentsService} + */ +@RunWith(MockitoJUnitRunner.class) +public class ContentsServiceTest { + + @Mock + private GitHubClient client; + + @Mock + private GitHubResponse response; + + private ContentsService service; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(client).get(any(GitHubRequest.class)); + service = new ContentsService(client); + } + + /** + * Get readme for null repository + * + * @throws Exception + */ + @Test(expected = IllegalArgumentException.class) + public void getReadmeNullRepository() throws Exception { + service.getReadme(null); + } + + /** + * Get readme for repository + * + * @throws Exception + */ + @Test + public void getReadme() throws Exception { + RepositoryId repo = new RepositoryId("o", "n"); + service.getReadme(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/readme"); + verify(client).get(request); + } + + /** + * Get contents for null repository + * + * @throws Exception + */ + @Test(expected = IllegalArgumentException.class) + public void getContentsNullRepository() throws Exception { + service.getContents(null); + } + + /** + * Get contents at root in repository + * + * @throws Exception + */ + @Test + public void getRootContents() throws Exception { + RepositoryId repo = new RepositoryId("o", "n"); + service.getContents(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/contents"); + verify(client).get(request); + } + + /** + * Get contents at path in repository + * + * @throws Exception + */ + @Test + public void getContents() throws Exception { + RepositoryId repo = new RepositoryId("o", "n"); + service.getContents(repo, "a/b"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/contents/a/b"); + verify(client).get(request); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryContentsTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryContentsTest.java new file mode 100644 index 00000000..5568ed38 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryContentsTest.java @@ -0,0 +1,53 @@ +/****************************************************************************** + * Copyright (c) 2012 GitHub Inc. + * 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: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.RepositoryContents; +import org.junit.Test; + +/** + * Unit tests of {@link RepositoryContents} + */ +public class RepositoryContentsTest { + + /** + * Test default state of contents + */ + @Test + public void defaultState() { + RepositoryContents contents = new RepositoryContents(); + assertNull(contents.getContent()); + assertNull(contents.getEncoding()); + assertNull(contents.getName()); + assertNull(contents.getPath()); + assertNull(contents.getSha()); + assertEquals(0, contents.getSize()); + assertNull(contents.getType()); + } + + /** + * Test updating contents fields + */ + @Test + public void updateFields() { + RepositoryContents contents = new RepositoryContents(); + assertEquals("abc", contents.setContent("abc").getContent()); + assertEquals("64", contents.setEncoding("64").getEncoding()); + assertEquals("file.txt", contents.setName("file.txt").getName()); + assertEquals("a/b", contents.setPath("a/b").getPath()); + assertEquals("abcdef", contents.setSha("abcdef").getSha()); + assertEquals(12345, contents.setSize(12345).getSize()); + assertEquals("dir", contents.setType("dir").getType()); + } +} |