UploadStorageManagerTest.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.owncloud.android.datamodel;
  2. import android.accounts.Account;
  3. import android.content.ContentResolver;
  4. import android.content.Context;
  5. import android.support.test.InstrumentationRegistry;
  6. import android.support.test.filters.SmallTest;
  7. import android.support.test.runner.AndroidJUnit4;
  8. import com.owncloud.android.db.OCUpload;
  9. import org.junit.After;
  10. import org.junit.Assert;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13. import org.junit.runner.RunWith;
  14. import java.io.File;
  15. /**
  16. * Created by JARP on 6/7/17.
  17. */
  18. @RunWith(AndroidJUnit4.class)
  19. @SmallTest
  20. public class UploadStorageManagerTest {
  21. private Account[] Accounts;
  22. private UploadsStorageManager uploadsStorageManager;
  23. @Before
  24. public void setUp() {
  25. Context instrumentationCtx = InstrumentationRegistry.getTargetContext();
  26. ContentResolver contentResolver = instrumentationCtx.getContentResolver();
  27. uploadsStorageManager = new UploadsStorageManager(contentResolver, instrumentationCtx);
  28. Accounts = new Account[]{new Account("A", "A"), new Account("B", "B")};
  29. }
  30. @Test
  31. public void testDeleteAllUploads() {
  32. //Clean
  33. for (Account account : Accounts) {
  34. uploadsStorageManager.removeAccountUploads(account);
  35. }
  36. int accountRowsA = 3;
  37. int accountRowsB = 4;
  38. insertUploads(Accounts[0], accountRowsA);
  39. insertUploads(Accounts[1], accountRowsB);
  40. Assert.assertTrue("Expected 4 removed uploads files", uploadsStorageManager.removeAccountUploads(Accounts[1]) == 4);
  41. }
  42. private void insertUploads(Account account, int rowsToInsert) {
  43. for (int i = 0; i < rowsToInsert; i++) {
  44. uploadsStorageManager.storeUpload(createUpload(account));
  45. }
  46. }
  47. private OCUpload createUpload(Account acc) {
  48. return new OCUpload(File.separator + "LocalPath",
  49. OCFile.PATH_SEPARATOR + "RemotePath",
  50. acc.name);
  51. }
  52. @After
  53. public void tearDown() {
  54. for (Account account : Accounts) {
  55. uploadsStorageManager.removeAccountUploads(account);
  56. }
  57. }
  58. }