diff options
4 files changed, 60 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java index 1a37ddca..cabb24d2 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java @@ -14,7 +14,7 @@ import java.util.Date; /** * GitHub issue comment class. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class Comment { @@ -33,14 +33,18 @@ public class Comment { * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.createdAt.getTime()); } /** * @return updatedAt */ public Date getUpdatedAt() { - return this.updatedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.updatedAt.getTime()); } /** diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index 16d752dc..8d67c594 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -18,6 +18,7 @@ Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", com.google.gson.reflect;version="1.6.0", org.apache.commons.httpclient;version="3.1.0", + org.apache.commons.logging;version="1.0.4", org.mockito;version="1.8.4", org.mockito.runners;version="1.8.4", org.mockito.stubbing;version="1.8.4" diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/CommentTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/CommentTest.java new file mode 100755 index 00000000..f22dc029 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/CommentTest.java @@ -0,0 +1,47 @@ +/*******************************************************************************
+ * 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.mylyn.github.internal;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * Unit tests for {@link Comment}
+ */
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class CommentTest {
+
+ private static final Gson gson = new GsonBuilder().setDateFormat(
+ "yyyy-MM-dd").create();
+
+ @Test
+ public void getCreatedAt_ReferenceMutableObject() {
+ Comment comment = gson.fromJson("{createdAt : '2003-10-10'}",
+ Comment.class);
+ comment.getCreatedAt().setTime(0);
+ assertTrue(comment.getCreatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getUpdatedAt_ReferenceMutableObject() {
+ Comment comment = gson.fromJson("{updatedAt : '2003-10-10'}",
+ Comment.class);
+ comment.getUpdatedAt().setTime(0);
+ assertTrue(comment.getUpdatedAt().getTime() != 0);
+ }
+}
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java index cf4c4e93..4fadbb4c 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.github.tests; +import org.eclipse.mylyn.github.internal.CommentTest; import org.eclipse.mylyn.github.internal.GistServiceTest; import org.eclipse.mylyn.github.internal.GitHubClientTest; import org.eclipse.mylyn.github.internal.IssueServiceTest; @@ -23,9 +24,10 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ GitHubClientTest.class, IssueServiceTest.class, - LabelServiceTest.class, MilestoneServiceTest.class, - GistServiceTest.class, PullRequestServiceTest.class }) +@SuiteClasses({ CommentTest.class, GitHubClientTest.class, + IssueServiceTest.class, LabelServiceTest.class, + MilestoneServiceTest.class, GistServiceTest.class, + PullRequestServiceTest.class }) public class AllHeadlessTests { } |