Skip to content

Commit f63133e

Browse files
committed
review wrt test coverage
1 parent 548ffcb commit f63133e

File tree

28 files changed

+1851
-9
lines changed

28 files changed

+1851
-9
lines changed

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

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public void testCRUDContent() throws Exception {
152152
* @throws Exception
153153
* the exception
154154
*/
155-
@SuppressWarnings("deprecation")
156155
@Test
157156
public void testCreateWithAuthorCommitter() throws Exception {
158157
GHRepository ghRepository = getTempRepository();
@@ -161,8 +160,32 @@ public void testCreateWithAuthorCommitter() throws Exception {
161160
.path("author-committer-test.md")
162161
.content("test content\n")
163162
.author("John Doe", "john@example.com")
164-
.author("John Doe", "john@example.com", new Date(1234567890000L))
165163
.committer("Service Account", "service@example.com")
164+
.commit();
165+
166+
assertThat(response.getContent(), notNullValue());
167+
assertThat(response.getCommit(), notNullValue());
168+
assertThat(response.getCommit().getAuthor().getName(), equalTo("John Doe"));
169+
assertThat(response.getCommit().getAuthor().getEmail(), equalTo("john@example.com"));
170+
assertThat(response.getCommit().getCommitter().getName(), equalTo("Service Account"));
171+
assertThat(response.getCommit().getCommitter().getEmail(), equalTo("service@example.com"));
172+
}
173+
174+
/**
175+
* Test creating content with custom author and committer with date via GHContentBuilder.
176+
*
177+
* @throws Exception
178+
* the exception
179+
*/
180+
@SuppressWarnings("deprecation")
181+
@Test
182+
public void testCreateWithAuthorCommitterAndDate() throws Exception {
183+
GHRepository ghRepository = getTempRepository();
184+
GHContentUpdateResponse response = ghRepository.createContent()
185+
.message("Creating with custom author and committer")
186+
.path("author-committer-test.md")
187+
.content("test content\n")
188+
.author("John Doe", "john@example.com", new Date(1234567890000L))
166189
.committer("Service Account", "service@example.com", new Date(1234567890000L))
167190
.commit();
168191

@@ -180,16 +203,37 @@ public void testCreateWithAuthorCommitter() throws Exception {
180203
* @throws Exception
181204
* the exception
182205
*/
183-
@SuppressWarnings("deprecation")
184206
@Test
185207
public void testDeleteWithAuthorCommitter() throws Exception {
186208
GHContent content = repo.getFileContent("ghcontent-ro/a-file-with-content");
187209
GHContentUpdateResponse response = content.createDelete()
188210
.message("Deleting with custom author and committer")
189211
.branch("main")
190212
.author("John Doe", "john@example.com")
191-
.author("John Doe", "john@example.com", new Date(1234567890000L))
192213
.committer("Service Account", "service@example.com")
214+
.commit();
215+
216+
assertThat(response.getCommit(), notNullValue());
217+
assertThat(response.getCommit().getAuthor().getName(), equalTo("John Doe"));
218+
assertThat(response.getCommit().getAuthor().getEmail(), equalTo("john@example.com"));
219+
assertThat(response.getCommit().getCommitter().getName(), equalTo("Service Account"));
220+
assertThat(response.getCommit().getCommitter().getEmail(), equalTo("service@example.com"));
221+
}
222+
223+
/**
224+
* Test deleting content with custom author and committer with date via GHContentDeleter.
225+
*
226+
* @throws Exception
227+
* the exception
228+
*/
229+
@SuppressWarnings("deprecation")
230+
@Test
231+
public void testDeleteWithAuthorCommitterAndDate() throws Exception {
232+
GHContent content = repo.getFileContent("ghcontent-ro/a-file-with-content");
233+
GHContentUpdateResponse response = content.createDelete()
234+
.message("Deleting with custom author and committer")
235+
.branch("main")
236+
.author("John Doe", "john@example.com", new Date(1234567890000L))
193237
.committer("Service Account", "service@example.com", new Date(1234567890000L))
194238
.commit();
195239

@@ -381,7 +425,6 @@ public void testMIMESmall() throws IOException {
381425
* @throws Exception
382426
* the exception
383427
*/
384-
@SuppressWarnings("deprecation")
385428
@Test
386429
public void testUpdateWithAuthorCommitter() throws Exception {
387430
GHContent content = repo.getFileContent("ghcontent-ro/a-file-with-content");
@@ -390,8 +433,32 @@ public void testUpdateWithAuthorCommitter() throws Exception {
390433
.message("Updating with custom author and committer")
391434
.branch("main")
392435
.author("John Doe", "john@example.com")
393-
.author("John Doe", "john@example.com", new Date(1234567890000L))
394436
.committer("Service Account", "service@example.com")
437+
.commit();
438+
439+
assertThat(response.getContent(), notNullValue());
440+
assertThat(response.getCommit(), notNullValue());
441+
assertThat(response.getCommit().getAuthor().getName(), equalTo("John Doe"));
442+
assertThat(response.getCommit().getAuthor().getEmail(), equalTo("john@example.com"));
443+
assertThat(response.getCommit().getCommitter().getName(), equalTo("Service Account"));
444+
assertThat(response.getCommit().getCommitter().getEmail(), equalTo("service@example.com"));
445+
}
446+
447+
/**
448+
* Test updating content with custom author and committer with date via GHContentUpdater.
449+
*
450+
* @throws Exception
451+
* the exception
452+
*/
453+
@SuppressWarnings("deprecation")
454+
@Test
455+
public void testUpdateWithAuthorCommitterAndDate() throws Exception {
456+
GHContent content = repo.getFileContent("ghcontent-ro/a-file-with-content");
457+
GHContentUpdateResponse response = content.createUpdate()
458+
.content("updated content\n")
459+
.message("Updating with custom author and committer")
460+
.branch("main")
461+
.author("John Doe", "john@example.com", new Date(1234567890000L))
395462
.committer("Service Account", "service@example.com", new Date(1234567890000L))
396463
.commit();
397464

src/test/resources/org/kohsuke/github/GHContentIntegrationTest/wiremock/testCreateWithAuthorCommitter/mappings/4-r_h_t_contents_author-committer-testmd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"bodyPatterns": [
1313
{
14-
"equalToJson": "{\"path\":\"author-committer-test.md\",\"message\":\"Creating with custom author and committer\",\"content\":\"dGVzdCBjb250ZW50Cg==\",\"author\":{\"name\":\"John Doe\",\"email\":\"john@example.com\",\"date\":\"2009-02-13T23:31:30Z\"},\"committer\":{\"name\":\"Service Account\",\"email\":\"service@example.com\",\"date\":\"2009-02-13T23:31:30Z\"}}",
14+
"equalToJson": "{\"path\":\"author-committer-test.md\",\"message\":\"Creating with custom author and committer\",\"content\":\"dGVzdCBjb250ZW50Cg==\",\"author\":{\"name\":\"John Doe\",\"email\":\"john@example.com\"},\"committer\":{\"name\":\"Service Account\",\"email\":\"service@example.com\"}}",
1515
"ignoreArrayOrder": true,
1616
"ignoreExtraElements": false
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"login": "bitwiseman",
3+
"id": 1958953,
4+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
5+
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/bitwiseman",
8+
"html_url": "https://github.com/bitwiseman",
9+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
10+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
14+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
15+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
16+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Liam Newman",
21+
"company": "Cloudbees, Inc.",
22+
"blog": "",
23+
"location": "Seattle, WA, USA",
24+
"email": "bitwiseman@gmail.com",
25+
"hireable": null,
26+
"bio": "https://twitter.com/bitwiseman",
27+
"public_repos": 178,
28+
"public_gists": 7,
29+
"followers": 144,
30+
"following": 9,
31+
"created_at": "2012-07-11T20:38:33Z",
32+
"updated_at": "2019-12-18T01:26:55Z",
33+
"private_gists": 7,
34+
"total_private_repos": 10,
35+
"owned_private_repos": 0,
36+
"disk_usage": 33697,
37+
"collaborators": 0,
38+
"two_factor_authentication": true,
39+
"plan": {
40+
"name": "free",
41+
"space": 976562499,
42+
"collaborators": 0,
43+
"private_repos": 10000
44+
}
45+
}

0 commit comments

Comments
 (0)