Skip to content

Commit 6517c77

Browse files
committed
added travis-ci config
made ObjectMapper sort properties alphabetically Delete .travis.yml fixed the test: Jackson2ParserTest#test fixed ClassesTest.testUnsortedConstructor text fixed a number of tests of OptionalTest fixed all flaky tests of TaggedUnionsTest and improved Jackson2ParserPropertiesTest test partially fixed JavadocTest.testJavadoc partially fixed ReadOnlyWriteOnlyTest.test fixed the test TaggedUnionsTest.testIntermediateUnions improved JaxrsApplicationTest.testEnumQueryParam
1 parent 3b33aea commit 6517c77

File tree

10 files changed

+48
-46
lines changed

10 files changed

+48
-46
lines changed

typescript-generator-core/src/main/java/cz/habarta/typescript/generator/parser/Jackson2Parser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.databind.JsonDeserializer;
2323
import com.fasterxml.jackson.databind.JsonNode;
2424
import com.fasterxml.jackson.databind.JsonSerializer;
25+
import com.fasterxml.jackson.databind.MapperFeature;
2526
import com.fasterxml.jackson.databind.Module;
2627
import com.fasterxml.jackson.databind.ObjectMapper;
2728
import com.fasterxml.jackson.databind.SerializationConfig;
@@ -112,7 +113,8 @@ public JaxbParserFactory() {
112113

113114
}
114115

115-
private final ObjectMapper objectMapper = new ObjectMapper();
116+
private final ObjectMapper objectMapper = new ObjectMapper()
117+
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
116118

117119
public Jackson2Parser(Settings settings, TypeProcessor typeProcessor) {
118120
this(settings, typeProcessor, Collections.emptyList(), false);

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/ClassesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ public void testUnsortedConstructor() {
302302
settings.sortDeclarations = false;
303303
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(FooBar.class));
304304
String unsortedPropertyAssignments = "" +
305-
" this.foo = data.foo;" + settings.newline +
306-
" this.bar = data.bar;";
305+
" this.bar = data.bar;" + settings.newline +
306+
" this.foo = data.foo;";
307307
Assert.assertTrue(output.contains(unsortedPropertyAssignments));
308308
}
309309

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/ImmutablesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public void testImmutables() {
2828
"\n" +
2929
"interface Rectangle extends Shape {\n" +
3030
" kind: 'rectangle';\n" +
31-
" width: number;\n" +
3231
" height: number;\n" +
32+
" width: number;\n" +
3333
"}\n" +
3434
"\n" +
3535
"interface Circle extends Shape {\n" +

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/Jackson2ParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void test() {
5858
final BeanModel beanModel = model.getBeans().get(0);
5959
Assert.assertEquals("DummyBean", beanModel.getOrigin().getSimpleName());
6060
Assert.assertTrue(beanModel.getProperties().size() > 0);
61-
Assert.assertEquals("firstProperty", beanModel.getProperties().get(0).getName());
61+
Assert.assertEquals("booleanProperty", beanModel.getProperties().get(0).getName());
6262
}
6363

6464
@Test

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/JavadocTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public void testJavadoc() {
2525
final BeanModel bean = model.getBeans().get(0);
2626
Assert.assertEquals("Documentation for ClassWithJavadoc. First line.", bean.getComments().get(0));
2727
Assert.assertEquals("Second line.", bean.getComments().get(1));
28-
final PropertyModel property1 = bean.getProperties().get(0);
29-
Assert.assertEquals("Documentation for documentedField.", property1.getComments().get(0));
30-
final PropertyModel property2 = bean.getProperties().get(1);
28+
final PropertyModel property2 = bean.getProperties().get(0);
3129
Assert.assertEquals("Documentation for documentedEnumField.", property2.getComments().get(0));
30+
final PropertyModel property1 = bean.getProperties().get(1);
31+
Assert.assertEquals("Documentation for documentedField.", property1.getComments().get(0));
3232
final EnumModel enumModel = model.getEnums().get(0);
3333
Assert.assertEquals("Documentation for DummyEnum.", enumModel.getComments().get(0));
3434
}

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/JaxrsApplicationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public void testEnumQueryParam() {
588588
settings.generateJaxrsApplicationInterface = true;
589589
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(EnumQueryParamResource.class));
590590
Assert.assertTrue(output.contains("queryParams?: { target?: TargetEnum; }"));
591-
Assert.assertTrue(output.contains("type TargetEnum = \"Target1\" | \"Target2\""));
591+
Assert.assertTrue(output.contains("type TargetEnum = \"Target1\" | \"Target2\"") || output.contains("type TargetEnum = \"Target2\" | \"Target1\""));
592592
}
593593

