-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6723aa3
commit 76f587e
Showing
3 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...tor-core/src/test/java/cz/habarta/typescript/generator/GenericCustomTypeMappingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
package cz.habarta.typescript.generator; | ||
|
||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
|
||
public class GenericCustomTypeMappingsTest { | ||
|
||
@Test | ||
public void testListWrapper() { | ||
final Settings settings = TestUtils.settings(); | ||
settings.customTypeNaming = Collections.singletonMap(ListWrapper1.class.getName(), "ListWrapper"); | ||
settings.customTypeMappings = Collections.singletonMap(ListWrapper2.class.getName(), "ListWrapper"); | ||
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(Class1.class)); | ||
Assert.assertTrue(output.contains("list1: ListWrapper<string>")); | ||
Assert.assertTrue(output.contains("list2: ListWrapper<number>")); | ||
} | ||
|
||
private static class Class1 { | ||
public ListWrapper1<String> list1; | ||
public ListWrapper2<Number> list2; | ||
} | ||
|
||
private static class ListWrapper1<T> { | ||
public List<T> values; | ||
} | ||
|
||
private static class ListWrapper2<T> { | ||
public List<T> values; | ||
} | ||
|
||
@Test | ||
public void testMap() { | ||
final Settings settings = TestUtils.settings(); | ||
settings.customTypeMappings = Collections.singletonMap("java.util.Map", "Map"); | ||
settings.mapDate = DateMapping.asString; | ||
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(Class2.class)); | ||
Assert.assertTrue(output.contains("someMap: Map<string, any>")); | ||
Assert.assertTrue(output.contains("dateMap: Map<string, DateAsString>")); | ||
} | ||
|
||
private static class Class2 { | ||
public Map<String, Object> someMap; | ||
public Map<String, Date> dateMap; | ||
} | ||
|
||
} |