Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7cc5176 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Fix test case in InitializerServiceTest

- Remove assertion about JobScheduler because it isn't used anymore
- Remove 'settingsAndMediaSyncDisabled_shouldStop' test case as not relevant anymore
- Add new method 'initializeWorkmanager()' in TestUtils
parent 23930868
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Properties;
import java.util.concurrent.Executors;

import static com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_OC_BASE_URL;
import static org.junit.Assert.assertTrue;
+2 −27
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@ import android.content.Context;
import android.net.ConnectivityManager;


import androidx.work.WorkManager;

import org.junit.Test;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
@@ -31,7 +33,6 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        sharedPreferences = context.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        dbHelper = new DbHelper(context);

        TestUtils.initializeWorkmanager(context);
        init_done = false;
    }
@@ -50,7 +51,6 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        mServiceController.create().startCommand(0,0);
        String lastLog = ShadowLog.getLogs().get(ShadowLog.getLogs().size()-1).msg;
        assertEquals("lastLog expected to be 'Initializer has already been run' but was "+lastLog, "Initializer has already been run", lastLog);
        assertEquals("service should have schedule a job but pending job contains "+jobScheduler.getAllPendingJobs().size(),1,  jobScheduler.getAllPendingJobs().size());
        //Teardown
        jobScheduler.cancelAll();
    }
@@ -91,29 +91,4 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        String lastLog = ShadowLog.getLogs().get(ShadowLog.getLogs().size()-1).msg;
        assertEquals("lastLog expected to be 'Account's name not found. Neither in shared prefs nor in intent's extras' but was "+lastLog, "Account's name not found. Neither in shared prefs nor in intent's extras", lastLog);
    }


    /**
     * Check that InitializerService stops if media & settings sync are disabled
     */
    @Test
    public void settingsAndMediaSyncDisabled_shouldStop(){
        initial_folder_number = -1;
        init_done = false;
        registerSharedPref();
        final int initFolderCount_pretest = sharedPreferences.getInt(AppConstants.INITIALFOLDERS_NUMBER, 0);
        assertEquals("Initial folders count expected to be -1 but got "+initFolderCount_pretest, -1, initFolderCount_pretest);

        prepareValidAccount();
        disableMediaAndSettingsSync(TestUtils.getValidAccount());

        mServiceController.create();
        mServiceController.startCommand(0,0);

        final int initFolderCount = sharedPreferences.getInt(AppConstants.INITIALFOLDERS_NUMBER, -1);
        assertEquals("Initial folders count expected to be 0 but got "+initFolderCount, 0, initFolderCount);

        final boolean initialization_done = sharedPreferences.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false);
        assertTrue("sharedPref initialization_done expected to be true but was false"+initialization_done, initialization_done);
    }
}