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

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

Replace deprecated assert instruction

parent 7b5d2dc5
Loading
Loading
Loading
Loading
+22 −18
Original line number Diff line number Diff line
package foundation.e.drive.operations;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import android.accounts.AccountManager;
import android.os.Build;

@@ -8,8 +14,6 @@ import com.owncloud.android.lib.common.UserInfo;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -61,7 +65,7 @@ public class UploadFileOperationTest {
    @Before
    public void setUp(){
        prepareDB();        //Create DB
        Assert.assertNotNull("Client is null. unexpected!", client);
        assertNotNull("Client is null. unexpected!", client);
    }

    @After
@@ -80,7 +84,7 @@ public class UploadFileOperationTest {
        DbHelper.insertSyncedFolder(createSyncedFolder("large"), RuntimeEnvironment.application);

        //Insert at least one file for each folder
        Assert.assertEquals("There isn't three folder in DB as expected", 3, DbHelper.getSyncedFolderList(RuntimeEnvironment.application, true).size());
        assertEquals("There isn't three folder in DB as expected", 3, DbHelper.getSyncedFolderList(RuntimeEnvironment.application, true).size());
    }

    /**
@@ -101,7 +105,7 @@ public class UploadFileOperationTest {
        try {
            TestUtils.createFile(smallDummyFilePath, 2);
        } catch (IOException | SecurityException e ) {
            Assert.fail(e.getMessage());
            fail(e.getMessage());
        }

        final SyncedFileState sfs = new SyncedFileState(-1, "dummy.txt", TestUtils.TEST_LOCAL_ROOT_FOLDER_PATH+"small/dummy.txt", TestUtils.TEST_REMOTE_ROOT_FOLDER_PATH+"small/dummy.txt",  "", 0l, 0, true, 3);
@@ -156,7 +160,7 @@ public class UploadFileOperationTest {
        createSmallFile(); //preparation

        final SyncedFileState sfs_fromDB = DbHelper.loadSyncedFile(RuntimeEnvironment.application, syncedFileStates.get(0).getLocalPath(), true);
        Assert.assertTrue("SyncedFileState loaded from DB must have an empty Etag", sfs_fromDB.getLastETAG().isEmpty());
        assertTrue("SyncedFileState loaded from DB must have an empty Etag", sfs_fromDB.getLastETAG().isEmpty());


        boolean checkEtag = false;
@@ -170,10 +174,10 @@ public class UploadFileOperationTest {
        if(result.getException() != null){
            errorMsg += "\n, exception msg: "+result.getException().getMessage();
        }
        Assert.assertTrue( errorMsg, result.isSuccess());
        assertTrue( errorMsg, result.isSuccess());

        final SyncedFileState sfs_fromDBAfterUpload = DbHelper.loadSyncedFile(RuntimeEnvironment.application, syncedFileStates.get(0).getLocalPath(), true);
        Assert.assertFalse("After upload, the database must store the etag of the syncedFileState. But here it is empty", sfs_fromDBAfterUpload.getLastETAG().isEmpty());
        assertFalse("After upload, the database must store the etag of the syncedFileState. But here it is empty", sfs_fromDBAfterUpload.getLastETAG().isEmpty());
    }


@@ -193,7 +197,7 @@ public class UploadFileOperationTest {
        UploadFileOperation testOperation = new UploadFileOperation(syncedFileState, RuntimeEnvironment.application);

        RemoteOperationResult result = testOperation.execute(client);
        Assert.assertEquals("Expected result code was FORBIDDEN but got: "+result.getCode().name(), RemoteOperationResult.ResultCode.FORBIDDEN, result.getCode());
        assertEquals("Expected result code was FORBIDDEN but got: "+result.getCode().name(), RemoteOperationResult.ResultCode.FORBIDDEN, result.getCode());
    }


@@ -207,16 +211,16 @@ public class UploadFileOperationTest {
        createSmallFile(); //preparation

        final SyncedFileState sfs_fromDB = DbHelper.loadSyncedFile(RuntimeEnvironment.application, syncedFileStates.get(0).getLocalPath(), true);
        Assert.assertTrue("SyncedFileState loaded from DB must have an empty Etag", sfs_fromDB.getLastETAG().isEmpty());
        assertTrue("SyncedFileState loaded from DB must have an empty Etag", sfs_fromDB.getLastETAG().isEmpty());

        boolean checkEtag = false;
        UploadFileOperation testOperation = new UploadFileOperation(syncedFileStates.get(0), RuntimeEnvironment.application);

        File smallFile = new File(sfs_fromDB.getLocalPath());
        Assert.assertTrue("Local file deletion return false instead of true", smallFile.delete());
        assertTrue("Local file deletion return false instead of true", smallFile.delete());

        RemoteOperationResult result = testOperation.execute(client);
        Assert.assertEquals("Expected result code was FORBIDDEN but got: "+result.getCode().name(), RemoteOperationResult.ResultCode.FORBIDDEN, result.getCode());
        assertEquals("Expected result code was FORBIDDEN but got: "+result.getCode().name(), RemoteOperationResult.ResultCode.FORBIDDEN, result.getCode());
    }


@@ -226,11 +230,11 @@ public class UploadFileOperationTest {
    @Test
    public void fileSizeBiggerThanFreeQuota_shouldnotBeAllowed(){
        //long freeQuota = getUserRemoteFreeQuota();
        Assert.assertFalse("Reading remote free quota fails"+userFreeQuota, -1 == userFreeQuota);
        assertFalse("Reading remote free quota fails"+userFreeQuota, -1 == userFreeQuota);
        //We don't care of parameter of UploadFileOperation's constructor
        RemoteOperationResult actualResult = new UploadFileOperation(Mockito.mock(SyncedFileState.class), RuntimeEnvironment.application)
                .checkAvailableSpace(client, (userFreeQuota+1));
        Assert.assertEquals("Quota check ("+ userFreeQuota+"vs"+(userFreeQuota+1)+") failed", RemoteOperationResult.ResultCode.QUOTA_EXCEEDED, actualResult.getCode());
        assertEquals("Quota check ("+ userFreeQuota+"vs"+(userFreeQuota+1)+") failed", RemoteOperationResult.ResultCode.QUOTA_EXCEEDED, actualResult.getCode());
    }

    /**
@@ -241,11 +245,11 @@ public class UploadFileOperationTest {
    public void fileSizeEqualToFreeQuota_shouldnotBeAllowed(){
        //I don't know why but it always fail for this test.
        //long freeQuota = getUserRemoteFreeQuota();
        Assert.assertFalse("Reading remote free quota fails"+userFreeQuota, -1 == userFreeQuota);
        assertFalse("Reading remote free quota fails"+userFreeQuota, -1 == userFreeQuota);

        RemoteOperationResult actualResult = new UploadFileOperation(Mockito.mock(SyncedFileState.class), RuntimeEnvironment.application)
                .checkAvailableSpace(client, userFreeQuota);
        Assert.assertEquals("Quota check  ("+ userFreeQuota+" vs "+userFreeQuota+") failed",
        assertEquals("Quota check  ("+ userFreeQuota+" vs "+userFreeQuota+") failed",
                RemoteOperationResult.ResultCode.QUOTA_EXCEEDED,
                actualResult.getCode());
    }
@@ -258,11 +262,11 @@ public class UploadFileOperationTest {
    @Test
    public void fileSizeSmallerThanFreeQuota_shouldBeAllowed(){
        //long freeQuota = getUserRemoteFreeQuota();
        Assert.assertFalse("Reading remote free quota fails "+userFreeQuota, -1 == userFreeQuota);
        assertFalse("Reading remote free quota fails "+userFreeQuota, -1 == userFreeQuota);

        RemoteOperationResult actualResult = new UploadFileOperation(Mockito.mock(SyncedFileState.class), RuntimeEnvironment.application)
                .checkAvailableSpace(client, (userFreeQuota-1));
        Assert.assertEquals("Quota check ("+ userFreeQuota+" vs "+(userFreeQuota-1)+") failed",
        assertEquals("Quota check ("+ userFreeQuota+" vs "+(userFreeQuota-1)+") failed",
                RemoteOperationResult.ResultCode.OK,
                actualResult.getCode());

+12 −12
Original line number Diff line number Diff line
package foundation.e.drive.services;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import android.accounts.AccountManager;
import android.app.job.JobScheduler;
import android.content.Context;
import android.net.ConnectivityManager;

import junit.framework.Assert;

import org.junit.Test;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
@@ -16,7 +17,6 @@ import foundation.e.drive.TestUtils;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.utils.AppConstants;


public class InitializerServiceTest extends AbstractServiceIT<InitializerService>{

    public InitializerServiceTest(){
@@ -43,12 +43,12 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        init_done = true;
        registerSharedPref();

        Assert.assertTrue("SharedPreferences.INITIALIZATION_HAS_BEEN_DONE expected to be true but was false", sharedPreferences.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false));
        assertTrue("SharedPreferences.INITIALIZATION_HAS_BEEN_DONE expected to be true but was false", sharedPreferences.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false));

        mServiceController.create().startCommand(0,0);
        String lastLog = ShadowLog.getLogs().get(ShadowLog.getLogs().size()-1).msg;
        Assert.assertEquals("lastLog expected to be 'Initializer has already been run' but was "+lastLog, "Initializer has already been run", lastLog);
        Assert.assertEquals("service should have schedule a job but pending job contains "+jobScheduler.getAllPendingJobs().size(),1,  jobScheduler.getAllPendingJobs().size());
        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();
    }
@@ -65,12 +65,12 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        /*try {
            testConnection(CommonUtils.getOwnCloudClient(validAccount, context));
        }catch(Exception e){
            Assert.fail(e.getMessage());
            fail(e.getMessage());
        }*/
        mServiceController.create().startCommand(0,0);
        //mService.onRemoteOperationFinish(new CreateInitialFolderRemoteOperation(null, true, context), new RemoteOperationResult(true, new MkColMethod("")));

        //Assert.fail("Not yet implemented");
        //fail("Not yet implemented");
    }

    /**
@@ -86,7 +86,7 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        mServiceController.create().startCommand(0,0);

        String lastLog = ShadowLog.getLogs().get(ShadowLog.getLogs().size()-1).msg;
        Assert.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);
        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);
    }


@@ -99,7 +99,7 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        init_done = false;
        registerSharedPref();
        final int initFolderCount_pretest = sharedPreferences.getInt(AppConstants.INITIALFOLDERS_NUMBER, 0);
        Assert.assertEquals("Initial folders count expected to be -1 but got "+initFolderCount_pretest, -1, initFolderCount_pretest);
        assertEquals("Initial folders count expected to be -1 but got "+initFolderCount_pretest, -1, initFolderCount_pretest);

        prepareValidAccount();
        disableMediaAndSettingsSync(TestUtils.getValidAccount());
@@ -108,9 +108,9 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService
        mServiceController.startCommand(0,0);

        final int initFolderCount = sharedPreferences.getInt(AppConstants.INITIALFOLDERS_NUMBER, -1);
        Assert.assertEquals("Initial folders count expected to be 0 but got "+initFolderCount, 0, initFolderCount);
        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);
        Assert.assertTrue("sharedPref initialization_done expected to be true but was false"+initialization_done, initialization_done);
        assertTrue("sharedPref initialization_done expected to be true but was false"+initialization_done, initialization_done);
    }
}
+22 −20
Original line number Diff line number Diff line
@@ -11,8 +11,6 @@ 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;

import org.junit.Ignore;
import org.junit.Test;
import org.robolectric.Robolectric;
@@ -34,6 +32,10 @@ import static foundation.e.drive.TestUtils.TEST_REMOTE_ROOT_FOLDER_PATH;
import static foundation.e.drive.TestUtils.getValidAccount;
import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE;
import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.robolectric.Shadows.shadowOf;

/**
@@ -59,7 +61,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
    private void setWifiNetworkStatus(){
        NetworkInfo netInfo = ShadowNetworkInfo.newInstance(null,
                ConnectivityManager.TYPE_WIFI, 0, true, NetworkInfo.State.CONNECTED);
        Assert.assertEquals("NetworkInfo type  is invalid",ConnectivityManager.TYPE_WIFI,netInfo.getType());
        assertEquals("NetworkInfo type  is invalid",ConnectivityManager.TYPE_WIFI,netInfo.getType());
        shadowOf(connectivityManager).setActiveNetworkInfo(netInfo);
    }

@@ -69,7 +71,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
    private void setUnavailableWifiNetworkStatus(){
        NetworkInfo netInfo = ShadowNetworkInfo.newInstance(null,
                ConnectivityManager.TYPE_WIFI, 0, true, NetworkInfo.State.DISCONNECTED);
        Assert.assertEquals("NetworkInfo type  is invalid",ConnectivityManager.TYPE_WIFI,netInfo.getType());
        assertEquals("NetworkInfo type  is invalid",ConnectivityManager.TYPE_WIFI,netInfo.getType());

        shadowOf(connectivityManager).setActiveNetworkInfo(netInfo);
    }
@@ -83,7 +85,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        try{
            folder.mkdirs();
        }catch(SecurityException e){
            Assert.fail(e.getMessage());
            fail(e.getMessage());
        }
        final SyncedFolder sFolder = new SyncedFolder(MEDIA_SYNCABLE_CATEGORIES[0], TEST_LOCAL_ROOT_FOLDER_PATH, TEST_REMOTE_ROOT_FOLDER_PATH, true);

@@ -107,10 +109,10 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        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());
        assertTrue("Creation of remote test folder failed",result.isSuccess());

        final int dbFolderListSize =DbHelper.getAllSyncedFolders(context).size();
        Assert.assertEquals("Expected DB's SyncedFolder table content was 1, but got:"+dbFolderListSize, 1, dbFolderListSize);
        assertEquals("Expected DB's SyncedFolder table content was 1, but got:"+dbFolderListSize, 1, dbFolderListSize);


        initial_folder_number =1;
@@ -135,11 +137,11 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
        ShadowLog.LogItem lastLog = logs.get(logs.size()-3);

        Assert.assertEquals("expected: 'Going to scan remote files' but found: '"+lastLog.msg, "Going to scan remote files", lastLog.msg);
        assertEquals("expected: 'Going to scan remote files' but found: '"+lastLog.msg, "Going to scan remote files", lastLog.msg);

        //Tear down
        mService.deleteDatabase(DbHelper.DATABASE_NAME);
        //Assert.assertTrue("Database hasn't been removed", myService.deleteDatabase(DbHelper.DATABASE_NAME));
        //assertTrue("Database hasn't been removed", myService.deleteDatabase(DbHelper.DATABASE_NAME));
    }


@@ -160,13 +162,13 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {

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

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

        List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
        ShadowLog.LogItem lastLog = logs.get(logs.size()-1);
        Assert.assertEquals("Last log isn't the one expected", "There is no Internet connexion.", lastLog.msg);
        assertEquals("Last log isn't the one expected", "There is no Internet connexion.", lastLog.msg);

    }

@@ -192,7 +194,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        ShadowLog.LogItem lastLog = logs.get(logs.size()-1);

        //Note: Checking log is the only way I've found to check that the service stopped as expected
        Assert.assertEquals("Last log isn't the one expected", "Delay between now and last call is too short", lastLog.msg);
        assertEquals("Last log isn't the one expected", "Delay between now and last call is too short", lastLog.msg);

    }

@@ -214,7 +216,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {

        List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
        for(ShadowLog.LogItem log : logs){
            Assert.assertFalse("Log shouldn't contains 'delay between now and last call is too short' but it does", log.msg.equals("Delay between now and last call is too short")); //There isn't assertNotEquals
            assertFalse("Log shouldn't contains 'delay between now and last call is too short' but it does", log.msg.equals("Delay between now and last call is too short")); //There isn't assertNotEquals
        }
    }

@@ -225,7 +227,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
    @Test
    public void syncAlreadyStarted_shouldStop(){
        //@TODO need to find how to access the "isRunning" private field inside the ObserverService for this test
        Assert.fail("Not yet implemented ");
        fail("Not yet implemented ");
    }


@@ -240,8 +242,8 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
        ShadowLog.LogItem lastLog = logs.get(logs.size()-1);

        Assert.assertEquals("Last expected log wasn't: 'No account registered' but "+lastLog.msg, "No account registered",lastLog.msg );
        Assert.assertTrue("jobScheduler expected to be have no pending job",jobScheduler.getAllPendingJobs().isEmpty());
        assertEquals("Last expected log wasn't: 'No account registered' but "+lastLog.msg, "No account registered",lastLog.msg );
        assertTrue("jobScheduler expected to be have no pending job",jobScheduler.getAllPendingJobs().isEmpty());
    }

    /**
@@ -259,7 +261,7 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        registerSharedPref();


       Assert.assertFalse("SharedPref doesn't contains the expected value for Initialization_has_been_done key", sharedPreferences.getBoolean(INITIALIZATION_HAS_BEEN_DONE, true));
       assertFalse("SharedPref doesn't contains the expected value for Initialization_has_been_done key", sharedPreferences.getBoolean(INITIALIZATION_HAS_BEEN_DONE, true));

        mServiceController.create().startCommand(0, 0);
        //How to assert this... ?
@@ -267,14 +269,14 @@ public class ObserverServiceTest extends AbstractServiceIT<ObserverService> {
        Intent expectedIntent = new Intent(mService, InitializerService.class);
        Intent actualIntent = shadowOf(RuntimeEnvironment.application).getNextStartedService();

        Assert.assertEquals("Checked intent not the expected one", expectedIntent.getComponent(), actualIntent.getComponent());
        assertEquals("Checked intent not the expected one", expectedIntent.getComponent(), actualIntent.getComponent());

        List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
        ShadowLog.LogItem lastLog = logs.get(logs.size()-1);

        //Note: Checking log is the only way I've found to check that the service stopped as expected
        Assert.assertEquals("Last log isn't the one expected", "Initialization hasn't been done", lastLog.msg);
        //Assert.assertTrue(logs.contains()); //@TODO how to assert that logs doesn't contain the expecteed message ?
        assertEquals("Last log isn't the one expected", "Initialization hasn't been done", lastLog.msg);
        //assertTrue(logs.contains()); //@TODO how to assert that logs doesn't contain the expecteed message ?

        //tearDown - Remove DB if it had been created
        mService.deleteDatabase(DbHelper.DATABASE_NAME);