Skip to content

Commit 1473203

Browse files
committed
Improve code coverage
1 parent 114e0e4 commit 1473203

File tree

6 files changed

+30
-20
lines changed

6 files changed

+30
-20
lines changed

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import org.junit.Test;
55

66
import java.io.IOException;
7-
import java.time.Instant;
87
import java.util.ArrayList;
98
import java.util.Arrays;
9+
import java.util.Date;
1010
import java.util.List;
1111

1212
import static org.hamcrest.Matchers.*;
@@ -123,8 +123,8 @@ public void testQueryCommits() throws Exception {
123123
commits = gitHub.getUser("jenkinsci")
124124
.getRepository("jenkins")
125125
.queryCommits()
126-
.since(Instant.ofEpochMilli(1199174400000L))
127-
.until(Instant.ofEpochMilli(1201852800000L))
126+
.since(new Date(1199174400000L))
127+
.until(new Date(1201852800000L))
128128
.path("pom.xml")
129129
.pageSize(100)
130130
.list()
@@ -137,8 +137,8 @@ public void testQueryCommits() throws Exception {
137137
commits = gitHub.getUser("jenkinsci")
138138
.getRepository("jenkins")
139139
.queryCommits()
140-
.since(Instant.ofEpochMilli(1199174400000L))
141-
.until(Instant.ofEpochMilli(1201852800000L))
140+
.since(new Date(1199174400000L))
141+
.until(new Date(1201852800000L))
142142
.path("pom.xml")
143143
.from("a5259970acaec9813e2a12a91f37dfc7871a5ef5")
144144
.list()
@@ -150,7 +150,7 @@ public void testQueryCommits() throws Exception {
150150
commits = gitHub.getUser("jenkinsci")
151151
.getRepository("jenkins")
152152
.queryCommits()
153-
.until(Instant.ofEpochMilli(1201852800000L))
153+
.until(new Date(1201852800000L))
154154
.path("pom.xml")
155155
.author("kohsuke")
156156
.list()
@@ -161,7 +161,7 @@ public void testQueryCommits() throws Exception {
161161
commits = gitHub.getUser("jenkinsci")
162162
.getRepository("jenkins")
163163
.queryCommits()
164-
.until(Instant.ofEpochMilli(1201852800000L))
164+
.until(new Date(1201852800000L))
165165
.path("pom.xml")
166166
.pageSize(100)
167167
.author("kohsuke@71c3de6d-444a-0410-be80-ed276b4c234a")

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
import org.junit.Test;
44

55
import java.io.IOException;
6+
import java.text.ParseException;
7+
import java.text.SimpleDateFormat;
68
import java.time.Instant;
79
import java.time.LocalDate;
810
import java.time.ZoneOffset;
911
import java.time.format.DateTimeFormatter;
1012
import java.util.Arrays;
1113
import java.util.Collections;
14+
import java.util.Date;
1215
import java.util.HashMap;
1316
import java.util.List;
1417
import java.util.Map;
18+
import java.util.TimeZone;
1519

1620
import static org.hamcrest.Matchers.*;
1721

@@ -115,11 +119,15 @@ public void listInstallations() throws IOException {
115119
*
116120
* @throws IOException
117121
* Signals that an I/O exception has occurred.
122+
* @throws ParseException
118123
*
119124
*/
120125
@Test
121-
public void listInstallationsSince() throws IOException {
122-
Instant localDate = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE)
126+
public void listInstallationsSince() throws IOException, ParseException {
127+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
128+
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
129+
Date localDate = simpleDateFormat.parse("2023-11-01");
130+
Instant localInstant = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE)
123131
.atStartOfDay()
124132
.toInstant(ZoneOffset.UTC);
125133
GHApp app = gitHub.getApp();
@@ -293,7 +301,7 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc
293301

294302
List<GHEvent> events = Arrays.asList(GHEvent.PULL_REQUEST, GHEvent.PUSH);
295303
assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0])));
296-
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseInstant("2019-07-04T01:19:36.000Z")));
304+
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2019-07-04T01:19:36.000Z").toInstant()));
297305
assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseInstant("2019-07-30T22:48:09.000Z")));
298306
assertThat(appInstallation.getSingleFileName(), nullValue());
299307
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import java.io.IOException;
3232
import java.time.Instant;
33+
import java.util.Date;
3334

