Search in sources :

Example 1 with AppDependencyModule

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

the class FormMapActivityTest method setUpActivity.

@Before
public void setUpActivity() {
    CollectHelpers.setupDemoProject();
    AppDependencyComponent component = CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public MapProvider providesMapProvider() {
            MapProvider mapProvider = mock(MapProvider.class);
            when(mapProvider.createMapFragment(ArgumentMatchers.any())).thenReturn(map);
            return mapProvider;
        }
    });
    FormsRepository formsRepository = component.formsRepositoryProvider().get();
    instancesRepository = component.instancesRepositoryProvider().get();
    form = formsRepository.save(testForm);
    Arrays.stream(testInstances).forEach(instancesRepository::save);
    Intent intent = new Intent();
    intent.putExtra(FormMapActivity.EXTRA_FORM_ID, form.getDbId());
    activityController = CollectHelpers.buildThemedActivity(FormMapActivity.class, intent);
    activity = (FormMapActivity) activityController.get();
    activityController.setup();
}
Also used : MapProvider(org.odk.collect.android.geo.MapProvider) FormsRepository(org.odk.collect.forms.FormsRepository) AppDependencyComponent(org.odk.collect.android.injection.config.AppDependencyComponent) Intent(android.content.Intent) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Before(org.junit.Before)

Example 2 with AppDependencyModule

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

the class QRCodeActivityResultDelegateTest method setup.

@Before
public void setup() {
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public QRCodeDecoder providesQRCodeDecoder() {
            return fakeQRDecoder;
        }
    });
    context = Robolectric.buildActivity(Activity.class).get();
}
Also used : AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Before(org.junit.Before)

Example 3 with AppDependencyModule

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

the class AnnotateWidgetTest method whenPromptHasDefaultAnswer_showsInImageView.

@Test
public void whenPromptHasDefaultAnswer_showsInImageView() throws Exception {
    String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath();
    ReferenceManager referenceManager = setupFakeReferenceManager(singletonList(new Pair<>(DrawWidgetTest.DEFAULT_IMAGE_ANSWER, imagePath)));
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public ImageLoader providesImageLoader() {
            return new SynchronousImageLoader();
        }
    });
    formEntryPrompt = new MockFormEntryPromptBuilder().withAnswerDisplayText(DrawWidgetTest.DEFAULT_IMAGE_ANSWER).build();
    AnnotateWidget widget = createWidget();
    ImageView imageView = widget.getImageView();
    assertThat(imageView, notNullValue());
    Drawable drawable = imageView.getDrawable();
    assertThat(drawable, notNullValue());
    String loadedPath = shadowOf(((BitmapDrawable) drawable).getBitmap()).getCreatedFromPath();
    assertThat(loadedPath, equalTo(imagePath));
}
Also used : SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RandomString(net.bytebuddy.utility.RandomString) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) ImageView(android.widget.ImageView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageLoader(org.odk.collect.imageloader.ImageLoader) SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager) CollectHelpers.overrideReferenceManager(org.odk.collect.android.support.CollectHelpers.overrideReferenceManager) Pair(androidx.core.util.Pair) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Example 4 with AppDependencyModule

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

the class SelectOneWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }

        @Override
        public SoftKeyboardController provideSoftKeyboardController() {
            return mock(SoftKeyboardController.class);
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) SoftKeyboardController(org.odk.collect.android.utilities.SoftKeyboardController) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager)

Example 5 with AppDependencyModule

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

the class SelectMultiWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }

        @Override
        public SoftKeyboardController provideSoftKeyboardController() {
            return mock(SoftKeyboardController.class);
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) SoftKeyboardController(org.odk.collect.android.utilities.SoftKeyboardController) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager)

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