From 4dec26de9c0533cfb3069731c8795822147943e6 Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sun, 2 Apr 2017 17:57:32 +0200 Subject: [PATCH] Generify check error response. This will help easier to test each method error response. Signed-off-by: Yahor Berdnikau --- .../api/subsonic/SubsonicAPITest.kt | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPITest.kt b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPITest.kt index d8019710..264eaffe 100644 --- a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPITest.kt +++ b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPITest.kt @@ -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 checkErrorCallParsed(apiRequest: () -> Response): 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() + } } \ No newline at end of file