From ed34e491f53478844b88f61f4313168db586d78f Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Thu, 12 May 2011 22:52:18 +0200 Subject: Unit tests for Repository. Change-Id: I770a575c60f9a51d94210d02eb6e3816fb04c051 Signed-off-by: Christian Trutz --- .../egit/github/core/tests/RepositoryTest.java | 45 ++++++++++++++++++++++ .../org/eclipse/egit/github/core/Repository.java | 9 +++-- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java new file mode 100755 index 00000000..e0feb281 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.Repository; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Tests for {@link Repository}. + */ +public class RepositoryTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + Repository repository = gson.fromJson("{createdAt : '2003-10-10'}", + Repository.class); + repository.getCreatedAt().setTime(0); + assertTrue(repository.getCreatedAt().getTime() != 0); + } + + @Test + public void getPushedAt_ReferenceMutableObject() { + Repository repository = gson.fromJson("{pushedAt : '2003-10-10'}", + Repository.class); + repository.getPushedAt().setTime(0); + assertTrue(repository.getPushedAt().getTime() != 0); + } + +} diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java index badf1760..7ea72d5d 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java @@ -10,12 +10,12 @@ *******************************************************************************/ package org.eclipse.egit.github.core; -import com.google.gson.annotations.SerializedName; - import java.net.MalformedURLException; import java.net.URL; import java.util.Date; +import com.google.gson.annotations.SerializedName; + /** * GitHub Repository class. */ @@ -207,14 +207,15 @@ public class Repository { * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + return this.createdAt != null ? new Date(this.createdAt.getTime()) + : null; } /** * @return pushedAt */ public Date getPushedAt() { - return this.pushedAt; + return this.pushedAt != null ? new Date(this.pushedAt.getTime()) : null; } /** -- cgit v1.2.3