diff options
author | Matthias Sohn | 2018-03-10 00:40:25 +0000 |
---|---|---|
committer | Matthias Sohn | 2018-03-16 23:55:55 +0000 |
commit | e6d330a2817fe1a65e420e9c8677a1577fc550ea (patch) | |
tree | e06f7ac903651a92304625ef1b02f4fed2ab7bed | |
parent | 44e57f5a2041abfe7591069c3032a7e869adfda4 (diff) | |
download | egit-github-e6d330a2817fe1a65e420e9c8677a1577fc550ea.tar.gz egit-github-e6d330a2817fe1a65e420e9c8677a1577fc550ea.tar.xz egit-github-e6d330a2817fe1a65e420e9c8677a1577fc550ea.zip |
Remove deprecated WatcherService
Use StargazerService instead.
Change-Id: I4ebd88489830e3fba22a20c142df20b66cfa46e2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
5 files changed, 1 insertions, 627 deletions
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 432e6c77..c325e219 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 @@ -121,7 +121,6 @@ import org.junit.runners.Suite.SuiteClasses; UserServiceTest.class, // UserTest.class, // WatchPayloadTest.class, // - WatcherServiceTest.class // }) public class AllHeadlessTests { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/WatcherServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/WatcherServiceTest.java deleted file mode 100644 index 18d8e5a9..00000000 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/WatcherServiceTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2011 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.assertNotNull; -import static org.junit.Assert.assertTrue; -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.Repository; -import org.eclipse.egit.github.core.RepositoryId; -import org.eclipse.egit.github.core.User; -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.client.PageIterator; -import org.eclipse.egit.github.core.service.WatcherService; -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 WatcherService} - */ -@RunWith(MockitoJUnitRunner.class) -public class WatcherServiceTest { - - @Mock - private GitHubClient client; - - @Mock - private GitHubResponse response; - - private WatcherService service; - - private RepositoryId repo; - - /** - * Test case set up - * - * @throws IOException - */ - @Before - public void before() throws IOException { - doReturn(response).when(client).get(any(GitHubRequest.class)); - service = new WatcherService(client); - repo = new RepositoryId("o", "n"); - } - - /** - * Create service using default constructor - */ - @Test - public void constructor() { - assertNotNull(new WatcherService().getClient()); - } - - /** - * Get watchers - * - * @throws IOException - */ - @Test - public void getWatchers() throws IOException { - service.getWatchers(repo); - GitHubRequest request = new GitHubRequest(); - request.setUri(Utils.page("/repos/o/n/watchers")); - verify(client).get(request); - } - - /** - * Get watched - * - * @throws IOException - */ - @Test - public void getCurrentWatched() throws IOException { - service.getWatched(); - GitHubRequest request = new GitHubRequest(); - request.setUri(Utils.page("/user/watched")); - verify(client).get(request); - } - - /** - * Get watched with null name - * - * @throws IOException - */ - @Test(expected = IllegalArgumentException.class) - public void getWatchedNullName() throws IOException { - service.getWatched(null); - } - - /** - * Get watched with empty name - * - * @throws IOException - */ - @Test(expected = IllegalArgumentException.class) - public void getWatchedEmptyName() throws IOException { - service.getWatched(""); - } - - /** - * Get watched - * - * @throws IOException - */ - @Test - public void getWatched() throws IOException { - service.getWatched("auser"); - GitHubRequest request = new GitHubRequest(); - request.setUri(Utils.page("/users/auser/watched")); - verify(client).get(request); - } - - /** - * Is watching - * - * @throws IOException - */ - @Test - public void isWatching() throws IOException { - service.isWatching(repo); - GitHubRequest request = new GitHubRequest(); - request.setUri("/user/watched/o/n"); - verify(client).get(request); - } - - /** - * Watch repository - * - * @throws IOException - */ - @Test - public void watch() throws IOException { - service.watch(repo); - verify(client).put("/user/watched/o/n"); - } - - /** - * Unwatch repository - * - * @throws IOException - */ - @Test - public void unwatch() throws IOException { - service.unwatch(repo); - verify(client).delete("/user/watched/o/n"); - } - - /** - * Page watchers - * - * @throws IOException - */ - @Test - public void pageWatchers() throws IOException { - PageIterator<User> iter = service.pageWatchers(repo); - assertNotNull(iter); - assertTrue(iter.hasNext()); - assertEquals(Utils.page("/repos/o/n/watchers"), iter.getRequest() - .generateUri()); - } - - /** - * Page watched - * - * @throws IOException - */ - @Test - public void pageCurrentWatched() throws IOException { - PageIterator<Repository> iter = service.pageWatched(); - assertNotNull(iter); - assertTrue(iter.hasNext()); - assertEquals(Utils.page("/user/watched"), iter.getRequest() - .generateUri()); - } - - /** - * Page watched - * - * @throws IOException - */ - @Test - public void pageWatched() throws IOException { - PageIterator<Repository> iter = service.pageWatched("auser"); - assertNotNull(iter); - assertTrue(iter.hasNext()); - assertEquals(Utils.page("/users/auser/watched"), iter.getRequest() - .generateUri()); - } -} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTests.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTests.java index 398e5be0..7c45b70f 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTests.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTests.java @@ -32,8 +32,7 @@ import org.junit.runners.Suite.SuiteClasses; PullRequestTest.class, RepositoryTest.class, TeamTest.class, - UserTest.class, - WatcherTest.class }) + UserTest.class}) public class LiveTests { } diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/WatcherTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/WatcherTest.java deleted file mode 100644 index efbef24e..00000000 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/WatcherTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2011 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.live; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.eclipse.egit.github.core.Repository; -import org.eclipse.egit.github.core.RepositoryId; -import org.eclipse.egit.github.core.User; -import org.eclipse.egit.github.core.service.WatcherService; -import org.junit.Test; - -/** - * Unit tests of {@link WatcherService} - */ -public class WatcherTest extends LiveTest { - - /** - * Test getting watchers of a repository - * - * @throws Exception - */ - @Test - public void getWatchers() throws Exception { - WatcherService service = new WatcherService(client); - List<User> watchers = service.getWatchers(new RepositoryId("defunkt", - "dotjs")); - assertNotNull(watchers); - assertFalse(watchers.isEmpty()); - for (User watcher : watchers) { - assertNotNull(watcher); - assertNotNull(watcher.getLogin()); - } - } - - /** - * Test getting repositories watched by a user - * - * @throws Exception - */ - @Test - public void getWatched() throws Exception { - WatcherService service = new WatcherService(client); - List<Repository> watched = service.getWatched("defunkt"); - assertNotNull(watched); - assertFalse(watched.isEmpty()); - for (Repository repo : watched) { - assertNotNull(repo); - assertNotNull(repo.getName()); - assertNotNull(repo.getOwner()); - } - } - - /** - * Test if current user is watching a repository - * - * @throws Exception - */ - @Test - public void isWatching() throws Exception { - checkUser(); - WatcherService service = new WatcherService(client); - List<Repository> watched = service.getWatched(); - assertNotNull(watched); - assertFalse(watched.isEmpty()); - for (Repository repo : watched) { - assertNotNull(repo); - assertNotNull(repo.getName()); - assertNotNull(repo.getOwner()); - assertTrue(service.isWatching(repo)); - } - } -} diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/WatcherService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/WatcherService.java deleted file mode 100644 index 1d41c348..00000000 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/WatcherService.java +++ /dev/null @@ -1,332 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2011 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.service; - -import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS; -import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USER; -import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USERS; -import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_WATCHED; -import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_WATCHERS; -import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST; -import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE; - -import java.io.IOException; -import java.util.List; - -import org.eclipse.egit.github.core.IRepositoryIdProvider; -import org.eclipse.egit.github.core.Repository; -import org.eclipse.egit.github.core.User; -import org.eclipse.egit.github.core.client.GitHubClient; -import org.eclipse.egit.github.core.client.PageIterator; -import org.eclipse.egit.github.core.client.PagedRequest; - -import com.google.gson.reflect.TypeToken; - -/** - * Service class for dealing with users watching GitHub repositories. - * - * @see <a href="http://developer.github.com/v3/repos/watching">GitHub watcher - * API documentation</a> - * @deprecated use {@link StargazerService} instead - */ -@Deprecated -public class WatcherService extends GitHubService { - - /** - * Create watcher service - */ - public WatcherService() { - super(); - } - - /** - * Create watcher service - * - * @param client - */ - public WatcherService(GitHubClient client) { - super(client); - } - - /** - * Create page watcher request - * - * @param repository - * @param start - * @param size - * @return request - * @deprecated use {@link StargazerService#createStargazerRequest} - */ - protected PagedRequest<User> createWatcherRequest( - IRepositoryIdProvider repository, int start, int size) { - String id = getId(repository); - PagedRequest<User> request = createPagedRequest(start, size); - StringBuilder uri = new StringBuilder(SEGMENT_REPOS); - uri.append('/').append(id); - uri.append(SEGMENT_WATCHERS); - request.setUri(uri); - request.setType(new TypeToken<List<User>>() { - }.getType()); - return request; - } - - /** - * Get user watching given repository - * - * @param repository - * @return non-null but possibly empty list of users - * @throws IOException - * @deprecated use {@link StargazerService#getStargazers} instead - */ - public List<User> getWatchers(IRepositoryIdProvider repository) - throws IOException { - PagedRequest<User> request = createWatcherRequest(repository, - PAGE_FIRST, PAGE_SIZE); - return getAll(request); - } - - /** - * Page watches of given repository - * - * @param repository - * @return page iterator - * @deprecated use {@link StargazerService#pageStargazers} - */ - public PageIterator<User> pageWatchers(IRepositoryIdProvider repository) { - return pageWatchers(repository, PAGE_SIZE); - } - - /** - * Page watches of given repository - * - * @param repository - * @param size - * @return page iterator - * @deprecated use {@link StargazerService#pageStargazers} - */ - public PageIterator<User> pageWatchers(IRepositoryIdProvider repository, - int size) { - return pageWatchers(repository, PAGE_FIRST, size); - } - - /** - * Page watches of given repository - * - * @param repository - * @param start - * @param size - * @return page iterator - * @deprecated use {@link StargazerService#pageStargazers} - */ - public PageIterator<User> pageWatchers(IRepositoryIdProvider repository, - int start, int size) { - PagedRequest<User> request = createWatcherRequest(repository, start, - size); - return createPageIterator(request); - } - - /** - * Create page watched request - * - * @param user - * @param start - * @param size - * @return request - * @deprecated use {@link StargazerService#createStarredRequest} - */ - protected PagedRequest<Repository> createWatchedRequest(String user, - int start, int size) { - if (user == null) - throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$ - if (user.length() == 0) - throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$ - - PagedRequest<Repository> request = createPagedRequest(start, size); - StringBuilder uri = new StringBuilder(SEGMENT_USERS); - uri.append('/').append(user); - uri.append(SEGMENT_WATCHED); - request.setUri(uri); - request.setType(new TypeToken<List<Repository>>() { - }.getType()); - return request; - } - - /** - * Create page watched request - * - * @param start - * @param size - * @return request - * @deprecated use {@link StargazerService#createStarredRequest} - */ - protected PagedRequest<Repository> createWatchedRequest(int start, int size) { - PagedRequest<Repository> request = createPagedRequest(start, size); - request.setUri(SEGMENT_USER + SEGMENT_WATCHED); - request.setType(new TypeToken<List<Repository>>() { - }.getType()); - return request; - } - - /** - * Get repositories watched by the given user - * - * @param user - * @return non-null but possibly empty list of repositories - * @throws IOException - * @deprecated use {@link StargazerService#getStarred} - */ - public List<Repository> getWatched(String user) throws IOException { - PagedRequest<Repository> request = createWatchedRequest(user, - PAGE_FIRST, PAGE_SIZE); - return getAll(request); - } - - /** - * Page repositories being watched by given user - * - * @param user - * @return page iterator - * @throws IOException - * @deprecated use {@link StargazerService#pageStarred} - */ - public PageIterator<Repository> pageWatched(String user) throws IOException { - return pageWatched(user, PAGE_SIZE); - } - - /** - * Page repositories being watched by given user - * - * @param user - * @param size - * @return page iterator - * @throws IOException - * @deprecated use {@link StargazerService#pageStarred} - */ - public PageIterator<Repository> pageWatched(String user, int size) - throws IOException { - return pageWatched(user, PAGE_FIRST, size); - } - - /** - * Page repositories being watched by given user - * - * @param user - * @param start - * @param size - * @return page iterator - * @throws IOException - * @deprecated use {@link StargazerService#pageStarred} - */ - public PageIterator<Repository> pageWatched(String user, int start, int size) - throws IOException { - PagedRequest<Repository> request = createWatchedRequest(user, start, - size); - return createPageIterator(request); - } - - /** - * Get repositories watched by the currently authenticated user - * - * @return non-null but possibly empty list of repositories - * @throws IOException - * @deprecated use {@link StargazerService#getStarred} - */ - public List<Repository> getWatched() throws IOException { - PagedRequest<Repository> request = createWatchedRequest(PAGE_FIRST, - PAGE_SIZE); - return getAll(request); - } - - /** - * Page repositories being watched by the currently authenticated user - * - * @return page iterator - * @throws IOException - * @deprecated use {@link StargazerService#pageStarred} - */ - public PageIterator<Repository> pageWatched() throws IOException { - return pageWatched(PAGE_SIZE); - } - - /** - * Page repositories being watched by the currently authenticated user - * - * @param size - * @return page iterator - * @throws IOException - * @deprecated use {@link StargazerService#pageStarred} - */ - public PageIterator<Repository> pageWatched(int size) throws IOException { - return pageWatched(PAGE_FIRST, size); - } - - /** - * Page repositories being watched by the currently authenticated user - * - * @param start - * @param size - * @return page iterator - * @throws IOException - * @deprecated use {@link StargazerService#pageStarred} - */ - public PageIterator<Repository> pageWatched(int start, int size) - throws IOException { - PagedRequest<Repository> request = createWatchedRequest(start, size); - return createPageIterator(request); - } - - /** - * Is currently authenticated user watching given repository? - * - * @param repository - * @return true if watch, false otherwise - * @throws IOException - * @deprecated use {@link StargazerService#isStarring} - */ - public boolean isWatching(IRepositoryIdProvider repository) - throws IOException { - String id = getId(repository); - StringBuilder uri = new StringBuilder(SEGMENT_USER); - uri.append(SEGMENT_WATCHED); - uri.append('/').append(id); - return check(uri.toString()); - } - - /** - * Add currently authenticated user as a watcher of the given repository - * - * @param repository - * @throws IOException - * @deprecated use {@link StargazerService#star} - */ - public void watch(IRepositoryIdProvider repository) throws IOException { - String id = getId(repository); - StringBuilder uri = new StringBuilder(SEGMENT_USER); - uri.append(SEGMENT_WATCHED); - uri.append('/').append(id); - client.put(uri.toString()); - } - - /** - * Remove currently authenticated user as a watcher of the given repository - * - * @param repository - * @throws IOException - * @deprecated use {@link StargazerService#unstar} - */ - public void unwatch(IRepositoryIdProvider repository) throws IOException { - String id = getId(repository); - StringBuilder uri = new StringBuilder(SEGMENT_USER); - uri.append(SEGMENT_WATCHED); - uri.append('/').append(id); - client.delete(uri.toString()); - } -} |