15
15
package com.optimizely.ab.android.odp
16
16
17
17
import androidx.test.ext.junit.runners.AndroidJUnit4
18
- import com.optimizely.ab.android.shared.ClientForODPOnly
18
+ import com.optimizely.ab.android.shared.Client
19
19
import java.io.OutputStream
20
20
import java.net.HttpURLConnection
21
21
import org.junit.Assert.assertNull
@@ -34,9 +34,9 @@ import org.slf4j.Logger
34
34
@RunWith(AndroidJUnit4 ::class )
35
35
class ODPSegmentClientTest {
36
36
private val logger = mock(Logger ::class .java)
37
- private val client = mock(ClientForODPOnly ::class .java)
37
+ private val client = mock(Client ::class .java)
38
38
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)
40
40
private lateinit var segmentClient: ODPSegmentClient
41
41
42
42
private val apiKey = " valid-key"
@@ -68,45 +68,45 @@ class ODPSegmentClientTest {
68
68
verify(urlConnection).disconnect()
69
69
}
70
70
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
+ }
112
112
}
0 commit comments