Search in sources :

Example 6 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class FormSaveViewModelTest method setup.

@Before
public void setup() {
    // Useful given some methods will execute AsyncTasks
    Robolectric.getBackgroundThreadScheduler().pause();
    formController = mock(FormController.class);
    logger = mock(AuditEventLogger.class);
    mediaUtils = mock(MediaUtils.class);
    Analytics analytics = mock(Analytics.class);
    when(formController.getAuditEventLogger()).thenReturn(logger);
    when(logger.isChangeReasonRequired()).thenReturn(false);
    audioRecorder = mock(AudioRecorder.class);
    currentProjectProvider = mock(CurrentProjectProvider.class);
    when(currentProjectProvider.getCurrentProject()).thenReturn(Project.Companion.getDEMO_PROJECT());
    viewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, analytics, scheduler, audioRecorder, currentProjectProvider);
    viewModel.formLoaded(formController);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) CurrentProjectProvider(org.odk.collect.android.projects.CurrentProjectProvider) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Analytics(org.odk.collect.analytics.Analytics) Before(org.junit.Before)

Example 7 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class BackgroundAudioPermissionDialogFragmentTest method setup.

@Before
public void setup() {
    backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
    fakePermissionsProvider = new FakePermissionsProvider();
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public BackgroundAudioViewModel.Factory providesBackgroundAudioViewModelFactory(AudioRecorder audioRecorder, SettingsProvider settingsProvider, PermissionsChecker permissionsChecker, Analytics analytics) {
            return new BackgroundAudioViewModel.Factory(audioRecorder, settingsProvider.getUnprotectedSettings(), permissionsChecker, System::currentTimeMillis) {

                @NonNull
                @Override
                public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
                    return (T) backgroundAudioViewModel;
                }
            };
        }

        @Override
        public PermissionsProvider providesPermissionsProvider(PermissionsChecker permissionsChecker) {
            return fakePermissionsProvider;
        }
    });
}
Also used : AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Analytics(org.odk.collect.analytics.Analytics) PermissionsProvider(org.odk.collect.permissions.PermissionsProvider) FakePermissionsProvider(org.odk.collect.android.fakes.FakePermissionsProvider) SettingsProvider(org.odk.collect.settings.SettingsProvider) NonNull(androidx.annotation.NonNull) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) PermissionsChecker(org.odk.collect.permissions.PermissionsChecker) FakePermissionsProvider(org.odk.collect.android.fakes.FakePermissionsProvider) Before(org.junit.Before)

Example 8 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class AudioRecordingControllerFragmentTest method setup.

@Before
public void setup() throws IOException {
    File stubRecording = File.createTempFile("test", ".m4a");
    stubRecording.deleteOnExit();
    audioRecorder = new StubAudioRecorder(stubRecording.getAbsolutePath());
    backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
    formEntryViewModel = mock(FormEntryViewModel.class);
    hasBackgroundRecording = new MutableNonNullLiveData<>(false);
    when(formEntryViewModel.hasBackgroundRecording()).thenReturn(hasBackgroundRecording);
    isBackgroundRecordingEnabled = new MutableNonNullLiveData<>(false);
    when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(isBackgroundRecordingEnabled);
    externalWebPageHelper = mock(ExternalWebPageHelper.class);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public BackgroundAudioViewModel.Factory providesBackgroundAudioViewModelFactory(AudioRecorder audioRecorder, SettingsProvider settingsProvider, PermissionsChecker permissionsChecker, Analytics analytics) {
            return new BackgroundAudioViewModel.Factory(audioRecorder, settingsProvider.getUnprotectedSettings(), permissionsChecker, System::currentTimeMillis) {

                @NonNull
                @Override
                public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
                    return (T) backgroundAudioViewModel;
                }
            };
        }

        @Override
        public FormEntryViewModel.Factory providesFormEntryViewModelFactory(Analytics analytics) {
            return new FormEntryViewModel.Factory(System::currentTimeMillis) {

                @NonNull
                @Override
                public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
                    return (T) formEntryViewModel;
                }
            };
        }

        @Override
        public AudioRecorder providesAudioRecorder(Application application) {
            return audioRecorder;
        }

        @Override
        public ExternalWebPageHelper providesExternalWebPageHelper() {
            return externalWebPageHelper;
        }
    });
}
Also used : StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) FormEntryViewModel(org.odk.collect.android.formentry.FormEntryViewModel) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Analytics(org.odk.collect.analytics.Analytics) SettingsProvider(org.odk.collect.settings.SettingsProvider) NonNull(androidx.annotation.NonNull) StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) PermissionsChecker(org.odk.collect.permissions.PermissionsChecker) BackgroundAudioViewModel(org.odk.collect.android.formentry.BackgroundAudioViewModel) File(java.io.File) Application(android.app.Application) ExternalWebPageHelper(org.odk.collect.android.utilities.ExternalWebPageHelper) Before(org.junit.Before)

