Skip to content

Commit

Permalink
Switch to Java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
aduprat authored and bitwiseman committed Jul 13, 2020
1 parent e452a90 commit 36967eb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
19 changes: 15 additions & 4 deletions src/test/java/org/jenkinsci/plugins/ghprb/GhprbIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import hudson.model.ParameterValue;
import hudson.model.Run;
import net.sf.json.JSONObject;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -20,7 +19,11 @@
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -89,12 +92,17 @@ public void shouldBuildTriggersOnUpdatingNewCommitsPR() throws Exception {
@Test
public void shouldBuildTriggersOnUpdatingRetestMessagePR() throws Exception {
// GIVEN
given(ghPullRequest.getCreatedAt()).willReturn(new DateTime().toDate());
given(ghPullRequest.getCreatedAt()).willReturn(Date.from(
ZonedDateTime.now(ZoneOffset.UTC)
.toInstant()));
GhprbTestUtil.triggerRunAndWait(10, trigger, project);
assertThat(project.getBuilds().toArray().length).isEqualTo(1);

given(comment.getBody()).willReturn("retest this please");
given(comment.getUpdatedAt()).willReturn(new DateTime().plusDays(1).toDate());
given(comment.getUpdatedAt()).willReturn(Date.from(
ZonedDateTime.now(ZoneOffset.UTC)
.plus(1, ChronoUnit.DAYS)
.toInstant()));
given(comment.getUser()).willReturn(ghUser);

given(ghPullRequest.getComments()).willReturn(newArrayList(comment));
Expand All @@ -111,7 +119,10 @@ public void shouldNotBuildDisabledBuild() throws Exception {
given(commitPointer.getSha()).willReturn("sha");

given(comment.getBody()).willReturn("retest this please");
given(comment.getUpdatedAt()).willReturn(new DateTime().plusDays(1).toDate());
given(comment.getUpdatedAt()).willReturn(Date.from(
ZonedDateTime.now(ZoneOffset.UTC)
.plus(1, ChronoUnit.DAYS)
.toInstant()));
given(comment.getUser()).willReturn(ghUser);
given(ghPullRequest.getComments()).willReturn(newArrayList(comment));
given(ghPullRequest.getNumber()).willReturn(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.GitSCM;
import org.joda.time.DateTime;
import org.kohsuke.github.GHCommitPointer;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHPullRequest;
Expand All @@ -16,6 +15,9 @@
import org.mockito.Mock;
import org.mockito.Mockito;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Map;

import static com.google.common.collect.Lists.newArrayList;
Expand Down Expand Up @@ -79,7 +81,11 @@ protected void beforeTest(

given(ghRepository.getName()).willReturn("dropwizard");

GhprbTestUtil.mockPR(ghPullRequest, commitPointer, new DateTime(), new DateTime().plusDays(1));
GhprbTestUtil.mockPR(ghPullRequest,
commitPointer,
ZonedDateTime.now(ZoneOffset.UTC),
ZonedDateTime.now(ZoneOffset.UTC)
.plus(1, ChronoUnit.DAYS));

given(ghRepository.getPullRequests(eq(GHIssueState.OPEN)))
.willReturn(newArrayList(ghPullRequest))
Expand Down
23 changes: 18 additions & 5 deletions src/test/java/org/jenkinsci/plugins/ghprb/GhprbRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.apache.commons.codec.binary.Hex;
import org.fest.util.Collections;
import org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -38,6 +37,9 @@
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -519,8 +521,14 @@ public void testCheckMethodWhenPrWasUpdatedWithNonKeyPhrase() throws Exception {
mockCommitList();
GhprbBuilds builds = mockBuilds();

Date later = new DateTime().plusHours(3).toDate();
Date tomorrow = new DateTime().plusDays(1).toDate();
Date later = Date.from(
ZonedDateTime.now(ZoneOffset.UTC)
.plus(3, ChronoUnit.HOURS)
.toInstant());
Date tomorrow = Date.from(
ZonedDateTime.now(ZoneOffset.UTC)
.plus(1, ChronoUnit.DAYS)
.toInstant());


given(ghRepository.getPullRequests(eq(GHIssueState.OPEN))).willReturn(ghPullRequests);
Expand Down Expand Up @@ -616,8 +624,13 @@ private List<GHPullRequest> createListWithMockPR() throws IOException {
public void testCheckMethodWhenPrWasUpdatedWithRetestPhrase() throws Exception {
// GIVEN
List<GHPullRequest> ghPullRequests = createListWithMockPR();
Date now = new Date();
Date tomorrow = new DateTime().plusDays(1).toDate();
Date now = Date.from(
ZonedDateTime.now(ZoneOffset.UTC)
.toInstant());
Date tomorrow = Date.from(
ZonedDateTime.now(ZoneOffset.UTC)
.plus(1, ChronoUnit.DAYS)
.toInstant());

mockHeadAndBase();
mockCommitList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.coravy.hudson.plugins.github.GithubProjectProperty;
import hudson.model.FreeStyleProject;
import hudson.plugins.git.GitSCM;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -28,6 +27,9 @@
import java.io.Reader;
import java.io.StringReader;
import java.net.URLEncoder;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
Expand Down Expand Up @@ -79,7 +81,11 @@ public void setup() throws Exception {
given(commitPointer.getRef()).willReturn("ref");
given(ghRepository.getName()).willReturn("dropwizard");

GhprbTestUtil.mockPR(ghPullRequest, commitPointer, new DateTime(), new DateTime().plusDays(1));
GhprbTestUtil.mockPR(ghPullRequest,
commitPointer,
ZonedDateTime.now(ZoneOffset.UTC),
ZonedDateTime.now(ZoneOffset.UTC)
.plus(1, ChronoUnit.DAYS));

given(ghRepository.getPullRequests(eq(OPEN))).willReturn(newArrayList(ghPullRequest)).willReturn(newArrayList(ghPullRequest));

Expand Down
17 changes: 9 additions & 8 deletions src/test/java/org/jenkinsci/plugins/ghprb/GhprbTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import hudson.plugins.git.UserRemoteConfig;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.kohsuke.github.GHCommitPointer;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRateLimit;
Expand All @@ -39,7 +38,9 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -253,7 +254,7 @@ public static void mockCommitList(GHPullRequest ghPullRequest) {
Mockito.when(itr.hasNext()).thenReturn(false);
}

public static void mockPR(GHPullRequest prToMock, GHCommitPointer commitPointer, DateTime... updatedDate) throws Exception {
public static void mockPR(GHPullRequest prToMock, GHCommitPointer commitPointer, ZonedDateTime... updatedDate) throws Exception {

given(prToMock.getHead()).willReturn(commitPointer);
given(prToMock.getBase()).willReturn(commitPointer);
Expand All @@ -262,13 +263,13 @@ public static void mockPR(GHPullRequest prToMock, GHCommitPointer commitPointer,

if (updatedDate.length > 1) {
given(prToMock.getUpdatedAt())
.willReturn(updatedDate[0].toDate())
.willReturn(updatedDate[0].toDate())
.willReturn(updatedDate[1].toDate())
.willReturn(updatedDate[1].toDate())
.willReturn(updatedDate[1].toDate());
.willReturn(Date.from(updatedDate[0].toInstant()))
.willReturn(Date.from(updatedDate[0].toInstant()))
.willReturn(Date.from(updatedDate[1].toInstant()))
.willReturn(Date.from(updatedDate[1].toInstant()))
.willReturn(Date.from(updatedDate[1].toInstant()));
} else {
given(prToMock.getUpdatedAt()).willReturn(updatedDate[0].toDate());
given(prToMock.getUpdatedAt()).willReturn(Date.from(updatedDate[0].toInstant()));
}
}

Expand Down

0 comments on commit 36967eb

Please sign in to comment.