-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make code generation for qualifiedTypeName configurable (#542)
- Loading branch information
Showing
13 changed files
with
183 additions
and
29 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
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
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
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
88 changes: 88 additions & 0 deletions
88
ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/KtorfitOptionsTest.kt
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,88 @@ | ||
package de.jensklingenberg.ktorfit | ||
|
||
import com.tschuchort.compiletesting.KotlinCompilation | ||
import com.tschuchort.compiletesting.SourceFile | ||
import com.tschuchort.compiletesting.kspSourcesDir | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import java.io.File | ||
|
||
class KtorfitOptionsTest { | ||
|
||
@Test | ||
fun `when QualifiedType options not set then don't generate qualifiedTypeName`() { | ||
|
||
val expected = "qualifiedTypename =\n" + | ||
" \"kotlin.collections.List<kotlin.Triple<kotlin.String,kotlin.Int?,kotlin.String>>\")" | ||
val source = SourceFile.kotlin( | ||
"Source.kt", """ | ||
package com.example.api | ||
import de.jensklingenberg.ktorfit.http.GET | ||
import de.jensklingenberg.ktorfit.http.Path | ||
class Test<T> | ||
interface TestService { | ||
@GET("posts") | ||
suspend fun test(): List<Triple<String,Int?,String>> | ||
} | ||
""" | ||
) | ||
|
||
val source2 = SourceFile.kotlin( | ||
"Source.kt", """ | ||
package com.example.api2 | ||
""" | ||
) | ||
|
||
val compilation = getCompilation(listOf(source2, source), mutableMapOf()) | ||
val result = compilation.compile() | ||
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode) | ||
val generatedSourcesDir = compilation.kspSourcesDir | ||
val generatedFile = File( | ||
generatedSourcesDir, | ||
"/kotlin/com/example/api/_TestServiceImpl.kt" | ||
) | ||
val actualSource = generatedFile.readText() | ||
assertFalse(actualSource.contains(expected)) | ||
} | ||
|
||
@Test | ||
fun `when QualifiedType options is set then generate qualifiedTypeName`() { | ||
|
||
val expected = "qualifiedTypename" | ||
val source = SourceFile.kotlin( | ||
"Source.kt", """ | ||
package com.example.api | ||
import de.jensklingenberg.ktorfit.http.GET | ||
import de.jensklingenberg.ktorfit.http.Path | ||
class Test<T> | ||
interface TestService { | ||
@GET("posts") | ||
suspend fun test(): List<Triple<String,Int?,String>> | ||
} | ||
""" | ||
) | ||
|
||
val source2 = SourceFile.kotlin( | ||
"Source.kt", """ | ||
package com.example.api2 | ||
""" | ||
) | ||
|
||
val compilation = getCompilation(listOf(source2, source), mutableMapOf("Ktorfit_QualifiedTypeName" to "true")) | ||
val result = compilation.compile() | ||
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode) | ||
val generatedSourcesDir = compilation.kspSourcesDir | ||
val generatedFile = File( | ||
generatedSourcesDir, | ||
"/kotlin/com/example/api/_TestServiceImpl.kt" | ||
) | ||
val actualSource = generatedFile.readText() | ||
assertTrue(actualSource.contains(expected)) | ||
} | ||
} |
8 changes: 3 additions & 5 deletions
8
ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/Utils.kt
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
package de.jensklingenberg.ktorfit | ||
|
||
import com.tschuchort.compiletesting.KotlinCompilation | ||
import com.tschuchort.compiletesting.SourceFile | ||
import com.tschuchort.compiletesting.kspIncremental | ||
import com.tschuchort.compiletesting.symbolProcessorProviders | ||
import com.tschuchort.compiletesting.* | ||
|
||
fun getCompilation(sources: List<SourceFile>): KotlinCompilation { | ||
fun getCompilation(sources: List<SourceFile>, kspArgs : MutableMap<String,String> = mutableMapOf()): KotlinCompilation { | ||
return KotlinCompilation().apply { | ||
this.sources = sources | ||
inheritClassPath = true | ||
symbolProcessorProviders = listOf(KtorfitProcessorProvider()) | ||
kspIncremental = true | ||
this.kspArgs = kspArgs | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -32,8 +32,6 @@ val jvmClient = HttpClient { | |
|
||
this.developmentMode = true | ||
expectSuccess = false | ||
|
||
|
||
} | ||
|
||
|
||
|
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