Skip to content

Commit 2d84b96

Browse files
committed
Convert RetrofitResponseTypeKeepProcessorTest to parametermized tests
1 parent 9640107 commit 2d84b96

8 files changed

Lines changed: 88 additions & 116 deletions

File tree

retrofit-response-type-keeper/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ dependencies {
1111
testImplementation libs.junit
1212
testImplementation libs.compileTesting
1313
testImplementation libs.truth
14+
testImplementation libs.testParameterInjector
1415
testImplementation projects.retrofit
1516
}

retrofit-response-type-keeper/src/test/kotlin/retrofit2/keeper/RetrofitResponseTypeKeepProcessorTest.kt

Lines changed: 22 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -18,86 +18,29 @@ package retrofit2.keeper
1818
import com.google.common.truth.Truth.assertAbout
1919
import com.google.testing.compile.JavaFileObjects
2020
import com.google.testing.compile.JavaSourceSubjectFactory.javaSource
21+
import com.google.testing.junit.testparameterinjector.TestParameter
22+
import com.google.testing.junit.testparameterinjector.TestParameterInjector
2123
import java.nio.charset.StandardCharsets.UTF_8
24+
import java.nio.file.NoSuchFileException
2225
import javax.tools.StandardLocation.CLASS_OUTPUT
26+
import kotlin.io.path.readText
27+
import kotlin.io.path.toPath
2328
import org.junit.Test
29+
import org.junit.runner.RunWith
2430

