@@ -53,8 +53,6 @@ public class TesterApiHttpClientTest {
53
53
private static final String TEST_PATH = "some/url/path" ;
54
54
private static final String TEST_URL =
55
55
String .format ("https://firebaseapptesters.googleapis.com/%s" , TEST_PATH );
56
- private static final String TEST_UPLOAD_URL =
57
- String .format ("https://firebaseapptesters.clients6.google.com/%s" , TEST_PATH );
58
56
private static final String TAG = "Test Tag" ;
59
57
private static final String TEST_POST_BODY = "Post body" ;
60
58
@@ -76,12 +74,13 @@ public void setup() throws Exception {
76
74
.setApiKey (TEST_API_KEY )
77
75
.build ());
78
76
77
+ when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
78
+
79
79
testerApiHttpClient = new TesterApiHttpClient (firebaseApp , mockHttpsURLConnectionFactory );
80
80
}
81
81
82
82
@ Test
83
83
public void makeGetRequest_whenResponseSuccessful_returnsJsonResponse () throws Exception {
84
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
85
84
String responseJson = readTestFile ("testSimpleResponse.json" );
86
85
InputStream responseInputStream =
87
86
new ByteArrayInputStream (responseJson .getBytes (UTF_8 ));
@@ -97,7 +96,6 @@ public void makeGetRequest_whenResponseSuccessful_returnsJsonResponse() throws E
97
96
98
97
@ Test
99
98
public void makeGetRequest_whenConnectionFails_throwsError () throws Exception {
100
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
101
99
IOException caughtException = new IOException ("error" );
102
100
when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenThrow (caughtException );
103
101
@@ -113,7 +111,6 @@ public void makeGetRequest_whenConnectionFails_throwsError() throws Exception {
113
111
114
112
@ Test
115
113
public void makeGetRequest_whenInvalidJson_throwsError () throws Exception {
116
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
117
114
InputStream response =
118
115
new ByteArrayInputStream (INVALID_RESPONSE .getBytes (UTF_8 ));
119
116
when (mockHttpsURLConnection .getInputStream ()).thenReturn (response );
@@ -132,7 +129,6 @@ public void makeGetRequest_whenInvalidJson_throwsError() throws Exception {
132
129
133
130
@ Test
134
131
public void makeGetRequest_whenResponseFailsWith401_throwsError () throws Exception {
135
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
136
132
when (mockHttpsURLConnection .getResponseCode ()).thenReturn (401 );
137
133
when (mockHttpsURLConnection .getInputStream ()).thenThrow (new IOException ("error" ));
138
134
@@ -149,7 +145,6 @@ public void makeGetRequest_whenResponseFailsWith401_throwsError() throws Excepti
149
145
150
146
@ Test
151
147
public void makeGetRequest_whenResponseFailsWith403_throwsError () throws Exception {
152
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
153
148
when (mockHttpsURLConnection .getResponseCode ()).thenReturn (403 );
154
149
when (mockHttpsURLConnection .getInputStream ()).thenThrow (new IOException ("error" ));
155
150
@@ -166,7 +161,6 @@ public void makeGetRequest_whenResponseFailsWith403_throwsError() throws Excepti
166
161
167
162
@ Test
168
163
public void makeGetRequest_whenResponseFailsWith404_throwsError () throws Exception {
169
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
170
164
when (mockHttpsURLConnection .getResponseCode ()).thenReturn (404 );
171
165
when (mockHttpsURLConnection .getInputStream ()).thenThrow (new IOException ("error" ));
172
166
@@ -183,7 +177,6 @@ public void makeGetRequest_whenResponseFailsWith404_throwsError() throws Excepti
183
177
184
178
@ Test
185
179
public void makeGetRequest_whenResponseFailsWithUnknownCode_throwsError () throws Exception {
186
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
187
180
when (mockHttpsURLConnection .getResponseCode ()).thenReturn (409 );
188
181
when (mockHttpsURLConnection .getInputStream ()).thenThrow (new IOException ("error" ));
189
182
@@ -200,7 +193,6 @@ public void makeGetRequest_whenResponseFailsWithUnknownCode_throwsError() throws
200
193
201
194
@ Test
202
195
public void makePostRequest_zipsRequestBodyAndSetsCorrectHeaders () throws Exception {
203
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
204
196
String responseJson = readTestFile ("testSimpleResponse.json" );
205
197
InputStream responseInputStream =
206
198
new ByteArrayInputStream (responseJson .getBytes (UTF_8 ));
@@ -224,7 +216,6 @@ public void makePostRequest_zipsRequestBodyAndSetsCorrectHeaders() throws Except
224
216
225
217
@ Test
226
218
public void makePostRequest_whenConnectionFails_throwsError () throws Exception {
227
- when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenReturn (mockHttpsURLConnection );
228
219
IOException caughtException = new IOException ("error" );
229
220
when (mockHttpsURLConnectionFactory .openConnection (TEST_URL )).thenThrow (caughtException );
230
221
@@ -240,7 +231,6 @@ public void makePostRequest_whenConnectionFails_throwsError() throws Exception {
240
231
241
232
@ Test
242
233
public void makeUploadRequest_zipsRequestBodyAndSetsCorrectHeaders () throws Exception {
243
- when (mockHttpsURLConnectionFactory .openConnection (TEST_UPLOAD_URL )).thenReturn (mockHttpsURLConnection );
244
234
String responseJson = readTestFile ("testSimpleResponse.json" );
245
235
InputStream responseInputStream =
246
236
new ByteArrayInputStream (responseJson .getBytes (UTF_8 ));
0 commit comments