Эх сурвалжийг харах

Merge pull request #6573 from nextcloud/uploadStorageTest

Remove all uploads after test for sure
Tobias Kaminsky 4 жил өмнө
parent
commit
eedb5008bb

+ 1 - 3
src/androidTest/java/com/owncloud/android/datamodel/UploadStorageManagerTest.java

@@ -183,9 +183,7 @@ public class UploadStorageManagerTest extends AbstractIT {
     }
 
     private void deleteAllUploads() {
-        for (Account account : getAllAccounts()) {
-            uploadsStorageManager.removeAccountUploads(account);
-        }
+        uploadsStorageManager.removeAllUploads();
 
         assertEquals(0, uploadsStorageManager.getAllStoredUploads().length);
     }

+ 21 - 11
src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -46,6 +46,7 @@ import java.util.Locale;
 import java.util.Observable;
 
 import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
 
 /**
  * Database helper for storing list of files to be uploaded, including status
@@ -581,17 +582,17 @@ public class UploadsStorageManager extends Observable {
         ContentValues cv = new ContentValues();
         cv.put(ProviderTableMeta.UPLOADS_STATUS, UploadStatus.UPLOAD_FAILED.getValue());
         cv.put(
-                ProviderTableMeta.UPLOADS_LAST_RESULT,
-                fail != null ? fail.getValue() : UploadResult.UNKNOWN.getValue()
-        );
+            ProviderTableMeta.UPLOADS_LAST_RESULT,
+            fail != null ? fail.getValue() : UploadResult.UNKNOWN.getValue()
+              );
         cv.put(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP, Calendar.getInstance().getTimeInMillis());
 
         int result = getDB().update(
-                ProviderTableMeta.CONTENT_URI_UPLOADS,
-                cv,
-                ProviderTableMeta.UPLOADS_STATUS + "=?",
-                new String[]{String.valueOf(UploadStatus.UPLOAD_IN_PROGRESS.getValue())}
-        );
+            ProviderTableMeta.CONTENT_URI_UPLOADS,
+            cv,
+            ProviderTableMeta.UPLOADS_STATUS + "=?",
+            new String[]{String.valueOf(UploadStatus.UPLOAD_IN_PROGRESS.getValue())}
+                                   );
 
         if (result == 0) {
             Log_OC.v(TAG, "No upload was killed");
@@ -603,12 +604,21 @@ public class UploadsStorageManager extends Observable {
         return result;
     }
 
+    @VisibleForTesting
+    public int removeAllUploads() {
+        Log_OC.v(TAG, "Delete all uploads!");
+        return getDB().delete(
+            ProviderTableMeta.CONTENT_URI_UPLOADS,
+            "",
+            new String[]{});
+    }
+
     public int removeAccountUploads(Account account) {
         Log_OC.v(TAG, "Delete all uploads for account " + account.name);
         return getDB().delete(
-                ProviderTableMeta.CONTENT_URI_UPLOADS,
-                ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
-                new String[]{account.name});
+            ProviderTableMeta.CONTENT_URI_UPLOADS,
+            ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
+            new String[]{account.name});
     }
 
     public enum UploadStatus {