19
19
import static org .junit .Assert .assertThrows ;
20
20
import static org .mockito .Mockito .when ;
21
21
22
+ import android .content .Context ;
23
+ import androidx .test .core .app .ApplicationProvider ;
22
24
import com .google .firebase .appdistribution .internal .AppDistributionReleaseInternal ;
23
25
import java .io .ByteArrayInputStream ;
24
26
import java .io .IOException ;
@@ -45,6 +47,7 @@ public class FirebaseAppDistributionTesterApiClientTest {
45
47
private static final String INVALID_RESPONSE = "InvalidResponse" ;
46
48
47
49
private FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ;
50
+ private Context applicationContext ;
48
51
@ Mock private HttpsURLConnection mockHttpsURLConnection ;
49
52
50
53
@ Before
@@ -59,6 +62,8 @@ public void setup() throws Exception {
59
62
Mockito .doReturn (mockHttpsURLConnection )
60
63
.when (firebaseAppDistributionTesterApiClient )
61
64
.openHttpsUrlConnection (TEST_APP_ID_1 , TEST_FID_1 );
65
+
66
+ applicationContext = ApplicationProvider .getApplicationContext ();
62
67
}
63
68
64
69
@ Test
@@ -69,7 +74,7 @@ public void fetchNewRelease_whenResponseSuccessfulForApk_returnsRelease() throws
69
74
when (mockHttpsURLConnection .getInputStream ()).thenReturn (response );
70
75
AppDistributionReleaseInternal release =
71
76
firebaseAppDistributionTesterApiClient .fetchNewRelease (
72
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN );
77
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext );
73
78
assertEquals (release .getBinaryType (), BinaryType .APK );
74
79
assertEquals (release .getBuildVersion (), "3" );
75
80
assertEquals (release .getDisplayVersion (), "3.0" );
@@ -86,7 +91,7 @@ public void fetchNewRelease_whenResponseSuccessfulForAab_returnsRelease() throws
86
91
when (mockHttpsURLConnection .getInputStream ()).thenReturn (response );
87
92
AppDistributionReleaseInternal release =
88
93
firebaseAppDistributionTesterApiClient .fetchNewRelease (
89
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN );
94
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext );
90
95
assertEquals (release .getBinaryType (), BinaryType .AAB );
91
96
assertEquals (release .getBuildVersion (), "3" );
92
97
assertEquals (release .getDisplayVersion (), "3.0" );
@@ -105,7 +110,7 @@ public void fetchNewRelease_whenResponseFailsWith401_throwsError() throws Except
105
110
FirebaseAppDistributionException .class ,
106
111
() ->
107
112
firebaseAppDistributionTesterApiClient .fetchNewRelease (
108
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN ));
113
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext ));
109
114
110
115
assertEquals (FirebaseAppDistributionException .Status .AUTHENTICATION_FAILURE , ex .getErrorCode ());
111
116
assertEquals ("Failed to authenticate the tester" , ex .getMessage ());
@@ -121,7 +126,7 @@ public void fetchNewRelease_whenResponseFailsWith403_throwsError() throws Except
121
126
FirebaseAppDistributionException .class ,
122
127
() ->
123
128
firebaseAppDistributionTesterApiClient .fetchNewRelease (
124
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN ));
129
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext ));
125
130
126
131
assertEquals (FirebaseAppDistributionException .Status .AUTHENTICATION_FAILURE , ex .getErrorCode ());
127
132
assertEquals ("Failed to authorize the tester" , ex .getMessage ());
@@ -137,7 +142,7 @@ public void fetchNewRelease_whenResponseFailsWith404_throwsError() throws Except
137
142
FirebaseAppDistributionException .class ,
138
143
() ->
139
144
firebaseAppDistributionTesterApiClient .fetchNewRelease (
140
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN ));
145
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext ));
141
146
142
147
assertEquals (FirebaseAppDistributionException .Status .AUTHENTICATION_FAILURE , ex .getErrorCode ());
143
148
assertEquals ("Tester or release not found" , ex .getMessage ());
@@ -153,7 +158,7 @@ public void fetchNewRelease_whenResponseFailsWith504_throwsError() throws Except
153
158
FirebaseAppDistributionException .class ,
154
159
() ->
155
160
firebaseAppDistributionTesterApiClient .fetchNewRelease (
156
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN ));
161
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext ));
157
162
158
163
assertEquals (FirebaseAppDistributionException .Status .NETWORK_FAILURE , ex .getErrorCode ());
159
164
assertEquals ("Failed to fetch releases due to timeout" , ex .getMessage ());
@@ -169,7 +174,7 @@ public void fetchNewRelease_whenResponseFailsWithUnknownCode_throwsError() throw
169
174
FirebaseAppDistributionException .class ,
170
175
() ->
171
176
firebaseAppDistributionTesterApiClient .fetchNewRelease (
172
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN ));
177
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext ));
173
178
174
179
assertEquals (FirebaseAppDistributionException .Status .NETWORK_FAILURE , ex .getErrorCode ());
175
180
assertEquals ("Failed to fetch releases due to unknown network error" , ex .getMessage ());
@@ -185,7 +190,7 @@ public void fetchNewRelease_whenInvalidJson_throwsError() throws Exception {
185
190
FirebaseAppDistributionException .class ,
186
191
() ->
187
192
firebaseAppDistributionTesterApiClient .fetchNewRelease (
188
- TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN ));
193
+ TEST_FID_1 , TEST_APP_ID_1 , TEST_API_KEY , TEST_AUTH_TOKEN , applicationContext ));
189
194
190
195
assertEquals (FirebaseAppDistributionException .Status .UNKNOWN , ex .getErrorCode ());
191
196
assertEquals ("Error parsing service response" , ex .getMessage ());
0 commit comments