1616package com .amazonaws .mobileconnectors .s3 .transferutility ;
1717
1818import android .content .Context ;
19+ import android .net .ConnectivityManager ;
1920import android .util .Log ;
21+
2022import androidx .test .platform .app .InstrumentationRegistry ;
2123
2224import com .amazonaws .services .s3 .AmazonS3Client ;
@@ -82,6 +84,7 @@ public void setup() {
8284 /**
8385 * Test that {@link TransferUtility#upload(String, InputStream)} calls the File based
8486 * upload method with all of the expected defaults.
87+ *
8588 * @throws IOException if upload fails to read input file
8689 */
8790 @ Test
@@ -101,6 +104,7 @@ public void testUpload() throws IOException {
101104 /**
102105 * Test that {@link TransferUtility#upload(String, InputStream, UploadOptions)} with
103106 * a default Builder calls the File based upload method with all of the expected defaults.
107+ *
104108 * @throws IOException if upload fails to read input file
105109 */
106110 @ Test
@@ -121,6 +125,7 @@ public void testUploadWithDefaults() throws IOException {
121125 * Test that {@link TransferUtility#upload(String, InputStream, UploadOptions)} with
122126 * all parameters specified calls the File based upload method with the same parameters
123127 * provided as input.
128+ *
124129 * @throws IOException if upload fails to read input file
125130 */
126131 @ Test
@@ -146,6 +151,7 @@ public void testUploadWithAllParametersSet() throws IOException {
146151
147152 /**
148153 * Verify that the File does in fact get deleted after the upload is complete.
154+ *
149155 * @throws IOException if upload fails to read input file
150156 */
151157 @ Test
@@ -169,6 +175,7 @@ public void testDeleteTempFileAfterUpload() throws IOException {
169175
170176 /**
171177 * Cleans up input stream
178+ *
172179 * @throws IOException if input stream fails to close
173180 */
174181 @ After
@@ -197,4 +204,31 @@ public void onError(int id, Exception exception) {
197204 Log .e (TAG , "Error during upload: " + id , exception );
198205 }
199206 }
207+
208+ @ Test
209+ public void testTransferRecordCheckPreferredNetworkAvailability () {
210+ Context context = InstrumentationRegistry .getInstrumentation ().getContext ();
211+ TransferStatusUpdater transferStatusUpdater = TransferStatusUpdater .getInstance (context );
212+ ConnectivityManager connManager = (ConnectivityManager ) context .getSystemService (Context .CONNECTIVITY_SERVICE );
213+ transferStatusUpdater .updateState (2342 , TransferState .IN_PROGRESS );
214+ transferStatusUpdater .addTransfer (new TransferRecord (34234 ));
215+ for (TransferRecord record : transferStatusUpdater .getTransfers ().values ()) {
216+ //When connectionManager is null - Base case
217+ assertTrue (record .checkPreferredNetworkAvailability (transferStatusUpdater , null ));
218+
219+ //When TransferUtilityOptions is null
220+ record .transferUtilityOptions = null ;
221+ assertTrue (record .checkPreferredNetworkAvailability (transferStatusUpdater , connManager ));
222+
223+ //When TransferNetworkConnectionType is null
224+ record .transferUtilityOptions = new TransferUtilityOptions ();
225+ record .transferUtilityOptions .transferNetworkConnectionType = null ;
226+ assertTrue (record .checkPreferredNetworkAvailability (transferStatusUpdater , connManager ));
227+
228+ //When TransferNetworkConnectionType is not null
229+ record .transferUtilityOptions .transferNetworkConnectionType = TransferNetworkConnectionType .ANY ;
230+ assertTrue (record .checkPreferredNetworkAvailability (transferStatusUpdater , connManager ));
231+ }
232+
233+ }
200234}
0 commit comments