Skip to content

Commit 3a62c10

Browse files
committed
Added test to explain usage of Swagger Codegen with Retrofit
1 parent 2bec121 commit 3a62c10

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

samples/generated-code/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ dependencies {
4646
// RxJava
4747
implementation "io.reactivex.rxjava2:rxjava:2.2.4"
4848
implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
49+
50+
// JUnit4
51+
testImplementation "junit:junit:4.12"
4952
}
5053

5154
generateSwagger {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.yelp.codegen.generatecodesamples
2+
3+
import com.yelp.codegen.generatecodesamples.apis.DefaultApi
4+
import com.yelp.codegen.generatecodesamples.tools.GeneratedCodeConverters
5+
import org.junit.Assert.assertEquals
6+
import org.junit.Test
7+
import retrofit2.Retrofit
8+
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
9+
10+
class InvokeRetrofitTest {
11+
12+
@Test
13+
fun createAndInvokeRetrofit() {
14+
val retrofit: Retrofit = Retrofit.Builder()
15+
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
16+
.addConverterFactory(GeneratedCodeConverters.converterFactory())
17+
.baseUrl("https://petstore.swagger.io/v2/")
18+
.build()
19+
20+
val defaultApi = retrofit.create(DefaultApi::class.java)
21+
val pet = defaultApi.getPetById(1).blockingGet()
22+
23+
println(pet)
24+
assertEquals(1L, pet.id)
25+
}
26+
}

0 commit comments

Comments
 (0)