Skip to content

Commit be3b4a4

Browse files
author
seal
committed
Exact Test cases from source code
Add some test cases
1 parent f0c8d5c commit be3b4a4

22 files changed

+399
-179
lines changed

.idea/libraries/com_winterbe_expekt_0_5_0.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JsonToKotlinClass.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
</content>
1111
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-171.4694.70" jdkType="IDEA JDK" />
1212
<orderEntry type="sourceFolder" forTests="false" />
13+
<orderEntry type="library" scope="TEST" name="com.winterbe:expekt:0.5.0" level="project" />
1314
</component>
1415
</module>

src/wu/seal/jsontokotlin/JsonElementTranslator.kt

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,6 @@ interface ITargetJsonElement {
1717
fun getTargetJsonElementForGeneratingCode(): JsonElement
1818
}
1919

20-
fun main(args: Array<String>) {
21-
22-
val gson = Gson()
23-
val text1 = """ {"UserID":11, "Name":"Truly", "Email":"zhuleipro◎hotmail.com"}"""
24-
val text2 = """ [
25-
{"UserID":11, "Name":{"FirstName":"Truly","LastName":"Zhu"}, "Email":"zhuleipro◎hotmail.com"},
26-
{"UserID":12, "Name":{"FirstName":"Jeffrey","LastName":"Richter"}, "Email":"xxx◎xxx.com"},
27-
{"UserID":13, "Name":{"FirstName":"Scott","LastName":"Gu"}, "Email":"xxx2◎xxx2.com"}
28-
]"""
29-
val text3 = """ [] """
30-
31-
val text4 = """ 1 """
32-
33-
val text5 = """[1,2,3]"""
34-
35-
val text6 = """["1","2","3"]"""
36-
37-
val text7 = """[1,"2",true]"""
38-
39-
40-
println("text1 getTargetElement ====>${getTargetElementJson(gson, text1)}")
41-
println("text2 getTargetElement ====>${getTargetElementJson(gson, text2)}")
42-
println("text3 getTargetElement ====>${getTargetElementJson(gson, text3)}")
43-
44-
println("text4 getTargetElement ====>${getTargetElementJson(gson, text4)}")
45-
println("text5 getTargetElement ====>${getTargetElementJson(gson, text5)}")
46-
println("text6 getTargetElement ====>${getTargetElementJson(gson, text6)}")
47-
println("text7 getTargetElement ====>${getTargetElementJson(gson, text7)}")
48-
}
49-
50-
private fun getTargetElementJson(gson: Gson, text1: String):String {
51-
return try {
52-
gson.toJson(TargetJsonElement(text1).getTargetJsonElementForGeneratingCode())
53-
} catch(e: Exception) {
54-
"UnSupport Json Format String !!"
55-
}
56-
}
57-
58-
5920
class TargetJsonElement : ITargetJsonElement {
6021
private val jsonElement: JsonElement
6122

src/wu/seal/jsontokotlin/KotlinMaker.kt

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -97,69 +97,3 @@ class KotlinMaker {
9797
}
9898

9999
}
100-
101-
fun main(args: Array<String>) {
102-
isTestModel = true
103-
val json1 = """{ "progr ammers": [
104-
{ "isFirstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
105-
{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },
106-
{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
107-
],
108-
"aut_hors": [
109-
{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
110-
{ "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
111-
{ "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
112-
],
113-
"musicians": [
114-
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
115-
{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
116-
] } """
117-
118-
val json2 = """ {"123menu": {
119-
"i d": [1,23,34],
120-
"value":[],
121-
"popup": {
122-
"m#@!$#%$#^%*^&(*)*(_)+{|}{:enu_item": [
123-
{"value": "New", "onclick": "CreateNewDoc()"},
124-
{"value": "Open", "onclick": "OpenDoc()"},
125-
{"value": "Close", "onclick": "CloseDoc()"}
126-
]}
127-
}}"""
128-
129-
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
130-
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
131-
132-
TestConfig.targetJsonConvertLib = TargetJsonConverter.Jackson
133-
TestConfig.isCommentOff = true
134-
TestConfig.isPropertiesVar = true
135-
TestConfig.isPropertyNullable = false
136-
137-
println("===========================================Change to Jackson json lib support========================================= ")
138-
139-
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
140-
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
141-
142-
143-
TestConfig.targetJsonConvertLib = TargetJsonConverter.FastJson
144-
TestConfig.isCommentOff = true
145-
TestConfig.isPropertiesVar = true
146-
TestConfig.isPropertyNullable = false
147-
148-
println("===========================================Change to FastJson json lib support========================================= ")
149-
150-
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
151-
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
152-
153-
154-
155-
TestConfig.targetJsonConvertLib = TargetJsonConverter.Gson
156-
TestConfig.isCommentOff = false
157-
TestConfig.isPropertiesVar = false
158-
TestConfig.isPropertyNullable = true
159-
160-
println("===========================================Change to Gson json lib support========================================= ")
161-
162-
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
163-
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
164-
165-
}

