You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by rm...@apache.org on 2015/07/23 18:36:23 UTC

incubator-johnzon git commit: making tests a bit more tolerant to timezone

Repository: incubator-johnzon
Updated Branches:
  refs/heads/master e63016c68 -> bd3e07e53


making tests a bit more tolerant to timezone


Project: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/commit/bd3e07e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/tree/bd3e07e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/diff/bd3e07e5

Branch: refs/heads/master
Commit: bd3e07e5330cfaeab4d9e4362566f4c4ec5dbecf
Parents: e63016c
Author: Romain Manni-Bucau <rm...@starbucks.com>
Authored: Thu Jul 23 09:36:09 2015 -0700
Committer: Romain Manni-Bucau <rm...@starbucks.com>
Committed: Thu Jul 23 09:36:09 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/johnzon/mapper/JPATest.java | 32 ++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/bd3e07e5/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/JPATest.java
----------------------------------------------------------------------
diff --git a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/JPATest.java b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/JPATest.java
index f2cca7d..3ad92b7 100644
--- a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/JPATest.java
+++ b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/JPATest.java
@@ -23,18 +23,21 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
 import javax.persistence.Entity;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.Temporal;
+import java.io.StringReader;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
 
 import static javax.persistence.TemporalType.DATE;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
 
 public class JPATest {
     private EntityManagerFactory emf;
@@ -49,7 +52,8 @@ public class JPATest {
         em = emf.createEntityManager();
 
         final AnEntity entity = new AnEntity();
-        entity.setDate(new Date(0)); // fixed date for testing
+        final Date date = new Date(0);
+        entity.setDate(date); // fixed date for testing
         em.getTransaction().begin();
         em.persist(entity);
         em.getTransaction().commit();
@@ -66,14 +70,18 @@ public class JPATest {
     @Test
     public void ensureStateIsIgnoredAndDateIsCorrect() {
         final AnEntity entity = em.find(AnEntity.class, id);
-        assertEquals(
-                "{\"date\":\"19700101000000\",\"id\":" + id + "}",
-                new MapperBuilder().setAttributeOrder(new Comparator<String>() {
-                    @Override
-                    public int compare(final String o1, final String o2) {
-                        return o1.compareTo(o2);
-                    }
-                }).build().writeObjectAsString(entity).replaceAll("\\+[^\"]*", ""));
+        final Mapper mapper = new MapperBuilder().setAttributeOrder(new Comparator<String>() {
+            @Override
+            public int compare(final String o1, final String o2) {
+                return o1.compareTo(o2);
+            }
+        }).build();
+        final String asString = mapper.writeObjectAsString(entity);
+        final AnEntity entity1 = mapper.readObject(new StringReader(asString), AnEntity.class);
+        // issue with date is the timezone of the test runner, make it simple for now
+        assertEquals(entity.getDate(), entity1.getDate());
+        assertNotSame(entity.getDate(), entity1.getDate());
+        assertTrue(asString.contains("\"id\":" + id));
     }
 
     @Entity