Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e7e2fe8b3de1bdcebbb8e476ed089eed6bf7b24d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/******************************************************************************
 *  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 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  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);
	}
}

Back to the top