diff options
| author | Christian Trutz | 2011-05-06 20:56:18 +0000 |
|---|---|---|
| committer | Christian Trutz | 2011-05-06 20:56:18 +0000 |
| commit | 5304013c52035e09910f19db44372f1add48ae4d (patch) | |
| tree | ae8d4a25b8d86bf3e8efef3371f5eb79bf368f4e | |
| parent | ae81bd433ef66f15ccc9993ba27aae37f537427c (diff) | |
| download | egit-github-5304013c52035e09910f19db44372f1add48ae4d.tar.gz egit-github-5304013c52035e09910f19db44372f1add48ae4d.tar.xz egit-github-5304013c52035e09910f19db44372f1add48ae4d.zip | |
Unit tests for Gist, Issue, Milestone, GistRevision.
See also FindBugs warnings in Hudson.
Change-Id: Ice5cd46fc56612ce2a76ac85fd7f0d8bf07edac3
Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
9 files changed, 219 insertions, 12 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java index 2707be5a..7743443a 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java @@ -25,7 +25,7 @@ public class Gist { private boolean isPublic; private Date createdAt; - + private Date updatedAt; private int comments; @@ -68,7 +68,9 @@ public class Gist { * @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()); } /** @@ -158,7 +160,9 @@ public class Gist { * @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.core/src/org/eclipse/mylyn/github/internal/GistRevision.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java index 60bab860..1d9e2b87 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java @@ -31,7 +31,9 @@ public class GistRevision { * @return committedAt */ public Date getCommittedAt() { - return this.committedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.committedAt.getTime()); } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java index e669393c..80640f26 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java @@ -15,7 +15,7 @@ import java.util.List; /** * GitHub issue class. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class Issue { @@ -52,21 +52,27 @@ public class Issue { * @return closedAt */ public Date getClosedAt() { - return this.closedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.closedAt.getTime()); } /** * @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.core/src/org/eclipse/mylyn/github/internal/Milestone.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java index 31ff4c9d..5024f4e9 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java @@ -14,7 +14,7 @@ import java.util.Date; /** * GitHub issue milestone class. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class Milestone { @@ -43,14 +43,18 @@ public class Milestone { * @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 dueOn */ public Date getDueOn() { - return this.dueOn; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.dueOn.getTime()); } /** diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistRevisionTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistRevisionTest.java new file mode 100755 index 00000000..e12b261d --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistRevisionTest.java @@ -0,0 +1,39 @@ +/*******************************************************************************
+ * 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 GistRevision}
+ */
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class GistRevisionTest {
+
+ private static final Gson gson = new GsonBuilder().setDateFormat(
+ "yyyy-MM-dd").create();
+
+ @Test
+ public void getCreatedAt_ReferenceMutableObject() {
+ GistRevision gistRevision = gson.fromJson(
+ "{committedAt : '2003-10-10'}", GistRevision.class);
+ gistRevision.getCommittedAt().setTime(0);
+ assertTrue(gistRevision.getCommittedAt().getTime() != 0);
+ }
+}
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistTest.java new file mode 100755 index 00000000..29d2a15f --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistTest.java @@ -0,0 +1,46 @@ +/*******************************************************************************
+ * 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 Gist}
+ */
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class GistTest {
+
+ private static final Gson gson = new GsonBuilder().setDateFormat(
+ "yyyy-MM-dd").create();
+
+ @Test
+ public void getCreatedAt_ReferenceMutableObject() {
+ Gist gist = gson.fromJson("{createdAt : '2003-10-10'}", Gist.class);
+ gist.getCreatedAt().setTime(0);
+ assertTrue(gist.getCreatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getUpdatedAt_ReferenceMutableObject() {
+ Gist gist = gson.fromJson("{updatedAt : '2003-10-10'}", Gist.class);
+ gist.getUpdatedAt().setTime(0);
+ assertTrue(gist.getUpdatedAt().getTime() != 0);
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueTest.java new file mode 100755 index 00000000..f52e8887 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueTest.java @@ -0,0 +1,53 @@ +/*******************************************************************************
+ * 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 Issue}
+ */
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class IssueTest {
+
+ private static final Gson gson = new GsonBuilder().setDateFormat(
+ "yyyy-MM-dd").create();
+
+ @Test
+ public void getCreatedAt_ReferenceMutableObject() {
+ Issue issue = gson.fromJson("{createdAt : '2003-10-10'}", Issue.class);
+ issue.getCreatedAt().setTime(0);
+ assertTrue(issue.getCreatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getUpdatedAt_ReferenceMutableObject() {
+ Issue issue = gson.fromJson("{updatedAt : '2003-10-10'}", Issue.class);
+ issue.getUpdatedAt().setTime(0);
+ assertTrue(issue.getUpdatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getClosedAt_ReferenceMutableObject() {
+ Issue issue = gson.fromJson("{closedAt : '2003-10-10'}", Issue.class);
+ issue.getClosedAt().setTime(0);
+ assertTrue(issue.getClosedAt().getTime() != 0);
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneTest.java new file mode 100755 index 00000000..957b4c5c --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneTest.java @@ -0,0 +1,48 @@ +/*******************************************************************************
+ * 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 Milestone}
+ */
+@SuppressWarnings("restriction")
+@RunWith(MockitoJUnitRunner.class)
+public class MilestoneTest {
+
+ private static final Gson gson = new GsonBuilder().setDateFormat(
+ "yyyy-MM-dd").create();
+
+ @Test
+ public void getCreatedAt_ReferenceMutableObject() {
+ Milestone milestone = gson.fromJson("{createdAt : '2003-10-10'}",
+ Milestone.class);
+ milestone.getCreatedAt().setTime(0);
+ assertTrue(milestone.getCreatedAt().getTime() != 0);
+ }
+
+ @Test
+ public void getDueOn_ReferenceMutableObject() {
+ Milestone milestone = gson.fromJson("{dueOn : '2003-10-10'}",
+ Milestone.class);
+ milestone.getDueOn().setTime(0);
+ assertTrue(milestone.getDueOn().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 4fadbb4c..40065a5d 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 @@ -13,18 +13,23 @@ package org.eclipse.mylyn.github.tests; import org.eclipse.mylyn.github.internal.CommentTest; +import org.eclipse.mylyn.github.internal.GistRevisionTest; import org.eclipse.mylyn.github.internal.GistServiceTest; +import org.eclipse.mylyn.github.internal.GistTest; import org.eclipse.mylyn.github.internal.GitHubClientTest; import org.eclipse.mylyn.github.internal.IssueServiceTest; +import org.eclipse.mylyn.github.internal.IssueTest; import org.eclipse.mylyn.github.internal.LabelServiceTest; import org.eclipse.mylyn.github.internal.MilestoneServiceTest; +import org.eclipse.mylyn.github.internal.MilestoneTest; import org.eclipse.mylyn.github.internal.PullRequestServiceTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ CommentTest.class, GitHubClientTest.class, +@SuiteClasses({ CommentTest.class, GistTest.class, GistRevisionTest.class, + IssueTest.class, MilestoneTest.class, GitHubClientTest.class, IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class, GistServiceTest.class, PullRequestServiceTest.class }) |
