|
1 | 1 |
|
2 | 2 | package cz.habarta.typescript.generator; |
3 | 3 |
|
4 | | -import java.lang.reflect.*; |
5 | | -import java.util.*; |
6 | | -import org.junit.*; |
| 4 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
| 5 | +import cz.habarta.typescript.generator.compiler.ModelCompiler; |
| 6 | +import cz.habarta.typescript.generator.emitter.TsModel; |
| 7 | +import cz.habarta.typescript.generator.parser.Jackson2Parser; |
| 8 | +import cz.habarta.typescript.generator.parser.Model; |
| 9 | +import org.hamcrest.CoreMatchers; |
| 10 | +import org.junit.Assert; |
| 11 | +import org.junit.Test; |
7 | 12 |
|
| 13 | +import java.lang.reflect.Type; |
| 14 | +import java.util.Arrays; |
| 15 | +import java.util.Date; |
| 16 | +import java.util.List; |
| 17 | +import java.util.Map; |
8 | 18 |
|
9 | 19 | public class ModelCompilerTest { |
10 | 20 |
|
@@ -37,6 +47,46 @@ public void testExclusionPattern() throws Exception { |
37 | 47 | Assert.assertEquals("{ [index: string]: any }[]", TestUtils.compileType(settings, javaType).toString()); |
38 | 48 | } |
39 | 49 |
|
| 50 | + @Test |
| 51 | + public void testIntermediateInterfacesWithoutTypeParams() throws Exception { |
| 52 | + final Settings settings = TestUtils.settings(); |
| 53 | + |
| 54 | + final Jackson2Parser jacksonParser = new Jackson2Parser(settings, new DefaultTypeProcessor()); |
| 55 | + final Model model = jacksonParser.parseModel(Implementation.class); |
| 56 | + final ModelCompiler modelCompiler = new TypeScriptGenerator(settings).getModelCompiler(); |
| 57 | + |
| 58 | + final TsModel result = modelCompiler.javaToTypeScript(model); |
| 59 | + |
| 60 | + Assert.assertThat( |
| 61 | + result.getBean(WithoutTypeParam.class).getProperties().get(0).tsType, |
| 62 | + CoreMatchers.instanceOf(TsType.UnionType.class) |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testIntermediateInterfacesWithTypeParams() throws Exception { |
| 68 | + final Settings settings = TestUtils.settings(); |
| 69 | + |
| 70 | + final Jackson2Parser jacksonParser = new Jackson2Parser(settings, new DefaultTypeProcessor()); |
| 71 | + final Model model = jacksonParser.parseModel(Implementation.class); |
| 72 | + final ModelCompiler modelCompiler = new TypeScriptGenerator(settings).getModelCompiler(); |
| 73 | + |
| 74 | + final TsModel result = modelCompiler.javaToTypeScript(model); |
| 75 | + |
| 76 | + Assert.assertThat( |
| 77 | + result.getBean(WithTypeParam.class).getProperties().get(0).tsType, |
| 78 | + CoreMatchers.instanceOf(TsType.UnionType.class) |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) |
| 83 | + private static interface WithoutTypeParam {} |
| 84 | + |
| 85 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) |
| 86 | + private static interface WithTypeParam<T> {} |
| 87 | + |
| 88 | + private static class Implementation implements WithTypeParam<Integer>, WithoutTypeParam {} |
| 89 | + |
40 | 90 | private static Settings getTestSettings(String... excludedClassNames) { |
41 | 91 | final Settings settings = TestUtils.settings(); |
42 | 92 | settings.mapDate = DateMapping.asString; |
|
0 commit comments