|
| 1 | +package io.temporal.common.converter; |
| 2 | + |
| 3 | +import io.temporal.api.common.v1.Payloads; |
| 4 | +import java.lang.reflect.Method; |
| 5 | +import java.util.List; |
| 6 | +import java.util.Optional; |
| 7 | +import org.junit.Assert; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +public class DataConverterTest { |
| 11 | + // Test methods for reflection |
| 12 | + public String testMethodNormalParameter(String input, String names) { |
| 13 | + return ""; |
| 14 | + } |
| 15 | + |
| 16 | + public String testMethodGenericParameter(String input, List<String> names) { |
| 17 | + return ""; |
| 18 | + } |
| 19 | + |
| 20 | + public String testMethodGenericArrayParameter(String input, List<Integer>[] names) { |
| 21 | + return ""; |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void noContent() throws NoSuchMethodException { |
| 26 | + DataConverter dc = GlobalDataConverter.get(); |
| 27 | + Method m = this.getClass().getMethod("testMethodGenericParameter", String.class, List.class); |
| 28 | + Object[] result = |
| 29 | + dc.fromPayloads(Optional.empty(), m.getParameterTypes(), m.getGenericParameterTypes()); |
| 30 | + Assert.assertNull(result[0]); |
| 31 | + Assert.assertNull(result[1]); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void addParameter() throws NoSuchMethodException { |
| 36 | + DataConverter dc = GlobalDataConverter.get(); |
| 37 | + Optional<Payloads> p = dc.toPayloads("test"); |
| 38 | + Method m = this.getClass().getMethod("testMethodNormalParameter", String.class, String.class); |
| 39 | + Object[] result = dc.fromPayloads(p, m.getParameterTypes(), m.getGenericParameterTypes()); |
| 40 | + Assert.assertEquals("test", result[0]); |
| 41 | + Assert.assertNull(result[1]); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void addGenericParameter() throws NoSuchMethodException { |
| 46 | + DataConverter dc = GlobalDataConverter.get(); |
| 47 | + Optional<Payloads> p = dc.toPayloads("test"); |
| 48 | + Method m = this.getClass().getMethod("testMethodGenericParameter", String.class, List.class); |
| 49 | + Object[] result = dc.fromPayloads(p, m.getParameterTypes(), m.getGenericParameterTypes()); |
| 50 | + Assert.assertEquals("test", result[0]); |
| 51 | + Assert.assertNull(result[1]); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void addGenericArrayParameter() throws NoSuchMethodException { |
| 56 | + DataConverter dc = GlobalDataConverter.get(); |
| 57 | + Optional<Payloads> p = dc.toPayloads("test"); |
| 58 | + Method m = |
| 59 | + this.getClass().getMethod("testMethodGenericArrayParameter", String.class, List[].class); |
| 60 | + Object[] result = dc.fromPayloads(p, m.getParameterTypes(), m.getGenericParameterTypes()); |
| 61 | + Assert.assertEquals("test", result[0]); |
| 62 | + Assert.assertNull(result[1]); |
| 63 | + } |
| 64 | +} |
0 commit comments