mirror of
https://github.com/hmalik144/api-testing-automation-framework.git
synced 2025-12-10 02:55:21 +00:00
Initial commit
- Retrofit used to call API
This commit is contained in:
20
src/test/kotlin/NetworkTests.kt
Normal file
20
src/test/kotlin/NetworkTests.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import retrofit2.Response
|
||||
import java.io.IOException
|
||||
|
||||
abstract class NetworkTests {
|
||||
|
||||
fun <T : Any> responseUnwrap(
|
||||
call: suspend () -> Response<T>
|
||||
): T {
|
||||
|
||||
val response = runBlocking { call.invoke() }
|
||||
if (response.isSuccessful) {
|
||||
return response.body()!!
|
||||
} else {
|
||||
val error = response.errorBody()?.string()
|
||||
|
||||
throw IOException(error ?: "Unable to handle end point")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user