-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestEvent.java
45 lines (36 loc) · 1.33 KB
/
TestEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.gson.Gson;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestEvent {
private static final Event event = new Event();
private static final String createdAt = DateTimeFormatter.ofPattern(Event.TS_FORMAT)
.withZone(ZoneId.from(ZoneOffset.UTC))
.format(event.getCreatedAt());
private void test(String result) {
System.out.println(result);
assertTrue(result.contains(createdAt));
}
@Test
public void withObjectMapper() throws JsonProcessingException {
test(new ObjectMapper()
.registerModule(new JavaTimeModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.writeValueAsString(event));
}
@Test
public void withJSONObject() {
test(new JSONObject(event).toString());
}
@Test
public void withGson() {
test(new Gson().toJson(event));
}
}