1919import static org .junit .Assert .assertThrows ;
2020import static org .mockito .Mockito .when ;
2121
22+ import android .content .Context ;
23+ import androidx .test .core .app .ApplicationProvider ;
2224import com .google .firebase .appdistribution .internal .AppDistributionReleaseInternal ;
2325import java .io .ByteArrayInputStream ;
2426import java .io .IOException ;
@@ -45,6 +47,7 @@ public class FirebaseAppDistributionTesterApiClientTest {
4547 private static final String INVALID_RESPONSE = "InvalidResponse" ;
4648
4749 private FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ;
50+ private Context applicationContext ;
4851 @ Mock private HttpsURLConnection mockHttpsURLConnection ;
4952
5053 @ Before
@@ -59,6 +62,8 @@ public void setup() throws Exception {
5962 Mockito .doReturn (mockHttpsURLConnection )
6063 .when (firebaseAppDistributionTesterApiClient )
6164 .openHttpsUrlConnection (TEST_APP_ID_1 , TEST_FID_1 );
65+
66+ applicationContext = ApplicationProvider .getApplicationContext ();
6267 }
6368
6469 @ Test
@@ -69,7 +74,7 @@ public void fetchNewRelease_whenResponseSuccessfulForApk_returnsRelease() throws
6974 when (mockHttpsURLConnection .getInputStream ()).thenReturn (response );
7075 AppDistributionReleaseInternal release =
7176 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 );
7378 assertEquals (release .getBinaryType (), BinaryType .APK );
7479 assertEquals (release .getBuildVersion (), "3" );
7580 assertEquals (release .getDisplayVersion (), "3.0" );
@@ -86,7 +91,7 @@ public void fetchNewRelease_whenResponseSuccessfulForAab_returnsRelease() throws
8691 when (mockHttpsURLConnection .getInputStream ()).thenReturn (response );
8792 AppDistributionReleaseInternal release =
8893 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 );
9095 assertEquals (release .getBinaryType (), BinaryType .AAB );
9196 assertEquals (release .getBuildVersion (), "3" );
9297 assertEquals (release .getDisplayVersion (), "3.0" );
@@ -105,7 +110,7 @@ public void fetchNewRelease_whenResponseFailsWith401_throwsError() throws Except
105110 FirebaseAppDistributionException .class ,
106111 () ->
107112 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 ));
109114
110115 assertEquals (FirebaseAppDistributionException .Status .AUTHENTICATION_FAILURE , ex .getErrorCode ());
111116 assertEquals ("Failed to authenticate the tester" , ex .getMessage ());
@@ -121,7 +126,7 @@ public void fetchNewRelease_whenResponseFailsWith403_throwsError() throws Except
121126 FirebaseAppDistributionException .class ,
122127 () ->
123128 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 ));
125130
126131 assertEquals (FirebaseAppDistributionException .Status .AUTHENTICATION_FAILURE , ex .getErrorCode ());
127132 assertEquals ("Failed to authorize the tester" , ex .getMessage ());
@@ -137,7 +142,7 @@ public void fetchNewRelease_whenResponseFailsWith404_throwsError() throws Except
137142 FirebaseAppDistributionException .class ,
138143 () ->
139144 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 ));
141146
142147 assertEquals (FirebaseAppDistributionException .Status .AUTHENTICATION_FAILURE , ex .getErrorCode ());
143148 assertEquals ("Tester or release not found" , ex .getMessage ());
@@ -153,7 +158,7 @@ public void fetchNewRelease_whenResponseFailsWith504_throwsError() throws Except
153158 FirebaseAppDistributionException .class ,
154159 () ->
155160 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 ));
157162
158163 assertEquals (FirebaseAppDistributionException .Status .NETWORK_FAILURE , ex .getErrorCode ());
159164 assertEquals ("Failed to fetch releases due to timeout" , ex .getMessage ());
@@ -169,7 +174,7 @@ public void fetchNewRelease_whenResponseFailsWithUnknownCode_throwsError() throw
169174 FirebaseAppDistributionException .class ,
170175 () ->
171176 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 ));
173178
174179 assertEquals (FirebaseAppDistributionException .Status .NETWORK_FAILURE , ex .getErrorCode ());
175180 assertEquals ("Failed to fetch releases due to unknown network error" , ex .getMessage ());
@@ -185,7 +190,7 @@ public void fetchNewRelease_whenInvalidJson_throwsError() throws Exception {
185190 FirebaseAppDistributionException .class ,
186191 () ->
187192 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 ));
189194
190195 assertEquals (FirebaseAppDistributionException .Status .UNKNOWN , ex .getErrorCode ());
191196 assertEquals ("Error parsing service response" , ex .getMessage ());
0 commit comments