Search in sources :

Example 1 with SettingsProvider

use of org.odk.collect.settings.SettingsProvider 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 2 with SettingsProvider

use of org.odk.collect.settings.SettingsProvider 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)

Aggregations

NonNull (androidx.annotation.NonNull)2 Before (org.junit.Before)2 Analytics (org.odk.collect.analytics.Analytics)2 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)2 AudioRecorder (org.odk.collect.audiorecorder.recording.AudioRecorder)2 PermissionsChecker (org.odk.collect.permissions.PermissionsChecker)2 SettingsProvider (org.odk.collect.settings.SettingsProvider)2 Application (android.app.Application)1 File (java.io.File)1 FakePermissionsProvider (org.odk.collect.android.fakes.FakePermissionsProvider)1 BackgroundAudioViewModel (org.odk.collect.android.formentry.BackgroundAudioViewModel)1 FormEntryViewModel (org.odk.collect.android.formentry.FormEntryViewModel)1 ExternalWebPageHelper (org.odk.collect.android.utilities.ExternalWebPageHelper)1 StubAudioRecorder (org.odk.collect.audiorecorder.testsupport.StubAudioRecorder)1 PermissionsProvider (org.odk.collect.permissions.PermissionsProvider)1