diff --git a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbIT.java b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbIT.java index 61a29846e..0201c1424 100644 --- a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbIT.java +++ b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbIT.java @@ -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; @@ -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; @@ -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)); @@ -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); diff --git a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbITBaseTestCase.java b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbITBaseTestCase.java index d4ecacd18..4bdcc1264 100644 --- a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbITBaseTestCase.java +++ b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbITBaseTestCase.java @@ -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; @@ -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; @@ -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)) diff --git a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRepositoryTest.java b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRepositoryTest.java index 25cab45dd..09904d214 100644 --- a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRepositoryTest.java +++ b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRepositoryTest.java @@ -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; @@ -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; @@ -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); @@ -616,8 +624,13 @@ private List createListWithMockPR() throws IOException { public void testCheckMethodWhenPrWasUpdatedWithRetestPhrase() throws Exception { // GIVEN List 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(); diff --git a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRootActionTest.java b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRootActionTest.java index d83c8a20b..c0d2a2a23 100644 --- a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRootActionTest.java +++ b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbRootActionTest.java @@ -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; @@ -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; @@ -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)); diff --git a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbTestUtil.java b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbTestUtil.java index 337653be6..1cba79ec3 100644 --- a/src/test/java/org/jenkinsci/plugins/ghprb/GhprbTestUtil.java +++ b/src/test/java/org/jenkinsci/plugins/ghprb/GhprbTestUtil.java @@ -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; @@ -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; @@ -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); @@ -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())); } }