Skip to content

Commit d7c8675

Browse files
committed
Restore ContentIntegrationTest GHCommit tests
1 parent 048b84b commit d7c8675

File tree

3 files changed

+70
-44
lines changed

3 files changed

+70
-44
lines changed

src/main/java/org/kohsuke/github/GHCommit.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public ShortInfo() {
5757
// Empty constructor required for Jackson binding
5858
};
5959

60+
/**
61+
* Instantiates a new short info.
62+
*
63+
* @param commit
64+
* the commit
65+
*/
66+
ShortInfo(GitCommit commit) {
67+
// Inherited copy constructor, used for bridge method from {@link GitCommit},
68+
// which is used in {@link GHContentUpdateResponse}) to {@link GHCommit}.
69+
super(commit);
70+
}
71+
6072
/**
6173
* Gets the parent SHA 1 s.
6274
*

src/main/java/org/kohsuke/github/GitCommit.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ public GitCommit() {
6868
// empty constructor for Jackson binding
6969
};
7070

71+
/**
72+
* Instantiates a new git commit.
73+
*
74+
* @param commit
75+
* the commit
76+
*/
77+
GitCommit(GitCommit commit) {
78+
// copy constructor used to cast to GitCommit.ShortInfo and from there
79+
// to GHCommit, for testing purposes
80+
this.owner = commit.getOwner();
81+
this.sha = commit.getSha();
82+
this.node_id = commit.getNodeId();
83+
this.url = commit.getUrl();
84+
this.html_url = commit.getHtmlUrl();
85+
this.author = commit.getAuthor();
86+
this.committer = commit.getCommitter();
87+
this.message = commit.getMessage();
88+
this.verification = commit.getVerification();
89+
this.tree = commit.getTree();
90+
this.parents = commit.getParents();
91+
}
92+
7193
/**
7294
* Gets owner.
7395
*
@@ -247,4 +269,13 @@ GitCommit wrapUp(GHRepository owner) {
247269
return this;
248270
}
249271

272+
/**
273+
* For test purposes only.
274+
*
275+
* @return Equivalent GHCommit
276+
*/
277+
GHCommit toGHCommit() {
278+
return new GHCommit(new GHCommit.ShortInfo(this));
279+
}
280+
250281
}

src/test/java/org/kohsuke/github/GHContentIntegrationTest.java

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import java.io.BufferedReader;
99
import java.io.IOException;
1010
import java.io.InputStreamReader;
11-
import java.lang.reflect.Method;
1211
import java.nio.charset.StandardCharsets;
1312
import java.util.List;
1413

1514
import static org.hamcrest.Matchers.*;
15+
import static org.junit.Assert.assertThrows;
1616

1717
// TODO: Auto-generated Javadoc
1818
/**
@@ -242,17 +242,15 @@ int checkCreatedCommits(GitCommit gitCommit, GHCommit ghCommit, int expectedRequ
242242
assertThat(gitCommit.getAuthoredDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:49Z")));
243243
assertThat(gitCommit.getCommitDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:49Z")));
244244

245-
// Changed this to assert null since bridge methods are missing.
246-
assertThat(ghCommit, nullValue());
247-
// assertThat(ghCommit.getCommitShortInfo().getMessage(), equalTo("Creating a file for integration tests."));
248-
// assertThat("Message already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
249-
// Assert.assertThrows(GHException.class, () -> ghCommit.getCommitShortInfo().getCommentCount());
245+
assertThat(ghCommit.getCommitShortInfo().getMessage(), equalTo("Creating a file for integration tests."));
246+
assertThat("Message already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
247+
assertThrows(GHException.class, () -> ghCommit.getCommitShortInfo().getCommentCount());
250248

251-
// ghCommit.populate();
252-
// assertThat("Populate GHCommit", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
249+
ghCommit.populate();
250+
assertThat("Populate GHCommit", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
253251

254-
// expectedRequestCount = checkCommitUserInfo(gitCommit, ghCommit, expectedRequestCount);
255-
// assertThat("Resolved GHUser for GHCommit", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
252+
expectedRequestCount = checkCommitUserInfo(gitCommit, ghCommit, expectedRequestCount);
253+
assertThat("Resolved GHUser for GHCommit", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
256254

257255
expectedRequestCount = checkCommitTree(gitCommit, ghCommit, expectedRequestCount);
258256

@@ -271,13 +269,7 @@ int checkCreatedCommits(GitCommit gitCommit, GHCommit ghCommit, int expectedRequ
271269
* the exception
272270
*/
273271
GHCommit getGHCommit(GHContentUpdateResponse resp) throws Exception {
274-
for (Method method : resp.getClass().getMethods()) {
275-
if (method.getName().equals("getCommit") && method.getReturnType().equals(GHCommit.class)) {
276-
return (GHCommit) method.invoke(resp);
277-
}
278-
}
279-
System.out.println("Unable to find bridge method");
280-
return null;
272+
return resp.getCommit().toGHCommit();
281273
}
282274

