private static void launchFormEntryForSavedForm(ShadowActivity homeActivityShadow, Intent savedFormsIntent, FormRecordListActivity savedFormsActivity) { ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); ShadowActivity formRecordShadow = Shadows.shadowOf(savedFormsActivity); homeActivityShadow.receiveResult(savedFormsIntent, formRecordShadow.getResultCode(), formRecordShadow.getResultIntent()); ShadowActivity.IntentForResult formEntryIntent = homeActivityShadow.getNextStartedActivityForResult(); Robolectric.buildActivity(FormEntryActivity.class) .withIntent(formEntryIntent.intent) .create().start().resume().get(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertNotNull(FormEntryActivity.mFormController); }
@Test public void isStorePictureAvailable_whenPermissionDeclaredAndMediaMounted_shouldReturnTrue() throws Exception { Robolectric.getShadowApplication().grantPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); assertThat(subject.isStorePictureSupported(context)).isTrue(); }
@Test public void isStorePictureAvailable_whenPermissionDenied_shouldReturnFalse() throws Exception { Robolectric.getShadowApplication().denyPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); assertThat(subject.isStorePictureSupported(context)).isFalse(); }
@Test public void isStorePictureAvailable_whenMediaUnmounted_shouldReturnFalse() throws Exception { Robolectric.getShadowApplication().grantPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_UNMOUNTED); assertThat(subject.isStorePictureSupported(context)).isFalse(); }
@Before public void setUp() throws Exception { ShadowLog.stream = System.out; mockWebServer = new MockWebServer(); downloadManager = new DownloadManager.Builder().context( ShadowApplication.getInstance().getApplicationContext()).build(); String filePath = ShadowEnvironment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + "download.apk"; request = new DownloadRequest.Builder().url(mockWebServer.url("/").toString()) .destinationFilePath(filePath) .build(); }
@Before public void setup() { TestAppInstaller.installAppAndLogin( "jr://resource/commcare-apps/form_save_regressions/profile.ccpr", "test", "123"); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); }
@Before public void setup() { TestAppInstaller.installAppAndLogin( "jr://resource/commcare-apps/form_entry_tests/profile.ccpr", "test", "123"); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); }
@Before public void setup() { XFormAndroidInstaller.registerAndroidLevelFormParsers(); TestAppInstaller.installAppAndLogin( "jr://resource/commcare-apps/phone_call/profile.ccpr", "test", "123"); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); }
@Before public void setup() { TestAppInstaller.installAppAndLogin( "jr://resource/commcare-apps/calendar_tests/profile.ccpr", "test", "123"); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); }
@Before public void setup() { TestAppInstaller.installAppAndLogin( "jr://resource/commcare-apps/form_nav_tests/profile.ccpr", "test", "123"); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); }
private void loadTestGpxTrace() throws IOException { byte[] encoded = Files.readAllBytes(Paths.get("src/test/resources/lost.gpx")); String contents = new String(encoded, "UTF-8"); ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); File directory = Environment.getExternalStorageDirectory(); File file = new File(directory, "lost.gpx"); FileWriter fileWriter = new FileWriter(file, false); fileWriter.write(contents); fileWriter.close(); }
@Test public void testGetExternalCacheDir() { ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); verifyFile(fileStore.getExternalCacheDir()); }
@Test public void testGetExternalCacheDir_withoutExternalStorage() { ShadowEnvironment.setExternalStorageState(Environment.MEDIA_REMOVED); assertNull(fileStore.getExternalCacheDir()); }
@Test public void testGetExternalFilesDir() { ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED); verifyFile(fileStore.getExternalFilesDir()); }
@Test public void testGetExternalFilesDir_withoutExternalStorage() { ShadowEnvironment.setExternalStorageState(Environment.MEDIA_REMOVED); assertNull(fileStore.getExternalFilesDir()); }
@After public void tearDown() throws Exception { this.context = null; ShadowEnvironment.reset(); }