diff options
author | Thomas Wolf | 2018-05-08 19:30:37 +0000 |
---|---|---|
committer | Thomas Wolf | 2018-05-08 19:30:37 +0000 |
commit | a039ba440106f7fcc4e6fa718771ce3a8d822377 (patch) | |
tree | c0dd453cd7f348e9ae31a397c1409dee9bf66b7c /org.eclipse.egit.github.core.tests/src/org | |
parent | 5fad06251c0b68aa4743fbfde25ad474d73f1a46 (diff) | |
download | egit-github-a039ba440106f7fcc4e6fa718771ce3a8d822377.tar.gz egit-github-a039ba440106f7fcc4e6fa718771ce3a8d822377.tar.xz egit-github-a039ba440106f7fcc4e6fa718771ce3a8d822377.zip |
Fix Repository.getWatchers(); add Repository.getStars()
Per [1] it appears that the JSON returned by Github changed,
apparently already in 2012. What Github shows today as the number of
"watchers" is stored in field "subscribers_count". Field "watchers"
actually is a copy of "stargazers_count" (as is "watchers_count").
So add fields "stargazersCount" and "subscribersCount", but keep the
legacy "watchers" field to be able to deal with old serialized (via
Gson or via Java serialization) objects.
Add tests, including a new test for Gson de-serialization. The test
data in test_repo.json is anonymized actual output for an existing
repository obtained from the Github API as of 2018-05-08.
[1] https://developer.github.com/changes/2012-09-05-watcher-api/
Bug: 534440
Change-Id: I1faba649986ab6ed9e367bfefdb0bbe2fbaf7071
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.github.core.tests/src/org')
-rw-r--r-- | org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java index 5506d231..f0eb3ec2 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java @@ -15,10 +15,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.util.Date; import org.eclipse.egit.github.core.Repository; import org.eclipse.egit.github.core.User; +import org.eclipse.egit.github.core.client.GsonUtils; import org.junit.Test; /** @@ -53,6 +59,7 @@ public class RepositoryTest { assertNull(repo.getSvnUrl()); assertNull(repo.getUrl()); assertEquals(0, repo.getWatchers()); + assertEquals(0, repo.getStars()); assertFalse(repo.isFork()); assertFalse(repo.isHasDownloads()); assertFalse(repo.isHasIssues()); @@ -93,6 +100,7 @@ public class RepositoryTest { assertEquals("svn://", repo.setSvnUrl("svn://").getSvnUrl()); assertEquals("url://", repo.setUrl("url://").getUrl()); assertEquals(200, repo.setWatchers(200).getWatchers()); + assertEquals(42, repo.setStars(42).getStars()); assertTrue(repo.setFork(true).isFork()); assertTrue(repo.setHasDownloads(true).isHasDownloads()); assertTrue(repo.setHasIssues(true).isHasIssues()); @@ -168,4 +176,15 @@ public class RepositoryTest { repo.setOwner(new User().setLogin("tuser")); assertEquals("tuser/myproject", repo.generateId()); } + + @Test + public void fromJson() throws IOException { + try (Reader r = new BufferedReader(new InputStreamReader ( + this.getClass().getResourceAsStream("test_repo.json"), + StandardCharsets.UTF_8))) { + Repository repo = GsonUtils.fromJson(r, Repository.class); + assertEquals(9,repo.getWatchers()); + assertEquals(21, repo.getStars()); + } + } } |