src/wu/seal/jsontokotlin/codeelements/DefaultValue.kt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,3 @@ fun getDefaultValue(propertyType: String): String {
3131
return "$rawType()"
3232
}
3333
}
34-
35-
data class Test(
36-
val a: String = "A"
37-
)
38-
39-
fun main(args: Array<String>) {
40-
41-
isTestModel = true
42-
43-
val json = """{"a":null} """
44-
45-
val gson = Gson()
46-
47-
val newJson = gson.toJson(JsonParser().parse(json))
48-
49-
val obj = gson.fromJson(newJson, Test::class.java)
50-
51-
println(obj)
52-
}

src/wu/seal/jsontokotlin/codeelements/KName.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,3 @@ abstract class KName : IKName {
6060
}
6161

6262
}
63-
64-
65-
fun main(args: Array<String>) {
66-
println("\\")
67-
}

src/wu/seal/jsontokotlin/statistics/Datas.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,3 @@ data class ConfigInfo(
2323
val daytime: String = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(Date())
2424

2525
)
26-
27-
28-
fun main(args: Array<String>) {
29-
isTestModel = true
30-
println(Gson().toJson(ConfigInfo()))
31-
}

src/wu/seal/jsontokotlin/statistics/NetWork.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,3 @@ fun sendConfigInfo() {
9595
e.printStackTrace()
9696
}
9797
}
98-
99-
fun main(args: Array<String>) {
100-
isTestModel = true
101-
102-
val demeoActionInfo = Gson().toJson(StartAction())
103-
sendExceptionLog("hello,I am exception")
104-
sendActionInfo(demeoActionInfo)
105-
106-
sendConfigInfo()
107-
}

src/wu/seal/jsontokotlin/supporter/NoneSupporter.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,15 @@ interface INoneLibSupporter {
1717
fun getNoneLibSupporterProperty(rawPropertyName: String, propertyType: String): String
1818

1919

20-
fun getNoneLibSupporterClassName(rawClassName: String)
20+
fun getNoneLibSupporterClassName(rawClassName: String):String
2121

2222
}
2323

24-
fun main(args: Array<String>) {
25-
26-
isTestModel = true
27-
println("getNoneLibSupporterProperty:\n ${NoneSupporter.getNoneLibSupporterProperty("seal is **() good_man ", "Boy")}")
28-
}
29-
3024

3125
object NoneSupporter : INoneLibSupporter {
3226

33-
override fun getNoneLibSupporterClassName(rawClassName: String) {
27+
override fun getNoneLibSupporterClassName(rawClassName: String):String {
28+
return ""
3429
}
3530

3631

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package wu.seal.jsontokotlin
2+
3+
import org.junit.Before
4+
import org.junit.Test
5+
6+
import org.junit.Assert.*
7+
8+
/**
9+
*
10+
* Created by Seal.Wu on 2018/2/6.
11+
*/
12+
class KotlinMakerTest {
13+
@Before
14+
fun setUp() {
15+
isTestModel = true
16+
}
17+
18+
@Test
19+
fun makeKotlinData() {
20+
val json1 = """{ "progr ammers": [
21+
{ "isFirstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
22+
{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },
23+
{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
24+
],
25+
"aut_hors": [
26+
{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
27+
{ "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
28+
{ "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
29+
],
30+
"musicians": [
31+
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
32+
{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
33+
] } """
34+
35+
val json2 = """ {"123menu": {
36+
"i d": [1,23,34],
37+
"value":[],
38+
"popup": {
39+
"m#@!$#%$#^%*^&(*)*(_)+{|}{:enu_item": [
40+
{"value": "New", "onclick": "CreateNewDoc()"},
41+
{"value": "Open", "onclick": "OpenDoc()"},
42+
{"value": "Close", "onclick": "CloseDoc()"}
43+
]}
44+
}}"""
45+
46+
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
47+
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
48+
49+
TestConfig.targetJsonConvertLib = TargetJsonConverter.Jackson
50+
TestConfig.isCommentOff = true
51+
TestConfig.isPropertiesVar = true
52+
TestConfig.isPropertyNullable = false
53+
54+
println("===========================================Change to Jackson json lib support========================================= ")
55+
56+
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
57+
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
58+
59+
60+
TestConfig.targetJsonConvertLib = TargetJsonConverter.FastJson
61+
TestConfig.isCommentOff = true
62+
TestConfig.isPropertiesVar = true
63+
TestConfig.isPropertyNullable = false
64+
65+
println("===========================================Change to FastJson json lib support========================================= ")
66+
67+
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
68+
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
69+
70+
71+
72+
TestConfig.targetJsonConvertLib = TargetJsonConverter.Gson
73+
TestConfig.isCommentOff = false
74+
TestConfig.isPropertiesVar = false
75+
TestConfig.isPropertyNullable = true
76+
77+
println("===========================================Change to Gson json lib support========================================= ")
78+
79+
println("json1 ====>\n${KotlinMaker("Class1", json1).makeKotlinData()}")
80+
println("json2 ====>\n${KotlinMaker("Class2", json2).makeKotlinData()}")
81+
}
82+
83+
}

0 commit comments

Comments
 (0)