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

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

Fix tests for services package

- Remote first parameter of @Config(...) for AbstractServiceIT
- Remove unused import for AbstractServiceIT, InitializerServiceTest
- ObserverServiceTest
- remove ObserverServiceTest.registerScannerJobInJobScheduler(): real method have been deleted
- fix ObserverServiceTest.createRemoteFolder(): replace folder creation remote operation
- remove call of 'registerScannerJobInJobScheduler()' from ObserverServiceTest.shouldWork()
and lastSyncWasLessThan15minAgo_shouldStop() and lastSync15minAnd30secAgo_shouldStart()
, noAccount_shouldStop() and InitializationNotDone_shouldStop()
parent 54a6f129
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ import org.robolectric.android.controller.ServiceController;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;

import foundation.e.drive.BuildConfig;
import foundation.e.drive.TestUtils;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.utils.AppConstants;
@@ -27,7 +26,7 @@ import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY
import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.O, manifest = Config.NONE)
@Config(sdk = Build.VERSION_CODES.O, manifest = Config.NONE)
public abstract class AbstractServiceIT<T extends Service> {

    /**
+0 −2
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@ import foundation.e.drive.TestUtils;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.utils.AppConstants;

import static org.robolectric.Shadows.shadowOf;


public class InitializerServiceTest extends AbstractServiceIT<InitializerService>{

+5 −25
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import android.net.NetworkInfo;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;

import junit.framework.Assert;

@@ -25,10 +26,8 @@ import java.util.List;
import foundation.e.drive.TestUtils;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.operations.CreateInitialFolderRemoteOperation;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.JobUtils;

import static foundation.e.drive.TestUtils.TEST_LOCAL_ROOT_FOLDER_PATH;
import static foundation.e.drive.TestUtils.TEST_REMOTE_ROOT_FOLDER_PATH;
@@ -54,19 +53,6 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        dbHelper = new DbHelper(context);
    }

    /**
     * Schedule a ScannerJob instance in JobScheduler
     */
    private void registerScannerJobInJobScheduler(){
        Assert.assertTrue("jobScheduler expected to be have no pending job",jobScheduler.getAllPendingJobs().isEmpty());

        JobUtils.scheduleScannerJob(context);
        int scheduledJobListSize = jobScheduler.getAllPendingJobs().size();
        Assert.assertEquals("PendingJob size expected to be 1 but was:"+scheduledJobListSize,1, scheduledJobListSize );

    }


    /**
     * Set the network status to an available wifi
     */
@@ -116,7 +102,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
     * @param folder the local folder metadata to create
     */
    private void createRemoteFolder(SyncedFolder folder){
        OwnCloudClient client = CommonUtils.getOwnCloudClient(getValidAccount(), context);
        final OwnCloudClient client = CommonUtils.getOwnCloudClient(getValidAccount(), context);

        try {
            TestUtils.testConnection(client, context);
@@ -124,8 +110,8 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
            System.out.println("Test connection failed :"+e.getMessage());
        }

        CreateInitialFolderRemoteOperation op = new CreateInitialFolderRemoteOperation(folder, true, context);
        RemoteOperationResult result = op.execute(client); //Give SSL issue
        final CreateFolderRemoteOperation op = new CreateFolderRemoteOperation(folder.getRemoteFolder(), true);
        final RemoteOperationResult result = op.execute(client); //Give SSL issue

        Assert.assertTrue("Creation of remote test folder failed",result.isSuccess());

@@ -147,7 +133,6 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        prepareValidAccount();
        enableMediaAndSettingsSync(getValidAccount());
        createRemoteFolder(createSingleTestSyncedFolder());
        registerScannerJobInJobScheduler();
        registerSharedPref();

        //Start the service
@@ -177,10 +162,9 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        prepareValidAccount();
        enableMediaAndSettingsSync(getValidAccount());
        //createRemoteSyncedFolder(createSingleTestSyncedFolder());
        registerScannerJobInJobScheduler();
        registerSharedPref();

        boolean haveNetworkConnexion = CommonUtils.haveNetworkConnexion(RuntimeEnvironment.application);
        boolean haveNetworkConnexion = CommonUtils.haveNetworkConnection(RuntimeEnvironment.application, true);
        String msg = "CommonUtils.haveNetworkConnexion should return false but return "+haveNetworkConnexion;
        Assert.assertFalse(msg, haveNetworkConnexion);

@@ -203,7 +187,6 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        prepareValidAccount();
        enableMediaAndSettingsSync(getValidAccount());
        //createRemoteSyncedFolder(createSingleTestSyncedFolder());
        registerScannerJobInJobScheduler();
        registerSharedPref();

        //Start the service
@@ -230,7 +213,6 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        prepareValidAccount();
        enableMediaAndSettingsSync(getValidAccount());
        //createRemoteSyncedFolder(createSingleTestSyncedFolder());
        registerScannerJobInJobScheduler();
        registerSharedPref();

        //Start the service
@@ -258,7 +240,6 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
     */
    @Test
    public void noAccount_shouldStop(){
        registerScannerJobInJobScheduler(); //Assert that the ScheduledJob is present

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

@@ -281,7 +262,6 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        prepareValidAccount();
        enableMediaAndSettingsSync(getValidAccount());
        //createRemoteSyncedFolder(createSingleTestSyncedFolder());
        registerScannerJobInJobScheduler();
        registerSharedPref();