From f3963f0b12055ba6710b9b28ddc93a5b5fe91d67 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Fri, 22 Sep 2017 16:39:00 +0300
Subject: Initial getNotifications query
* using Java 8 DateTime API where possible
---
src/test/java/com/juick/rss/LegacyRSS.java | 4 ++--
src/test/java/com/juick/tests/ApiTests.java | 3 ---
src/test/java/com/juick/tests/MessageTests.java | 10 +++++++---
3 files changed, 9 insertions(+), 8 deletions(-)
(limited to 'src')
diff --git a/src/test/java/com/juick/rss/LegacyRSS.java b/src/test/java/com/juick/rss/LegacyRSS.java
index 2ad276c7..3038e2d2 100644
--- a/src/test/java/com/juick/rss/LegacyRSS.java
+++ b/src/test/java/com/juick/rss/LegacyRSS.java
@@ -119,7 +119,7 @@ public class LegacyRSS {
out.println("]]>");
out.println("");
- out.println("" + DateFormattersHolder.getRssFormatterInstance().format(msg.getDate()) + "");
+ out.println("" + DateFormattersHolder.getRssFormatterInstance().format(msg.getTimestamp()) + "");
out.println("http://juick.com/" + msg.getUser().getName() + "/" + msg.getMid() + "");
if (!msg.getTags().isEmpty()) {
@@ -190,7 +190,7 @@ public class LegacyRSS {
out.println("http://juick.com/" + r.uname + "/");
out.println("
@" + r.uname + ":");
out.println("");
- out.println("" + DateFormattersHolder.getRssFormatterInstance().format(r.pubDate) + "");
+ out.println("" + DateFormattersHolder.getRssFormatterInstance().format(r.pubDate.toInstant()) + "");
String attachment = r.attachmentType;
if (attachment != null && !attachment.isEmpty()) {
if (attachment.equals("jpg")) {
diff --git a/src/test/java/com/juick/tests/ApiTests.java b/src/test/java/com/juick/tests/ApiTests.java
index 7001d3f0..51641c1d 100644
--- a/src/test/java/com/juick/tests/ApiTests.java
+++ b/src/test/java/com/juick/tests/ApiTests.java
@@ -168,9 +168,6 @@ public class ApiTests {
int mid = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
Message msg = messagesService.getMessage(mid);
assertEquals("yo", msg.getText());
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(msg.getDate());
- assertEquals(2017, calendar.get(Calendar.YEAR));
User me = msg.getUser();
assertEquals("mmmme", me.getName());
assertEquals("mmmme", messagesService.getMessageAuthor(mid).getName());
diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java
index 25a5115e..2cc8fed2 100644
--- a/src/test/java/com/juick/tests/MessageTests.java
+++ b/src/test/java/com/juick/tests/MessageTests.java
@@ -18,6 +18,8 @@
package com.juick.tests;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.juick.Message;
import com.juick.util.DateFormattersHolder;
import org.apache.commons.codec.CharEncoding;
@@ -38,7 +40,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.text.ParseException;
-import java.util.Date;
+import java.time.Instant;
import static org.junit.Assert.assertEquals;
@@ -51,9 +53,11 @@ public class MessageTests {
assertEquals("First tag must be", "test", msg.getTags().get(0).getName());
assertEquals("Third tag must be", "test3", msg.getTags().get(2).getName());
assertEquals("Count of tags must be", 3, msg.getTags().size());
- Date currentDate = new Date();
- msg.setDate(currentDate);
+ Instant currentDate = Instant.now();
+ msg.setTimestamp(currentDate);
ObjectMapper serializer = new ObjectMapper();
+ serializer.registerModule(new Jdk8Module());
+ serializer.registerModule(new JavaTimeModule());
String jsonMessage = serializer.writeValueAsString(msg);
JSONObject jsonObject = new JSONObject(jsonMessage);
assertEquals("date should be in timestamp field", DateFormattersHolder.getMessageFormatterInstance().format(currentDate),
--
cgit v1.2.3