31+
@RunWith(TestParameterInjector::class)
2532
class RetrofitResponseTypeKeepProcessorTest {
2633
@Test
27-
fun allHttpMethods() {
34+
fun process(
35+
@TestParameter(
36+
"all-http-methods",
37+
"nesting",
38+
"kotlin-suspend",
39+
) name: String
40+
) {
2841
val service = JavaFileObjects.forSourceString(
2942
"test.Service",
30-
"""
31-
package test;
32-
import retrofit2.*;
33-
import retrofit2.http.*;
34-
35-
class DeleteUser {}
36-
class GetUser {}
37-
class HeadUser {}
38-
class HttpUser {}
39-
class OptionsUser {}
40-
class PatchUser {}
41-
class PostUser {}
42-
class PutUser {}
43-
44-
interface Service {
45-
@DELETE("/") Call<DeleteUser> delete();
46-
@GET("/") Call<GetUser> get();
47-
@HEAD("/") Call<HeadUser> head();
48-
@HTTP(method = "CUSTOM", path = "/") Call<HttpUser> http();
49-
@OPTIONS("/") Call<OptionsUser> options();
50-
@PATCH("/") Call<PatchUser> patch();
51-
@POST("/") Call<PostUser> post();
52-
@PUT("/") Call<PutUser> put();
53-
}
54-
""".trimIndent(),
55-
)
56-
57-
assertAbout(javaSource())
58-
.that(service)
59-
.processedWith(RetrofitResponseTypeKeepProcessor())
60-
.compilesWithoutError()
61-
.and()
62-
.generatesFileNamed(
63-
CLASS_OUTPUT,
64-
"",
65-
"META-INF/proguard/retrofit-response-type-keeper-test.Service.pro",
66-
).withStringContents(
67-
UTF_8,
68-
"""
69-
|# test.Service
70-
|-keep,allowoptimization,allowshrinking,allowobfuscation class retrofit2.Call
71-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.DeleteUser
72-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.GetUser
73-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.HeadUser
74-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.HttpUser
75-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.OptionsUser
76-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.PatchUser
77-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.PostUser
78-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.PutUser
79-
|
80-
""".trimMargin(),
81-
)
82-
}
83-
84-
@Test
85-
fun nesting() {
86-
val service = JavaFileObjects.forSourceString(
87-
"test.Service",
88-
"""
89-
package test;
90-
import retrofit2.*;
91-
import retrofit2.http.*;
92-
93-
class One<T> {}
94-
class Two<T> {}
95-
class Three {}
96-
97-
interface Service {
98-
@GET("/") Call<One<Two<Three>>> get();
99-
}
100-
""".trimIndent(),
43+
readResourceAsText("$name/Service.java"),
10144
)
10245

10346
assertAbout(javaSource())
@@ -111,52 +54,15 @@ class RetrofitResponseTypeKeepProcessorTest {
11154
"META-INF/proguard/retrofit-response-type-keeper-test.Service.pro",
11255
).withStringContents(
11356
UTF_8,
114-
"""
115-
|# test.Service
116-
|-keep,allowoptimization,allowshrinking,allowobfuscation class retrofit2.Call
117-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.One
118-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.Three
119-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.Two
120-
|
121-
""".trimMargin(),
57+
readResourceAsText("$name/Service.pro"),
12258
)
12359
}
12460

125-
@Test
126-
fun kotlinSuspend() {
127-
val service = JavaFileObjects.forSourceString(
128-
"test.Service",
129-
"""
130-
package test;
131-
import kotlin.coroutines.Continuation;
132-
import retrofit2.*;
133-
import retrofit2.http.*;
134-
135-
class Body {}
136-
137-
interface Service {
138-
@GET("/") Object get(Continuation<? extends Body> c);
139-
}
140-
""".trimIndent(),
141-
)
142-
143-
assertAbout(javaSource())
144-
.that(service)
145-
.processedWith(RetrofitResponseTypeKeepProcessor())
146-
.compilesWithoutError()
147-
.and()
148-
.generatesFileNamed(
149-
CLASS_OUTPUT,
150-
"",
151-
"META-INF/proguard/retrofit-response-type-keeper-test.Service.pro",
152-
).withStringContents(
153-
UTF_8,
154-
"""
155-
|# test.Service
156-
|-keep,allowoptimization,allowshrinking,allowobfuscation class java.lang.Object
157-
|-keep,allowoptimization,allowshrinking,allowobfuscation class test.Body
158-
|
159-
""".trimMargin(),
160-
)
61+
private companion object {
62+
fun readResourceAsText(name: String): String {
63+
val resource = RetrofitResponseTypeKeepProcessorTest::class.java.classLoader.getResource(name)
64+
?: throw NoSuchFileException("Resource $name not found.")
65+
return resource.toURI().toPath().readText()
66+
}
16167
}
16268
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test;
2+
3+
import retrofit2.*;
4+
import retrofit2.http.*;
5+
6+
class DeleteUser {}
7+
class GetUser {}
8+
class HeadUser {}
9+
class HttpUser {}
10+
class OptionsUser {}
11+
class PatchUser {}
12+
class PostUser {}
13+
class PutUser {}
14+
15+
interface Service {
16+
@DELETE("/") Call<DeleteUser> delete();
17+
@GET("/") Call<GetUser> get();
18+
@HEAD("/") Call<HeadUser> head();
19+
@HTTP(method = "CUSTOM", path = "/") Call<HttpUser> http();
20+
@OPTIONS("/") Call<OptionsUser> options();
21+
@PATCH("/") Call<PatchUser> patch();
22+
@POST("/") Call<PostUser> post();
23+
@PUT("/") Call<PutUser> put();
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# test.Service
2+
-keep,allowoptimization,allowshrinking,allowobfuscation class retrofit2.Call
3+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.DeleteUser
4+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.GetUser
5+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.HeadUser
6+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.HttpUser
7+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.OptionsUser
8+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.PatchUser
9+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.PostUser
10+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.PutUser
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package test;
2+
3+
import kotlin.coroutines.Continuation;
4+
import retrofit2.*;
5+
import retrofit2.http.*;
6+
7+
class Body {}
8+
9+
interface Service {
10+
@GET("/") Object get(Continuation<? extends Body> c);
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# test.Service
2+
-keep,allowoptimization,allowshrinking,allowobfuscation class java.lang.Object
3+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.Body
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test;
2+
3+
import retrofit2.*;
4+
import retrofit2.http.*;
5+
6+
class One<T> {}
7+
class Two<T> {}
8+
class Three {}
9+
10+
interface Service {
11+
@GET("/") Call<One<Two<Three>>> get();
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# test.Service
2+
-keep,allowoptimization,allowshrinking,allowobfuscation class retrofit2.Call
3+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.One
4+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.Three
5+
-keep,allowoptimization,allowshrinking,allowobfuscation class test.Two

0 commit comments

Comments
 (0)