Search in sources :

Example 11 with AppDependencyModule

use of org.odk.collect.android.injection.config.AppDependencyModule in project collect by opendatakit.

the class ArbitraryFileWidgetTest method setup.

@Before
public void setup() {
    mediaUtils = mock(MediaUtils.class);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public MediaUtils providesMediaUtils(IntentLauncher intentLauncher) {
            return mediaUtils;
        }
    });
    when(mediaUtils.isAudioFile(any())).thenReturn(true);
}
Also used : IntentLauncher(org.odk.collect.androidshared.system.IntentLauncher) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Before(org.junit.Before)

Example 12 with AppDependencyModule

use of org.odk.collect.android.injection.config.AppDependencyModule 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 13 with AppDependencyModule

use of org.odk.collect.android.injection.config.AppDependencyModule 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 14 with AppDependencyModule

use of org.odk.collect.android.injection.config.AppDependencyModule in project collect by opendatakit.

the class AudioRecordingFormErrorDialogFragmentTest method setup.

@Before
public void setup() throws Exception {
    File stubRecording = File.createTempFile("test", ".m4a");
    stubRecording.deleteOnExit();
    audioRecorder = new StubAudioRecorder(stubRecording.getAbsolutePath());
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public AudioRecorder providesAudioRecorder(Application application) {
            return audioRecorder;
        }
    });
}
Also used : StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) File(java.io.File) Application(android.app.Application) Before(org.junit.Before)

Example 15 with AppDependencyModule

use of org.odk.collect.android.injection.config.AppDependencyModule in project collect by opendatakit.

the class ExVideoWidgetTest method setup.

@Before
public void setup() {
    mediaUtils = mock(MediaUtils.class);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public MediaUtils providesMediaUtils(IntentLauncher intentLauncher) {
            return mediaUtils;
        }
    });
    when(mediaUtils.isVideoFile(any())).thenReturn(true);
}
Also used : IntentLauncher(org.odk.collect.androidshared.system.IntentLauncher) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Before(org.junit.Before)

Aggregations

AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)23 Before (org.junit.Before)10 Test (org.junit.Test)9 FileWidgetTest (org.odk.collect.android.widgets.base.FileWidgetTest)9 ImageView (android.widget.ImageView)8 RandomString (net.bytebuddy.utility.RandomString)8 ReferenceManager (org.javarosa.core.reference.ReferenceManager)8 CollectHelpers.setupFakeReferenceManager (org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager)8 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)8 SynchronousImageLoader (org.odk.collect.android.widgets.support.SynchronousImageLoader)8 ImageLoader (org.odk.collect.imageloader.ImageLoader)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)7 Drawable (android.graphics.drawable.Drawable)7 Pair (androidx.core.util.Pair)6 File (java.io.File)6 MediaUtils (org.odk.collect.android.utilities.MediaUtils)6 IntentLauncher (org.odk.collect.androidshared.system.IntentLauncher)6 Application (android.app.Application)5 Analytics (org.odk.collect.analytics.Analytics)5 AudioHelperFactory (org.odk.collect.android.formentry.media.AudioHelperFactory)3