Generify check error response.

This will help easier to test each method error response.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-04-02 17:57:32 +02:00
parent cfa90e0a8d
commit 4dec26de9c
1 changed files with 19 additions and 22 deletions

View File

@ -53,21 +53,12 @@ class SubsonicAPITest {
}
@Test
fun `Should parse error response`() {
enqueueResponse("generic_error_response.json")
val response = api.getApi().ping().execute()
assertResponseSuccessful(response)
with(response.body()) {
status `should be` SubsonicResponse.Status.ERROR
version `should be` SubsonicAPIVersions.V1_13_0
error `should be` SubsonicError.GENERIC
}
fun `Should parse ping error response`() {
checkErrorCallParsed { api.getApi().ping().execute() }
}
@Test
fun `Should parse get license response`() {
fun `Should parse get license ok response`() {
enqueueResponse("license_ok.json")
val response = api.getApi().getLicense().execute()
@ -81,17 +72,10 @@ class SubsonicAPITest {
}
@Test
fun `Should parse error get license response`() {
enqueueResponse("generic_error_response.json")
fun `Should parse get license error response`() {
val response = checkErrorCallParsed { api.getApi().getLicense().execute() }
val response = api.getApi().getLicense().execute()
assertResponseSuccessful(response)
with(response.body()) {
status `should be` SubsonicResponse.Status.ERROR
error `should be` SubsonicError.GENERIC
license `should be` null
}
response.license `should be` null
}
private fun enqueueResponse(resourceName: String) {
@ -116,4 +100,17 @@ class SubsonicAPITest {
return result
}
private fun <T: SubsonicResponse> checkErrorCallParsed(apiRequest: () -> Response<T>): T {
enqueueResponse("generic_error_response.json")
val response = apiRequest()
assertResponseSuccessful(response)
with(response.body()) {
status `should be` SubsonicResponse.Status.ERROR
error `should be` SubsonicError.GENERIC
}
return response.body()
}
}