1 package com.github.jonasrutishauser.transactional.event.api.serialization;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertThrows;
5 import static org.junit.jupiter.api.Assertions.fail;
6
7 import java.util.List;
8 import java.util.function.Function;
9
10 import org.junit.jupiter.api.Test;
11
12 class EventSerializerTest {
13
14 @Test
15 void testGetTypeSimpleClass() {
16 assertEquals(Integer.class, new EventSerializer<Integer>() {
17 @Override
18 public String serialize(Integer event) {
19 return fail("should not be called");
20 }
21 }.getType());
22 }
23
24 @Test
25 void testGetTypeGeneric() {
26 assertEquals(List.class, new EventSerializer<List<String>>() {
27 @Override
28 public String serialize(List<String> event) {
29 return fail("should not be called");
30 }
31 }.getType());
32 }
33
34 @Test
35 void testGetTypeLambda() {
36 assertThrows(IllegalStateException.class,
37 ((EventSerializer<Boolean>) event -> fail("should not be called"))::getType,
38 "Class does not implement EventSerializer directly");
39 }
40
41 @Test
42 void testGetTypeGenericClass() {
43 assertThrows(IllegalStateException.class, new TestSerializer<Boolean>()::getType,
44 "Class does not implement EventSerializer directly");
45 }
46
47 private static class TestSerializer<T> implements Function<String, String>, EventSerializer<T> {
48 @Override
49 public String serialize(T event) {
50 return fail("should not be called");
51 }
52
53 @Override
54 public String apply(String value) {
55 return fail("should not be called");
56 }
57 }
58
59 }