diff --git a/odp/src/androidTest/java/com/optimizely/ab/android/odp/ODPSegmentClientTest.kt b/odp/src/androidTest/java/com/optimizely/ab/android/odp/ODPSegmentClientTest.kt index ec18f126..c3027843 100644 --- a/odp/src/androidTest/java/com/optimizely/ab/android/odp/ODPSegmentClientTest.kt +++ b/odp/src/androidTest/java/com/optimizely/ab/android/odp/ODPSegmentClientTest.kt @@ -68,45 +68,45 @@ class ODPSegmentClientTest { verify(urlConnection).disconnect() } -// @Test -// fun fetchQualifiedSegments_400() { -// `when`(urlConnection.responseCode).thenReturn(400) -// -// segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload) -// -// verify(client).execute(captor.capture(), eq(0), eq(0)) -// val received = captor.value.execute() -// -// assertNull(received) -// verify(logger).error("Unexpected response from ODP segment endpoint, status: 400") -// verify(urlConnection).disconnect() -// } - -// @Test -// fun fetchQualifiedSegments_500() { -// `when`(urlConnection.responseCode).thenReturn(500) -// -// segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload) -// -// verify(client).execute(captor.capture(), eq(0), eq(0)) -// val received = captor.value.execute() -// -// assertNull(received) -// verify(logger).error("Unexpected response from ODP segment endpoint, status: 500") -// verify(urlConnection).disconnect() -// } - -// @Test -// fun fetchQualifiedSegments_connectionFailed() { -// `when`(urlConnection.responseCode).thenReturn(200) -// -// apiEndpoint = "invalid-url" -// segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload) -// -// verify(client).execute(captor.capture(), eq(0), eq(0)) -// val received = captor.value.execute() -// -// assertNull(received) -// verify(logger).error(contains("Error making ODP segment request"), any()) -// } + @Test + fun fetchQualifiedSegments_400() { + `when`(urlConnection.responseCode).thenReturn(400) + + segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload) + + verify(client).execute(captor.capture(), eq(0), eq(0)) + val received = captor.value.execute() + + assertNull(received) + verify(logger).error("Unexpected response from ODP segment endpoint, status: 400") + verify(urlConnection).disconnect() + } + + @Test + fun fetchQualifiedSegments_500() { + `when`(urlConnection.responseCode).thenReturn(500) + + segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload) + + verify(client).execute(captor.capture(), eq(0), eq(0)) + val received = captor.value.execute() + + assertNull(received) + verify(logger).error("Unexpected response from ODP segment endpoint, status: 500") + verify(urlConnection).disconnect() + } + + @Test + fun fetchQualifiedSegments_connectionFailed() { + `when`(urlConnection.responseCode).thenReturn(200) + + apiEndpoint = "invalid-url" + segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload) + + verify(client).execute(captor.capture(), eq(0), eq(0)) + val received = captor.value.execute() + + assertNull(received) + verify(logger).error(contains("Error making ODP segment request"), any()) + } } diff --git a/odp/src/main/java/com/optimizely/ab/android/odp/ODPSegmentClient.kt b/odp/src/main/java/com/optimizely/ab/android/odp/ODPSegmentClient.kt index 1d8d7496..c8875047 100644 --- a/odp/src/main/java/com/optimizely/ab/android/odp/ODPSegmentClient.kt +++ b/odp/src/main/java/com/optimizely/ab/android/odp/ODPSegmentClient.kt @@ -62,13 +62,11 @@ open class ODPSegmentClient(private val client: ClientForODPOnly, private val lo } else { var errMsg = "Unexpected response from ODP segment endpoint, status: $status" logger.error(errMsg) -// return@Request null - throw Exception(errMsg) + return@Request null } } catch (e: Exception) { logger.error("Error making ODP segment request", e) - // return@Request null - throw e + return@Request null } finally { if (urlConnection != null) { try {