Skip to content
Prev Previous commit
Next Next commit
Improve code coverage
  • Loading branch information
bitwiseman committed Apr 6, 2025
commit 8ffd6eec383740ee54e488f230c57cfc0a329778
14 changes: 7 additions & 7 deletions src/test/java/org/kohsuke/github/CommitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.junit.Test;

import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -123,8 +123,8 @@ public void testQueryCommits() throws Exception {
commits = gitHub.getUser("jenkinsci")
.getRepository("jenkins")
.queryCommits()
.since(Instant.ofEpochMilli(1199174400000L))
.until(Instant.ofEpochMilli(1201852800000L))
.since(new Date(1199174400000L))
.until(new Date(1201852800000L))
.path("pom.xml")
.pageSize(100)
.list()
Expand All @@ -137,8 +137,8 @@ public void testQueryCommits() throws Exception {
commits = gitHub.getUser("jenkinsci")
.getRepository("jenkins")
.queryCommits()
.since(Instant.ofEpochMilli(1199174400000L))
.until(Instant.ofEpochMilli(1201852800000L))
.since(new Date(1199174400000L))
.until(new Date(1201852800000L))
.path("pom.xml")
.from("a5259970acaec9813e2a12a91f37dfc7871a5ef5")
.list()
Expand All @@ -150,7 +150,7 @@ public void testQueryCommits() throws Exception {
commits = gitHub.getUser("jenkinsci")
.getRepository("jenkins")
.queryCommits()
.until(Instant.ofEpochMilli(1201852800000L))
.until(new Date(1201852800000L))
.path("pom.xml")
.author("kohsuke")
.list()
Expand All @@ -161,7 +161,7 @@ public void testQueryCommits() throws Exception {
commits = gitHub.getUser("jenkinsci")
.getRepository("jenkins")
.queryCommits()
.until(Instant.ofEpochMilli(1201852800000L))
.until(new Date(1201852800000L))
.path("pom.xml")
.pageSize(100)
.author("kohsuke@71c3de6d-444a-0410-be80-ed276b4c234a")
Expand Down
15 changes: 12 additions & 3 deletions src/test/java/org/kohsuke/github/GHAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import org.junit.Test;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import static org.hamcrest.Matchers.*;

Expand Down Expand Up @@ -115,11 +119,16 @@ public void listInstallations() throws IOException {
*
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ParseException
* Signals that a ParseException has occurred.
*
*/
@Test
public void listInstallationsSince() throws IOException {
Instant localDate = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE)
public void listInstallationsSince() throws IOException, ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date localDate = simpleDateFormat.parse("2023-11-01");
Instant localInstant = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE)
.atStartOfDay()
.toInstant(ZoneOffset.UTC);
GHApp app = gitHub.getApp();
Expand Down Expand Up @@ -293,7 +302,7 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc

List<GHEvent> events = Arrays.asList(GHEvent.PULL_REQUEST, GHEvent.PUSH);
assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0])));
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseInstant("2019-07-04T01:19:36.000Z")));
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2019-07-04T01:19:36.000Z").toInstant()));
assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseInstant("2019-07-30T22:48:09.000Z")));
assertThat(appInstallation.getSingleFileName(), nullValue());
}
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.io.IOException;
import java.time.Instant;
import java.util.Date;

import static org.hamcrest.Matchers.*;

Expand Down Expand Up @@ -71,8 +72,8 @@ public void createCheckRun() throws Exception {
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.withDetailsURL("http://nowhere.net/stuff")
.withExternalID("whatever")
.withStartedAt(Instant.ofEpochMilli(999_999_000))
.withCompletedAt(Instant.ofEpochMilli(999_999_999))
.withStartedAt(new Date(999_999_000))
.withCompletedAt(new Date(999_999_999))
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…").withText("Hello Text!")
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
1,
Expand Down Expand Up @@ -195,7 +196,7 @@ public void updateCheckRun() throws Exception {
GHCheckRun updated = checkRun.update()
.withStatus(GHCheckRun.Status.COMPLETED)
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.withCompletedAt(Instant.ofEpochMilli(999_999_999))
.withCompletedAt(new Date(999_999_999))
.create();
assertThat(Instant.ofEpochMilli(999_999_000), equalTo(updated.getStartedAt()));
assertThat("foo", equalTo(updated.getName()));
Expand Down Expand Up @@ -254,7 +255,7 @@ public void updateCheckRunWithNameException() throws Exception {
() -> checkRun.update()
.withStatus(GHCheckRun.Status.COMPLETED)
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.withCompletedAt(Instant.ofEpochMilli(999_999_999))
.withCompletedAt(new Date(999_999_999))
.withName("bar", null)
.create());
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/kohsuke/github/GHIssueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import static org.hamcrest.Matchers.contains;
Expand Down Expand Up @@ -137,7 +138,7 @@ public void issueComment() throws Exception {
comments = issue.queryComments().since(firstCommentCreatedAtPlus1Second).list().toList();
assertThat(comments, hasSize(1));
assertThat(comments, contains(hasProperty("body", equalTo("Second comment"))));
comments = issue.queryComments().since(secondCommentCreatedAt).list().toList();
comments = issue.queryComments().since(Date.from(secondCommentCreatedAt)).list().toList();
assertThat(comments, hasSize(1));
assertThat(comments, contains(hasProperty("body", equalTo("Second comment"))));
comments = issue.queryComments().since(secondCommentCreatedAtPlus1Second).list().toList();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/kohsuke/github/GHMilestoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import java.io.IOException;
import java.time.Instant;
import java.util.Date;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsString;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -59,7 +59,7 @@ public void testUpdateMilestone() throws Exception {

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

milestone.setTitle(NEW_TITLE);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/kohsuke/github/GHTreeBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.junit.Test;

import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
import java.util.Date;

import static org.hamcrest.Matchers.*;

Expand Down Expand Up @@ -146,8 +146,8 @@ private GHCommit updateTree() throws IOException {
String treeSha = treeBuilder.create().getSha();
GHCommit commit = new GHCommitBuilder(repo).message("Add files")
.tree(treeSha)
.author("author", "author@author.com", Instant.ofEpochMilli(1611433225969L))
.committer("committer", "committer@committer.com", Instant.ofEpochMilli(1611433225968L))
.author("author", "author@author.com", new Date(1611433225969L))
.committer("committer", "committer@committer.com", new Date(1611433225968L))
.parent(mainRef.getObject().getSha())
.create();

Expand Down
Loading