Skip to content

Commit

Permalink
Remove as Call<Any> cast in ClientInvocationHandler (#1855)
Browse files Browse the repository at this point in the history
* Remove as Call<Any> cast in ClientInvocationHandler

* add test

Co-authored-by: Jesse Wilson <jesse@swank.ca>
  • Loading branch information
Felix Jancso-Szabo and swankjesse authored Apr 15, 2021
1 parent ae89ecb commit 9593078
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal class ClientInvocationHandler(
"no action corresponding to ${interfaceType.qualifiedName}#${method.name}"
)

return method.invoke(retrofitProxy, *argsList.toTypedArray()) as Call<Any>
return method.invoke(retrofitProxy, *argsList.toTypedArray())
}
}

Expand Down
21 changes: 21 additions & 0 deletions misk/src/test/kotlin/misk/client/TypedHttpClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.inject.Injector
import com.google.inject.Provides
import com.google.inject.name.Names
import helpers.protos.Dinosaur
import kotlinx.coroutines.runBlocking
import misk.MiskTestingServiceModule
import misk.inject.KAbstractModule
import misk.inject.getInstance
Expand Down Expand Up @@ -103,11 +104,27 @@ internal class TypedHttpClientTest {
)
}

@Test
fun suspendingMethod() {
val client: ReturnADinosaurNonBlocking = clientInjector.getInstance(
Names.named("nonblockingDinosaur")
)
val response = runBlocking {
client.getDinosaur(Dinosaur.Builder().name("trex").build())
}
assertThat(response.name!!).isEqualTo("supertrex")
}

interface ReturnADinosaur {
@POST("/cooldinos")
fun getDinosaur(@Body request: Dinosaur): Call<Dinosaur>
}

interface ReturnADinosaurNonBlocking {
@POST("/cooldinos")
suspend fun getDinosaur(@Body request: Dinosaur): Dinosaur
}

class ReturnADinosaurAction @Inject constructor() : WebAction {
@Post("/cooldinos")
@RequestContentType(MediaTypes.APPLICATION_JSON)
Expand Down Expand Up @@ -150,6 +167,10 @@ internal class TypedHttpClientTest {
override fun configure() {
install(MiskTestingServiceModule())
install(TypedHttpClientModule.create<ReturnADinosaur>("dinosaur", Names.named("dinosaur")))
install(TypedHttpClientModule.create<ReturnADinosaurNonBlocking>(
"dinosaur",
Names.named("nonblockingDinosaur")
))
install(
TypedHttpClientModule.create<ReturnAProtoDinosaur>("protoDino", Names.named("protoDino"))
)
Expand Down

0 comments on commit 9593078

Please sign in to comment.