summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Trutz2011-05-12 16:25:08 (EDT)
committer Christian Trutz2011-05-12 16:25:08 (EDT)
commit675f6e47212164c49f9d81bf8d00702ea4d3b38a (patch)
treee6d5e68e44de586b80d5fd0bfbb2b5639459aae4
parent8d67bad3b63edd9b4ac99c1af7f69041715b7c59 (diff)
downloadegit-github-675f6e47212164c49f9d81bf8d00702ea4d3b38a.zip
egit-github-675f6e47212164c49f9d81bf8d00702ea4d3b38a.tar.gz
egit-github-675f6e47212164c49f9d81bf8d00702ea4d3b38a.tar.bz2
Unit tests for PullRequest.refs/changes/95/3395/1
Change-Id: Iee8529a027a9fea91de5dda8ee5a1dc71098289a Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java2
-rwxr-xr-xorg.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java77
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java16
3 files changed, 88 insertions, 7 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java
index 3d65b08..5434871 100644
--- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java
@@ -25,7 +25,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/**
- * Tests for {@link PullRequestServiceTest}
+ * Tests for {@link PullRequestService}
*/
@RunWith(MockitoJUnitRunner.class)
public class PullRequestServiceTest {
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java
new file mode 100755
index 0000000..0cf7000
--- /dev/null
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Christian Trutz
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Trutz - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.github.core.tests;
+
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.egit.github.core.PullRequest;
+import org.junit.Test;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * Tests for {@link PullRequest}
+ */
+public class PullRequestTest {
+
+ private static final Gson gson = new GsonBuilder().setDateFormat(
+ "yyyy-MM-dd").create();
+
+ @Test
+ public void getCreatedAt_ReferenceMutableObject() {
+ PullRequest pullRequest = gson.fromJson("{createdAt : '2003-10-10'}",
+ PullRequest.class);
+ pullRequest.getCreatedAt().setTime(0);
+ assertTrue(pullRequest.getCreatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getIssueCreatedAt_ReferenceMutableObject() {
+ PullRequest pullRequest = gson.fromJson(
+ "{issueCreatedAt : '2003-10-10'}", PullRequest.class);
+ pullRequest.getIssueCreatedAt().setTime(0);
+ assertTrue(pullRequest.getIssueCreatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getIssueUpdatedAt_ReferenceMutableObject() {
+ PullRequest pullRequest = gson.fromJson(
+ "{issueUpdatedAt : '2003-10-10'}", PullRequest.class);
+ pullRequest.getIssueUpdatedAt().setTime(0);
+ assertTrue(pullRequest.getIssueUpdatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getMergedAt_ReferenceMutableObject() {
+ PullRequest pullRequest = gson.fromJson("{mergedAt : '2003-10-10'}",
+ PullRequest.class);
+ pullRequest.getMergedAt().setTime(0);
+ assertTrue(pullRequest.getMergedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getUpdatedAt_ReferenceMutableObject() {
+ PullRequest pullRequest = gson.fromJson("{updatedAt : '2003-10-10'}",
+ PullRequest.class);
+ pullRequest.getUpdatedAt().setTime(0);
+ assertTrue(pullRequest.getUpdatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getClosedAt_ReferenceMutableObject() {
+ PullRequest pullRequest = gson.fromJson("{closedAt : '2003-10-10'}",
+ PullRequest.class);
+ pullRequest.getClosedAt().setTime(0);
+ assertTrue(pullRequest.getClosedAt().getTime() != 0);
+ }
+
+}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java
index 3fa6518..a42fbe3 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java
@@ -51,42 +51,46 @@ public class PullRequest {
* @return closedAt
*/
public Date getClosedAt() {
- return this.closedAt;
+ return this.closedAt != null ? new Date(this.closedAt.getTime()) : null;
}
/**
* @return createdAt
*/
public Date getCreatedAt() {
- return this.createdAt;
+ return this.createdAt != null ? new Date(this.createdAt.getTime())
+ : null;
}
/**
* @return issueCreatedAt
*/
public Date getIssueCreatedAt() {
- return this.issueCreatedAt;
+ return this.issueCreatedAt != null ? new Date(
+ this.issueCreatedAt.getTime()) : null;
}
/**
* @return issueUpdatedAt
*/
public Date getIssueUpdatedAt() {
- return this.issueUpdatedAt;
+ return this.issueUpdatedAt != null ? new Date(
+ this.issueUpdatedAt.getTime()) : null;
}
/**
* @return mergedAt
*/
public Date getMergedAt() {
- return this.mergedAt;
+ return this.mergedAt != null ? new Date(this.mergedAt.getTime()) : null;
}
/**
* @return updatedAt
*/
public Date getUpdatedAt() {
- return this.updatedAt;
+ return this.updatedAt != null ? new Date(this.updatedAt.getTime())
+ : null;
}
/**