From 9a50ad8dea5e9ebc5eb1c5efb19aa7a784283e14 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 18:25:11 +0300 Subject: date and tests --- src/test/java/com/juick/JsonTests.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/java/com/juick/JsonTests.java (limited to 'src/test/java') diff --git a/src/test/java/com/juick/JsonTests.java b/src/test/java/com/juick/JsonTests.java new file mode 100644 index 00000000..5d78a2d6 --- /dev/null +++ b/src/test/java/com/juick/JsonTests.java @@ -0,0 +1,30 @@ +package com.juick; + +import static org.junit.Assert.assertEquals; + +import com.juick.json.MessageSerializer; +import org.junit.Assert; +import org.junit.Test; + +import com.juick.Message; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +public class JsonTests { + @Test + public void DateTest() { + Message msg = new Message(); + SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + msg.setDate(df.parse("2015-01-01 00:00:00")); + MessageSerializer serializer = new MessageSerializer(); + String json = serializer.serialize(msg).toString(); + assertEquals("{\"timestamp\":\"2015-01-01 00:00:00\"}", json); + } catch (ParseException e) { + e.printStackTrace(); + } + + } +} \ No newline at end of file -- cgit v1.2.3 From 1a39696a6eaf4ea41447e4426ccdcfacec657554 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 19:03:54 +0300 Subject: update test for date and time --- src/test/java/com/juick/JsonTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/com/juick/JsonTests.java b/src/test/java/com/juick/JsonTests.java index 5d78a2d6..890360c1 100644 --- a/src/test/java/com/juick/JsonTests.java +++ b/src/test/java/com/juick/JsonTests.java @@ -18,10 +18,10 @@ public class JsonTests { Message msg = new Message(); SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { - msg.setDate(df.parse("2015-01-01 00:00:00")); + msg.setDate(df.parse("2015-01-01 05:02:10")); MessageSerializer serializer = new MessageSerializer(); String json = serializer.serialize(msg).toString(); - assertEquals("{\"timestamp\":\"2015-01-01 00:00:00\"}", json); + assertEquals("{\"timestamp\":\"2015-01-01 05:02:10\"}", json); } catch (ParseException e) { e.printStackTrace(); } -- cgit v1.2.3 From 9dfad84fa487960fde4cc4b0ac6760c8dd5f4ac9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 19:16:41 +0300 Subject: fix tests --- src/test/java/com/juick/JsonTests.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/com/juick/JsonTests.java b/src/test/java/com/juick/JsonTests.java index 890360c1..ba01e80c 100644 --- a/src/test/java/com/juick/JsonTests.java +++ b/src/test/java/com/juick/JsonTests.java @@ -11,12 +11,14 @@ import com.juick.Message; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.TimeZone; public class JsonTests { @Test public void DateTest() { Message msg = new Message(); SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + df.setTimeZone(TimeZone.getTimeZone("UTC")); try { msg.setDate(df.parse("2015-01-01 05:02:10")); MessageSerializer serializer = new MessageSerializer(); -- cgit v1.2.3