-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventDeserializationTest.java
More file actions
46 lines (35 loc) · 1.38 KB
/
Copy pathEventDeserializationTest.java
File metadata and controls
46 lines (35 loc) · 1.38 KB
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
46
package com.techevents.model;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class EventDeserializationTest {
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
@Test
public void testValidJsonDeserialization() throws JsonProcessingException {
String json = """
{
"title": "Tech Conference",
"description": "Annual tech meetup",
"eventDate": "2025-06-01",
"city": "San Francisco",
"tags": ["conference", "dev"]
}
""";
Event event = objectMapper.readValue(json, Event.class);
assertEquals("Tech Conference", event.getTitle());
assertEquals(LocalDate.of(2025, 6, 1), event.getEventDate());
assertEquals("San Francisco", event.getCity());
assertEquals(List.of("conference", "dev"), event.getTags());
}
@Test
public void testInvalidJsonDeserialization() {
String invalidJson = "{ title: \"oops\" ";
assertThrows(JsonProcessingException.class, () -> {
objectMapper.readValue(invalidJson, Event.class);
});
}
}