1515package com.optimizely.ab.android.odp
1616
1717import androidx.test.ext.junit.runners.AndroidJUnit4
18- import com.optimizely.ab.android.shared.ClientForODPOnly
18+ import com.optimizely.ab.android.shared.Client
1919import java.io.OutputStream
2020import java.net.HttpURLConnection
2121import org.junit.Assert.assertNull
@@ -34,9 +34,9 @@ import org.slf4j.Logger
3434@RunWith(AndroidJUnit4 ::class )
3535class ODPSegmentClientTest {
3636 private val logger = mock(Logger ::class .java)
37- private val client = mock(ClientForODPOnly ::class .java)
37+ private val client = mock(Client ::class .java)
3838 private val urlConnection = mock(HttpURLConnection ::class .java)
39- private val captor = ArgumentCaptor .forClass(ClientForODPOnly .Request ::class .java)
39+ private val captor = ArgumentCaptor .forClass(Client .Request ::class .java)
4040 private lateinit var segmentClient: ODPSegmentClient
4141
4242 private val apiKey = " valid-key"
@@ -68,45 +68,45 @@ class ODPSegmentClientTest {
6868 verify(urlConnection).disconnect()
6969 }
7070
71- // @Test
72- // fun fetchQualifiedSegments_400() {
73- // `when`(urlConnection.responseCode).thenReturn(400)
74- //
75- // segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
76- //
77- // verify(client).execute(captor.capture(), eq(0), eq(0))
78- // val received = captor.value.execute()
79- //
80- // assertNull(received)
81- // verify(logger).error("Unexpected response from ODP segment endpoint, status: 400")
82- // verify(urlConnection).disconnect()
83- // }
84-
85- // @Test
86- // fun fetchQualifiedSegments_500() {
87- // `when`(urlConnection.responseCode).thenReturn(500)
88- //
89- // segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
90- //
91- // verify(client).execute(captor.capture(), eq(0), eq(0))
92- // val received = captor.value.execute()
93- //
94- // assertNull(received)
95- // verify(logger).error("Unexpected response from ODP segment endpoint, status: 500")
96- // verify(urlConnection).disconnect()
97- // }
98-
99- // @Test
100- // fun fetchQualifiedSegments_connectionFailed() {
101- // `when`(urlConnection.responseCode).thenReturn(200)
102- //
103- // apiEndpoint = "invalid-url"
104- // segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
105- //
106- // verify(client).execute(captor.capture(), eq(0), eq(0))
107- // val received = captor.value.execute()
108- //
109- // assertNull(received)
110- // verify(logger).error(contains("Error making ODP segment request"), any())
111- // }
71+ @Test
72+ fun fetchQualifiedSegments_400 () {
73+ `when `(urlConnection.responseCode).thenReturn(400 )
74+
75+ segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
76+
77+ verify(client).execute(captor.capture(), eq(0 ), eq(0 ))
78+ val received = captor.value.execute()
79+
80+ assertNull(received)
81+ verify(logger).error(" Unexpected response from ODP segment endpoint, status: 400" )
82+ verify(urlConnection).disconnect()
83+ }
84+
85+ @Test
86+ fun fetchQualifiedSegments_500 () {
87+ `when `(urlConnection.responseCode).thenReturn(500 )
88+
89+ segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
90+
91+ verify(client).execute(captor.capture(), eq(0 ), eq(0 ))
92+ val received = captor.value.execute()
93+
94+ assertNull(received)
95+ verify(logger).error(" Unexpected response from ODP segment endpoint, status: 500" )
96+ verify(urlConnection).disconnect()
97+ }
98+
99+ @Test
100+ fun fetchQualifiedSegments_connectionFailed () {
101+ `when `(urlConnection.responseCode).thenReturn(200 )
102+
103+ apiEndpoint = " invalid-url"
104+ segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
105+
106+ verify(client).execute(captor.capture(), eq(0 ), eq(0 ))
107+ val received = captor.value.execute()
108+
109+ assertNull(received)
110+ verify(logger).error(contains(" Error making ODP segment request" ), any())
111+ }
112112}
0 commit comments