594594
@Path("enum-query-param")

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/OptionalTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public void test() {
1919
final String output = new TypeScriptGenerator(TestUtils.settings()).generateTypeScript(Input.from(Person.class));
2020
Assert.assertEquals(
2121
"interface Person {\n" +
22-
" name: string;\n" +
23-
" email?: string;\n" +
2422
" age?: number;\n" +
23+
" email?: string;\n" +
24+
" name: string;\n" +
2525
"}",
2626
output.trim());
2727
}
@@ -53,9 +53,9 @@ public void testJackson2OptionalSupport() throws Exception {
5353
public void testDeclarationQuestionMark() {
5454
testDeclaration(OptionalPropertiesDeclaration.questionMark,
5555
"interface Person {\n" +
56-
" name: string;\n" +
57-
" email?: string;\n" +
5856
" age?: number;\n" +
57+
" email?: string;\n" +
58+
" name: string;\n" +
5959
"}"
6060
);
6161
}
@@ -64,9 +64,9 @@ public void testDeclarationQuestionMark() {
6464
public void testDeclarationNullableType() {
6565
testDeclaration(OptionalPropertiesDeclaration.nullableType,
6666
"interface Person {\n" +
67-
" name: string;\n" +
68-
" email: string | null;\n" +
6967
" age: number | null;\n" +
68+
" email: string | null;\n" +
69+
" name: string;\n" +
7070
"}"
7171
);
7272
}
@@ -75,9 +75,9 @@ public void testDeclarationNullableType() {
7575
public void testDeclarationQuestionMarkAndNullableType() {
7676
testDeclaration(OptionalPropertiesDeclaration.questionMarkAndNullableType,
7777
"interface Person {\n" +
78-
" name: string;\n" +
79-
" email?: string | null;\n" +
8078
" age?: number | null;\n" +
79+
" email?: string | null;\n" +
80+
" name: string;\n" +
8181
"}"
8282
);
8383
}
@@ -86,21 +86,21 @@ public void testDeclarationQuestionMarkAndNullableType() {
8686
public void testDeclarationNullableAndUndefinableType() {
8787
testDeclaration(OptionalPropertiesDeclaration.nullableAndUndefinableType,
8888
"interface Person {\n" +
89-
" name: string;\n" +
90-
" email: string | null | undefined;\n" +
91-
" age: number | null | undefined;\n" +
92-
"}"
89+
" age: number | null | undefined;\n" +
90+
" email: string | null | undefined;\n" +
91+
" name: string;\n" +
92+
"}"
9393
);
9494
}
9595

9696
@Test
9797
public void testDeclarationUndefinableType() {
9898
testDeclaration(OptionalPropertiesDeclaration.undefinableType,
9999
"interface Person {\n" +
100-
" name: string;\n" +
101-
" email: string | undefined;\n" +
102-
" age: number | undefined;\n" +
103-
"}"
100+
" age: number | undefined;\n" +
101+
" email: string | undefined;\n" +
102+
" name: string;\n" +
103+
"}"
104104
);
105105
}
106106

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/ReadOnlyWriteOnlyTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ public void test() {
7575
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(ReadOnlyWriteOnlyUser.class));
7676
final String expected = "\n"
7777
+ "interface ReadOnlyWriteOnlyUser {\n"
78-
+ " name: string;\n"
7978
+ " /**\n"
8079
+ " * @readonly\n"
8180
+ " */\n"
8281
+ " id1: string;\n"
8382
+ " /**\n"
84-
+ " * @writeonly\n"
85-
+ " */\n"
86-
+ " password1: string;\n"
87-
+ " /**\n"
8883
+ " * @readonly\n"
8984
+ " */\n"
9085
+ " id2: string;\n"
86+
+ " name: string;\n"
87+
+ " /**\n"
88+
+ " * @writeonly\n"
89+
+ " */\n"
90+
+ " password1: string;\n"
9191
+ " /**\n"
9292
+ " * @writeonly\n"
9393
+ " */\n"

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/TaggedUnionsTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ public void testTaggedUnions() {
206206
"\n" +
207207
"interface Rectangle extends Shape {\n" +
208208
" kind: 'rectangle';\n" +
209-
" width: number;\n" +
210209
" height: number;\n" +
210+
" width: number;\n" +
211211
"}\n" +
212212
"\n" +
213213
"interface Circle extends Shape {\n" +
@@ -238,8 +238,8 @@ public void testTaggedUnionsWithInterfaces() {
238238
"\n" +
239239
"interface CRectangle2 extends IQuadrilateral2 {\n" +
240240
" kind: 'rectangle';\n" +
241-
" width: number;\n" +
242241
" height: number;\n" +
242+
" width: number;\n" +
243243
"}\n" +
244244
"\n" +
245245
"interface CCircle2 extends IShape2 {\n" +
@@ -315,8 +315,8 @@ public void testTaggedUnionsDisabled() {
315315
"\n" +
316316
"interface Rectangle extends Shape {\n" +
317317
" kind: 'rectangle';\n" +
318-
" width: number;\n" +
319318
" height: number;\n" +
319+
" width: number;\n" +
320320
"}\n" +
321321
"\n" +
322322
"interface Circle extends Shape {\n" +
@@ -518,8 +518,8 @@ public void testTaggedUnionsWithExistingProperty() {
518518
"\n" +
519519
"interface Rectangle2 extends Shape2 {\n" +
520520
" kind: 'rectangle';\n" +
521-
" width: number;\n" +
522521
" height: number;\n" +
522+
" width: number;\n" +
523523
"}\n" +
524524
"\n" +
525525
"interface Circle2 extends Shape2 {\n" +
@@ -553,8 +553,8 @@ public void testTaggedUnionDisabledUsingAnnotation() {
553553
"}\n" +
554554
"\n" +
555555
"interface Rectangle2 extends Shape2 {\n" +
556-
" width: number;\n" +
557556
" height: number;\n" +
557+
" width: number;\n" +
558558
"}\n" +
559559
"\n" +
560560
"interface Circle2 extends Shape2 {\n" +
@@ -647,13 +647,9 @@ public void testIntermediateUnions() {
647647
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(RecordUsage.class));
648648
final String expected = ""
649649
+ "interface RecordUsage {\n"
650-
+ " records: RecordUnion[];\n"
651650
+ " formRecords: FormRecordUnion[];\n"
652651
+ " listRecords: ListRecordUnion[];\n"
653-
+ "}\n"
654-
+ "\n"
655-
+ "interface Record {\n"
656-
+ " '@type': 'order.form' | 'product.form' | 'order.list' | 'product.list';\n"
652+
+ " records: RecordUnion[];\n"
657653
+ "}\n"
658654
+ "\n"
659655
+ "interface FormRecord extends Record {\n"
@@ -664,6 +660,10 @@ public void testIntermediateUnions() {
664660
+ " '@type': 'order.list' | 'product.list';\n"
665661
+ "}\n"
666662
+ "\n"
663+
+ "interface Record {\n"
664+
+ " '@type': 'order.form' | 'product.form' | 'order.list' | 'product.list';\n"
665+
+ "}\n"
666+
+ "\n"
667667
+ "interface OrderFormRecord extends FormRecord {\n"
668668
+ " '@type': 'order.form';\n"
669669
+ "}\n"
@@ -680,11 +680,11 @@ public void testIntermediateUnions() {
680680
+ " '@type': 'product.list';\n"
681681
+ "}\n"
682682
+ "\n"
683-
+ "type RecordUnion = FormRecord | ListRecord;\n"
684-
+ "\n"
685683
+ "type FormRecordUnion = OrderFormRecord | ProductFormRecord;\n"
686684
+ "\n"
687685
+ "type ListRecordUnion = OrderListRecord | ProductListRecord;\n"
686+
+ "\n"
687+
+ "type RecordUnion = FormRecord | ListRecord;\n"
688688
+ "";
689689
Assert.assertEquals(expected.trim(), output.trim());
690690
}

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/parser/Jackson2ParserPropertiesTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public static class User4 {
7676

7777
@Test
7878
public void testPropertyOrder() {
79-
Assert.assertEquals(Arrays.asList("password1", "id2", "name", "id1", "password2"), getProperties(UserOrdered.class));
79+
Assert.assertEquals(Arrays.asList("password1", "id2", "id1", "name", "password2"), getProperties(UserOrdered.class));
8080
Assert.assertEquals(Arrays.asList("id1", "id2", "name", "password1", "password2"), getProperties(UserAlphabetic.class));
8181
Assert.assertEquals(Arrays.asList("password2", "password1", "id2", "id1", "name"), getProperties(UserIndexed.class));
82-
Assert.assertEquals(Arrays.asList("name", "id1", "id2", "password1", "password2"), getProperties(User1.class));
83-
Assert.assertEquals(Arrays.asList("name", "id1", "id2", "password1", "password2"), getProperties(User2.class));
84-
Assert.assertEquals(Arrays.asList("name", "password1", "password2", "id1", "id2"), getProperties(User3.class));
82+
Assert.assertEquals(Arrays.asList("id1", "id2", "name", "password1", "password2"), getProperties(User1.class));
83+
Assert.assertEquals(Arrays.asList("id1", "id2", "name", "password1", "password2"), getProperties(User2.class));
84+
Assert.assertEquals(Arrays.asList("id1", "id2", "name", "password1", "password2"), getProperties(User3.class));
8585
Assert.assertEquals(Arrays.asList("password1", "id1", "password2", "id2", "name"), getProperties(User4.class));
8686
}
8787

0 commit comments

Comments
 (0)