Example 9 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class ServerFormDownloaderTest method whenDownloadingCentralDraftWithVersion_andId_butNotHashOnDevice_doesNotLogAnalytics.

@Test
public void whenDownloadingCentralDraftWithVersion_andId_butNotHashOnDevice_doesNotLogAnalytics() throws Exception {
    String xform = FormUtils.createXFormBody("form", "version", "A title");
    Form form = buildForm("form", "version", getFormFilesPath(), xform).build();
    formsRepository.save(form);
    String xform2 = FormUtils.createXFormBody("form2", "version", "A different title");
    Form form2 = buildForm("form", "version", getFormFilesPath(), xform2).build();
    ServerFormDetails serverFormDetails = new ServerFormDetails(form2.getDisplayName(), "http://downloadUrl/draft.xml", form2.getFormId(), form2.getVersion(), Md5.getMd5Hash(new ByteArrayInputStream(xform2.getBytes())), true, false, null);
    FormSource formSource = mock(FormSource.class);
    when(formSource.fetchForm("http://downloadUrl/draft.xml")).thenReturn(new ByteArrayInputStream(xform2.getBytes()));
    Analytics mockAnalytics = mock(Analytics.class);
    ServerFormDownloader downloader = new ServerFormDownloader(formSource, formsRepository, cacheDir, formsDir.getAbsolutePath(), new FormMetadataParser(), mockAnalytics);
    downloader.downloadForm(serverFormDetails, null, null);
    verifyNoInteractions(mockAnalytics);
}
Also used : Form(org.odk.collect.forms.Form) FormUtils.buildForm(org.odk.collect.formstest.FormUtils.buildForm) ByteArrayInputStream(java.io.ByteArrayInputStream) FormSource(org.odk.collect.forms.FormSource) Analytics(org.odk.collect.analytics.Analytics) Test(org.junit.Test)

Aggregations

Analytics (org.odk.collect.analytics.Analytics)9 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)5 Application (android.app.Application)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ReferenceManager (org.javarosa.core.reference.ReferenceManager)3 Before (org.junit.Before)3 Test (org.junit.Test)3 AudioHelperFactory (org.odk.collect.android.formentry.media.AudioHelperFactory)3 CollectHelpers.setupFakeReferenceManager (org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager)3 Scheduler (org.odk.collect.async.Scheduler)3 AudioRecorder (org.odk.collect.audiorecorder.recording.AudioRecorder)3 Form (org.odk.collect.forms.Form)3 FormSource (org.odk.collect.forms.FormSource)3 FormUtils.buildForm (org.odk.collect.formstest.FormUtils.buildForm)3 NonNull (androidx.annotation.NonNull)2 SoftKeyboardController (org.odk.collect.android.utilities.SoftKeyboardController)2 PermissionsChecker (org.odk.collect.permissions.PermissionsChecker)2 SettingsProvider (org.odk.collect.settings.SettingsProvider)2 Pair (androidx.core.util.Pair)1 File (java.io.File)1