283275
/**
@@ -303,16 +295,14 @@ int checkUpdatedContentResponseCommits(GitCommit gitCommit, GHCommit ghCommit, i
303295
assertThat(gitCommit.getAuthoredDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:51Z")));
304296
assertThat(gitCommit.getCommitDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:51Z")));
305297

306-
// Changed this to assert null since bridge methods are missing.
307-
assertThat(ghCommit, nullValue());
308-
// assertThat(ghCommit.getCommitShortInfo().getMessage(), equalTo("Updated file for integration tests."));
309-
// assertThat("Message already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
298+
assertThat(ghCommit.getCommitShortInfo().getMessage(), equalTo("Updated file for integration tests."));
299+
assertThat("Message already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
310300

311-
// ghCommit.populate();
312-
// assertThat("Populate GHCommit", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
301+
ghCommit.populate();
302+
assertThat("Populate GHCommit", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
313303

314-
// expectedRequestCount = checkCommitUserInfo(gitCommit, ghCommit, expectedRequestCount);
315-
// assertThat("GHUser already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
304+
expectedRequestCount = checkCommitUserInfo(gitCommit, ghCommit, expectedRequestCount);
305+
assertThat("GHUser already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
316306

317307
expectedRequestCount = checkCommitTree(gitCommit, ghCommit, expectedRequestCount);
318308

@@ -342,11 +332,9 @@ int checkBasicCommitInfo(GitCommit gitCommit, GHCommit ghCommit, int expectedReq
342332
equalTo("https://github.com/hub4j-test-org/GHContentIntegrationTest/commit/" + gitCommit.getSHA1()));
343333
assertThat(gitCommit.getVerification(), notNullValue());
344334

345-
// Changed this to assert null since bridge methods are missing.
346-
assertThat(ghCommit, nullValue());
347-
// assertThat(ghCommit.getSHA1(), notNullValue());
348-
// assertThat(ghCommit.getUrl().toString(),
349-
// endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/commits/" + ghCommit.getSHA1()));
335+
assertThat(ghCommit.getSHA1(), notNullValue());
336+
assertThat(ghCommit.getUrl().toString(),
337+
endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/commits/" + ghCommit.getSHA1()));
350338

351339
return expectedRequestCount;
352340
}
@@ -402,16 +390,13 @@ int checkCommitTree(GitCommit gitCommit, GHCommit ghCommit, int expectedRequestC
402390
endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/trees/" + gitCommit.getTree().getSha()));
403391
assertThat("GHTree already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
404392

405-
// Changed this to assert null since bridge methods are missing.
406-
assertThat(ghCommit, nullValue());
407-
// assertThat(ghCommit.getTree().getSha(), notNullValue());
408-
// assertThat("GHCommit has to resolve GHTree", mockGitHub.getRequestCount(), equalTo(expectedRequestCount +=
409-
// 1));
410-
// assertThat(ghCommit.getTree().getUrl().toString(),
411-
// endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/trees/" + ghCommit.getTree().getSha()));
412-
// assertThat("GHCommit resolving GHTree is not cached",
413-
// mockGitHub.getRequestCount(),
414-
// equalTo(expectedRequestCount += 2));
393+
assertThat(ghCommit.getTree().getSha(), notNullValue());
394+
assertThat("GHCommit has to resolve GHTree", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
395+
assertThat(ghCommit.getTree().getUrl().toString(),
396+
endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/trees/" + ghCommit.getTree().getSha()));
397+
assertThat("GHCommit resolving GHTree is not cached",
398+
mockGitHub.getRequestCount(),
399+
equalTo(expectedRequestCount += 2));
415400

416401
return expectedRequestCount;
417402
}
@@ -432,10 +417,8 @@ int checkCommitTree(GitCommit gitCommit, GHCommit ghCommit, int expectedRequestC
432417
int checkCommitParents(GitCommit gitCommit, GHCommit ghCommit, int expectedRequestCount) throws IOException {
433418
assertThat(gitCommit.getParentSHA1s().size(), is(greaterThan(0)));
434419
assertThat(gitCommit.getParentSHA1s().get(0), notNullValue());
435-
// Changed this to assert null since bridge methods are missing.
436-
assertThat(ghCommit, nullValue());
437-
// assertThat(ghCommit.getParentSHA1s().size(), is(greaterThan(0)));
438-
// assertThat(ghCommit.getParentSHA1s().get(0), notNullValue());
420+
assertThat(ghCommit.getParentSHA1s().size(), is(greaterThan(0)));
421+
assertThat(ghCommit.getParentSHA1s().get(0), notNullValue());
439422

440423
return expectedRequestCount;
441424
}

0 commit comments

Comments
 (0)