Skip to content

Commit 20684ac

Browse files
Merge pull request #98 from vojtechhabarta/covariant-properties-test
Covariant properties
2 parents 19518f4 + ce7ebde commit 20684ac

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
package cz.habarta.typescript.generator;
3+
4+
import java.util.*;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
9+
public class CovariantPropertiesTest {
10+
11+
@Test
12+
public void test() {
13+
final Settings settings = TestUtils.settings();
14+
settings.sortDeclarations = true;
15+
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(Dog.class));
16+
final String expected =
17+
"interface Animal {\n" +
18+
" allFood: Food[];\n" +
19+
" todaysFood: Food;\n" +
20+
"}\n" +
21+
"\n" +
22+
"interface Dog extends Animal {\n" +
23+
" allFood: DogFood[];\n" +
24+
" todaysFood: DogFood;\n" +
25+
"}\n" +
26+
"\n" +
27+
"interface DogFood extends Food {\n" +
28+
"}\n" +
29+
"\n" +
30+
"interface Food {\n" +
31+
"}";
32+
Assert.assertEquals(expected.replace('\'', '"'), output.trim());
33+
}
34+
35+
private static abstract class Animal {
36+
public abstract Food getTodaysFood();
37+
public abstract List<? extends Food> getAllFood();
38+
}
39+
40+
private static abstract class Dog extends Animal {
41+
@Override
42+
public abstract DogFood getTodaysFood();
43+
@Override
44+
public abstract List<? extends DogFood> getAllFood();
45+
}
46+
47+
private static abstract class Food {
48+
}
49+
50+
private static abstract class DogFood extends Food {
51+
}
52+
53+
}

0 commit comments

Comments
 (0)