Skip to content

Commit 240c9df

Browse files
committed
Test stubs.
1 parent ae7e4ff commit 240c9df

File tree

13 files changed

+227
-149
lines changed

13 files changed

+227
-149
lines changed

core/src/main/java/com/github/api/v2/services/impl/BaseGitHubService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.gson.JsonDeserializationContext;
2424
import com.google.gson.JsonDeserializer;
2525
import com.google.gson.JsonElement;
26+
import com.google.gson.JsonObject;
2627
import com.google.gson.JsonParseException;
2728
import com.google.gson.JsonParser;
2829
import com.google.gson.reflect.TypeToken;
@@ -126,9 +127,14 @@ public Language deserialize(JsonElement arg0, Type arg1,
126127
return builder;
127128
}
128129

129-
protected JsonElement unmarshall(InputStream jsonContent) {
130+
protected JsonObject unmarshall(InputStream jsonContent) {
130131
try {
131-
return parser.parse(new InputStreamReader(jsonContent));
132+
JsonElement element = parser.parse(new InputStreamReader(jsonContent));
133+
if (element.isJsonObject()) {
134+
return element.getAsJsonObject();
135+
} else {
136+
throw new GitHubException("Unknown content found in response." + element);
137+
}
132138
} catch (Exception e) {
133139
throw new GitHubException(e);
134140
} finally {

core/src/main/java/com/github/api/v2/services/impl/CommitServiceImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.github.api.v2.services.constant.GitHubApiUrls;
1111
import com.github.api.v2.services.constant.ParameterNames;
1212
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
13-
import com.google.gson.JsonElement;
13+
import com.google.gson.JsonObject;
1414
import com.google.gson.reflect.TypeToken;
1515

1616
/**
@@ -24,28 +24,28 @@ public class CommitServiceImpl extends BaseGitHubService implements
2424
public Commit getCommit(String userName, String repositoryName, String sha) {
2525
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.CommitApiUrls.GET_COMMIT_URL);
2626
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.SHA, sha).buildUrl();
27-
JsonElement json = unmarshall(callApiGet(apiUrl));
27+
JsonObject json = unmarshall(callApiGet(apiUrl));
2828

29-
return unmarshall(new TypeToken<Commit>(){}, json.getAsJsonObject().get("commit"));
29+
return unmarshall(new TypeToken<Commit>(){}, json.get("commit"));
3030
}
3131

3232
@Override
3333
public List<Commit> getCommits(String userName, String repositoryName,
3434
String branch) {
3535
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.CommitApiUrls.GET_COMMITS_URL);
3636
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.BRANCH, branch).buildUrl();
37-
JsonElement json = unmarshall(callApiGet(apiUrl));
37+
JsonObject json = unmarshall(callApiGet(apiUrl));
3838

39-
return unmarshall(new TypeToken<List<Commit>>(){}, json.getAsJsonObject().get("commits"));
39+
return unmarshall(new TypeToken<List<Commit>>(){}, json.get("commits"));
4040
}
4141

4242
@Override
4343
public List<Commit> getCommits(String userName, String repositoryName,
4444
String branch, String filePath) {
4545
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.CommitApiUrls.GET_COMMITS_FILE_URL);
4646
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.BRANCH, branch).withField(ParameterNames.FILE_PATH, filePath).buildUrl();
47-
JsonElement json = unmarshall(callApiGet(apiUrl));
47+
JsonObject json = unmarshall(callApiGet(apiUrl));
4848

49-
return unmarshall(new TypeToken<List<Commit>>(){}, json.getAsJsonObject().get("commits"));
49+
return unmarshall(new TypeToken<List<Commit>>(){}, json.get("commits"));
5050
}
5151
}

core/src/main/java/com/github/api/v2/services/impl/GistServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.github.api.v2.services.constant.GitHubApiUrls;
1212
import com.github.api.v2.services.constant.ParameterNames;
1313
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
14-
import com.google.gson.JsonElement;
14+
import com.google.gson.JsonObject;
1515
import com.google.gson.reflect.TypeToken;
1616

1717
/**
@@ -25,9 +25,9 @@ public class GistServiceImpl extends BaseGitHubService implements
2525
public Gist getGist(String gistId) {
2626
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.GistApiUrls.GET_GIST_URL);
2727
String apiUrl = builder.withField(ParameterNames.GIST_ID, gistId).buildUrl();
28-
JsonElement json = unmarshall(callApiGet(apiUrl));
28+
JsonObject json = unmarshall(callApiGet(apiUrl));
2929

30-
List<Gist> gists = unmarshall(new TypeToken<List<Gist>>(){}, json.getAsJsonObject().get("gists"));
30+
List<Gist> gists = unmarshall(new TypeToken<List<Gist>>(){}, json.get("gists"));
3131
return (gists.isEmpty())? null : gists.get(0);
3232
}
3333

@@ -42,8 +42,8 @@ public InputStream getGistContent(String gistId, String fileName) {
4242
public List<Gist> getUserGists(String userName) {
4343
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.GistApiUrls.GET_USER_GISTS_URL);
4444
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).buildUrl();
45-
JsonElement json = unmarshall(callApiGet(apiUrl));
45+
JsonObject json = unmarshall(callApiGet(apiUrl));
4646

47-
return unmarshall(new TypeToken<List<Gist>>(){}, json.getAsJsonObject().get("gists"));
47+
return unmarshall(new TypeToken<List<Gist>>(){}, json.get("gists"));
4848
}
4949
}

core/src/main/java/com/github/api/v2/services/impl/IssueServiceImpl.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import com.github.api.v2.services.constant.GitHubApiUrls;
1515
import com.github.api.v2.services.constant.ParameterNames;
1616
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
17-
import com.google.gson.JsonElement;
17+
import com.google.gson.JsonObject;
1818
import com.google.gson.reflect.TypeToken;
1919

2020
/**
@@ -31,19 +31,19 @@ public void addComment(String userName, String repositoryName,
3131
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.ISSUE_NUMBER, String.valueOf(issueNumber)).buildUrl();
3232
Map<String, String> parameters = new HashMap<String, String>();
3333
parameters.put(ParameterNames.COMMENT, comment);
34-
JsonElement json = unmarshall(callApiPost(apiUrl, parameters));
34+
JsonObject json = unmarshall(callApiPost(apiUrl, parameters));
3535

36-
unmarshall(new TypeToken<Comment>(){}, json.getAsJsonObject().get("comment"));
36+
unmarshall(new TypeToken<Comment>(){}, json.get("comment"));
3737
}
3838

3939
@Override
4040
public List<String> addLabel(String userName, String repositoryName,
4141
int issueNumber, String label) {
4242
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.ADD_LABEL_URL);
4343
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.LABEL, label).withField(ParameterNames.ISSUE_NUMBER, String.valueOf(issueNumber)).buildUrl();
44-
JsonElement json = unmarshall(callApiPost(apiUrl, EMPTY_PARAMETERS));
44+
JsonObject json = unmarshall(callApiPost(apiUrl, EMPTY_PARAMETERS));
4545

46-
return unmarshall(new TypeToken<List<String>>(){}, json.getAsJsonObject().get("labels"));
46+
return unmarshall(new TypeToken<List<String>>(){}, json.get("labels"));
4747
}
4848

4949
@Override
@@ -70,48 +70,48 @@ public Issue getIssue(String userName, String repositoryName,
7070
int issueNumber) {
7171
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.GET_ISSUE_URL);
7272
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.ISSUE_NUMBER, String.valueOf(issueNumber)).buildUrl();
73-
JsonElement json = unmarshall(callApiGet(apiUrl));
73+
JsonObject json = unmarshall(callApiGet(apiUrl));
7474

75-
return unmarshall(new TypeToken<Issue>(){}, json.getAsJsonObject().get("issue"));
75+
return unmarshall(new TypeToken<Issue>(){}, json.get("issue"));
7676
}
7777

7878
@Override
7979
public List<Comment> getIssueComments(String userName,
8080
String repositoryName, int issueNumber) {
8181
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.GET_ISSUE_COMMENTS_URL);
8282
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.ISSUE_NUMBER, String.valueOf(issueNumber)).buildUrl();
83-
JsonElement json = unmarshall(callApiGet(apiUrl));
83+
JsonObject json = unmarshall(callApiGet(apiUrl));
8484

85-
return unmarshall(new TypeToken<List<Comment>>(){}, json.getAsJsonObject().get("comments"));
85+
return unmarshall(new TypeToken<List<Comment>>(){}, json.get("comments"));
8686
}
8787

8888
@Override
8989
public List<String> getIssueLabels(String userName, String repositoryName) {
9090
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.GET_ISSUE_LABELS_URL);
9191
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).buildUrl();
92-
JsonElement json = unmarshall(callApiGet(apiUrl));
92+
JsonObject json = unmarshall(callApiGet(apiUrl));
9393

94-
return unmarshall(new TypeToken<List<String>>(){}, json.getAsJsonObject().get("labels"));
94+
return unmarshall(new TypeToken<List<String>>(){}, json.get("labels"));
9595
}
9696

9797
@Override
9898
public List<Issue> getIssues(String userName, String repositoryName,
9999
State state) {
100100
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.GET_ISSUES_URL);
101101
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withFieldEnum(ParameterNames.STATE, state).buildUrl();
102-
JsonElement json = unmarshall(callApiGet(apiUrl));
102+
JsonObject json = unmarshall(callApiGet(apiUrl));
103103

104-
return unmarshall(new TypeToken<List<Issue>>(){}, json.getAsJsonObject().get("issues"));
104+
return unmarshall(new TypeToken<List<Issue>>(){}, json.get("issues"));
105105
}
106106

107107
@Override
108108
public List<String> removeLabel(String userName, String repositoryName,
109109
int issueNumber, String label) {
110110
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.REMOVE_LABEL_URL);
111111
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.LABEL, label).withField(ParameterNames.ISSUE_NUMBER, String.valueOf(issueNumber)).buildUrl();
112-
JsonElement json = unmarshall(callApiPost(apiUrl, EMPTY_PARAMETERS));
112+
JsonObject json = unmarshall(callApiPost(apiUrl, EMPTY_PARAMETERS));
113113

114-
return unmarshall(new TypeToken<List<String>>(){}, json.getAsJsonObject().get("labels"));
114+
return unmarshall(new TypeToken<List<String>>(){}, json.get("labels"));
115115
}
116116

117117
@Override
@@ -127,9 +127,9 @@ public List<Issue> searchIssues(String userName, String repositoryName,
127127
State state, String keyword) {
128128
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.SEARCH_ISSUES_URL);
129129
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withFieldEnum(ParameterNames.STATE, state).withField(ParameterNames.KEYWORD, keyword).buildUrl();
130-
JsonElement json = unmarshall(callApiGet(apiUrl));
130+
JsonObject json = unmarshall(callApiGet(apiUrl));
131131

132-
return unmarshall(new TypeToken<List<Issue>>(){}, json.getAsJsonObject().get("issues"));
132+
return unmarshall(new TypeToken<List<Issue>>(){}, json.get("issues"));
133133
}
134134

135135
@Override

core/src/main/java/com/github/api/v2/services/impl/NetworkServiceImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.github.api.v2.services.constant.GitHubApiUrls;
1212
import com.github.api.v2.services.constant.ParameterNames;
1313
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
14-
import com.google.gson.JsonElement;
14+
import com.google.gson.JsonObject;
1515
import com.google.gson.reflect.TypeToken;
1616

1717
/**
@@ -26,26 +26,26 @@ public List<Commit> getNetworkData(String userName, String repositoryName,
2626
String networkHash) {
2727
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.NetworkApiUrls.GET_NETWORK_DATA_URL);
2828
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withParameter(ParameterNames.NET_HASH, networkHash).buildUrl();
29-
JsonElement json = unmarshall(callApiGet(apiUrl));
29+
JsonObject json = unmarshall(callApiGet(apiUrl));
3030

31-
return unmarshall(new TypeToken<List<Commit>>(){}, json.getAsJsonObject().get("commits"));
31+
return unmarshall(new TypeToken<List<Commit>>(){}, json.get("commits"));
3232
}
3333

3434
@Override
3535
public List<Commit> getNetworkData(String userName, String repositoryName,
3636
String networkHash, int startIndex, int endIndex) {
3737
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.NetworkApiUrls.GET_NETWORK_DATA_URL);
3838
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withParameter(ParameterNames.NET_HASH, networkHash).withParameter(ParameterNames.START_INDEX, String.valueOf(startIndex)).withParameter(ParameterNames.END_INDEX, String.valueOf(endIndex)).buildUrl();
39-
JsonElement json = unmarshall(callApiGet(apiUrl));
39+
JsonObject json = unmarshall(callApiGet(apiUrl));
4040

41-
return unmarshall(new TypeToken<List<Commit>>(){}, json.getAsJsonObject().get("commits"));
41+
return unmarshall(new TypeToken<List<Commit>>(){}, json.get("commits"));
4242
}
4343

4444
@Override
4545
public Network getNetworkMeta(String userName, String repositoryName) {
4646
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.NetworkApiUrls.GET_NETWORK_META_URL);
4747
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).buildUrl();
48-
JsonElement json = unmarshall(callApiGet(apiUrl));
48+
JsonObject json = unmarshall(callApiGet(apiUrl));
4949

5050
return unmarshall(new TypeToken<Network>(){}, json);
5151
}

core/src/main/java/com/github/api/v2/services/impl/ObjectServiceImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.github.api.v2.services.constant.GitHubApiUrls;
1313
import com.github.api.v2.services.constant.ParameterNames;
1414
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
15-
import com.google.gson.JsonElement;
15+
import com.google.gson.JsonObject;
1616
import com.google.gson.reflect.TypeToken;
1717

1818
/**
@@ -27,19 +27,19 @@ public Blob getBlob(String userName, String repositoryName, String treeSha,
2727
String filePath) {
2828
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.ObjectApiUrls.GET_BLOBS_URL);
2929
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.SHA, treeSha).withField(ParameterNames.FILE_PATH, filePath).buildUrl();
30-
JsonElement json = unmarshall(callApiGet(apiUrl));
30+
JsonObject json = unmarshall(callApiGet(apiUrl));
3131

32-
return unmarshall(new TypeToken<Blob>(){}, json.getAsJsonObject().get("blob"));
32+
return unmarshall(new TypeToken<Blob>(){}, json.get("blob"));
3333
}
3434

3535
@Override
3636
public List<Blob> getBlobs(String userName, String repositoryName,
3737
String treeSha) {
3838
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.ObjectApiUrls.GET_BLOBS_URL);
3939
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.SHA, treeSha).buildUrl();
40-
JsonElement json = unmarshall(callApiGet(apiUrl));
40+
JsonObject json = unmarshall(callApiGet(apiUrl));
4141

42-
return unmarshall(new TypeToken<List<Blob>>(){}, json.getAsJsonObject().get("blobs"));
42+
return unmarshall(new TypeToken<List<Blob>>(){}, json.get("blobs"));
4343
}
4444

4545
@Override
@@ -55,8 +55,8 @@ public List<Tree> getTree(String userName, String repositoryName,
5555
String treeSha) {
5656
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.ObjectApiUrls.GET_TREE_URL);
5757
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).withField(ParameterNames.SHA, treeSha).buildUrl();
58-
JsonElement json = unmarshall(callApiGet(apiUrl));
58+
JsonObject json = unmarshall(callApiGet(apiUrl));
5959

60-
return unmarshall(new TypeToken<List<Tree>>(){}, json.getAsJsonObject().get("tree"));
60+
return unmarshall(new TypeToken<List<Tree>>(){}, json.get("tree"));
6161
}
6262
}

0 commit comments

Comments
 (0)