3435
import static org.hamcrest.Matchers.*;
3536

@@ -71,8 +72,8 @@ public void createCheckRun() throws Exception {
7172
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
7273
.withDetailsURL("http://nowhere.net/stuff")
7374
.withExternalID("whatever")
74-
.withStartedAt(Instant.ofEpochMilli(999_999_000))
75-
.withCompletedAt(Instant.ofEpochMilli(999_999_999))
75+
.withStartedAt(new Date(999_999_000))
76+
.withCompletedAt(new Date(999_999_999))
7677
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…").withText("Hello Text!")
7778
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
7879
1,
@@ -195,7 +196,7 @@ public void updateCheckRun() throws Exception {
195196
GHCheckRun updated = checkRun.update()
196197
.withStatus(GHCheckRun.Status.COMPLETED)
197198
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
198-
.withCompletedAt(Instant.ofEpochMilli(999_999_999))
199+
.withCompletedAt(new Date(999_999_999))
199200
.create();
200201
assertThat(Instant.ofEpochMilli(999_999_000), equalTo(updated.getStartedAt()));
201202
assertThat("foo", equalTo(updated.getName()));
@@ -254,7 +255,7 @@ public void updateCheckRunWithNameException() throws Exception {
254255
() -> checkRun.update()
255256
.withStatus(GHCheckRun.Status.COMPLETED)
256257
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
257-
.withCompletedAt(Instant.ofEpochMilli(999_999_999))
258+
.withCompletedAt(new Date(999_999_999))
258259
.withName("bar", null)
259260
.create());
260261
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.time.Instant;
99
import java.util.Collection;
10+
import java.util.Date;
1011
import java.util.List;
1112

1213
import static org.hamcrest.Matchers.contains;
@@ -137,7 +138,7 @@ public void issueComment() throws Exception {
137138
comments = issue.queryComments().since(firstCommentCreatedAtPlus1Second).list().toList();
138139
assertThat(comments, hasSize(1));
139140
assertThat(comments, contains(hasProperty("body", equalTo("Second comment"))));
140-
comments = issue.queryComments().since(secondCommentCreatedAt).list().toList();
141+
comments = issue.queryComments().since(Date.from(secondCommentCreatedAt)).list().toList();
141142
assertThat(comments, hasSize(1));
142143
assertThat(comments, contains(hasProperty("body", equalTo("Second comment"))));
143144
comments = issue.queryComments().since(secondCommentCreatedAtPlus1Second).list().toList();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import java.io.IOException;
88
import java.time.Instant;
9+
import java.util.Date;
910

1011
import static org.hamcrest.Matchers.*;
11-
import static org.hamcrest.Matchers.containsString;
1212

1313
// TODO: Auto-generated Javadoc
1414
/**
@@ -59,7 +59,7 @@ public void testUpdateMilestone() throws Exception {
5959

6060
String NEW_TITLE = "Updated Title";
6161
String NEW_DESCRIPTION = "Updated Description";
62-
Instant NEW_DUE_DATE = GitHubClient.parseInstant("2020-10-05T13:00:00Z");
62+
Date NEW_DUE_DATE = GitHubClient.parseDate("2020-10-05T13:00:00Z");
6363
Instant OUTPUT_DUE_DATE = GitHubClient.parseInstant("2020-10-05T07:00:00Z");
6464

6565
milestone.setTitle(NEW_TITLE);

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import org.junit.Test;
66

77
import java.io.IOException;
8-
import java.time.Instant;
98
import java.util.Arrays;
9+
import java.util.Date;
1010

1111
import static org.hamcrest.Matchers.*;
1212

@@ -146,8 +146,8 @@ private GHCommit updateTree() throws IOException {
146146
String treeSha = treeBuilder.create().getSha();
147147
GHCommit commit = new GHCommitBuilder(repo).message("Add files")
148148
.tree(treeSha)
149-
.author("author", "author@author.com", Instant.ofEpochMilli(1611433225969L))
150-
.committer("committer", "committer@committer.com", Instant.ofEpochMilli(1611433225968L))
149+
.author("author", "author@author.com", new Date(1611433225969L))
150+
.committer("committer", "committer@committer.com", new Date(1611433225968L))
151151
.parent(mainRef.getObject().getSha())
152152
.create();
153153

0 commit comments

Comments
 (0)