@Test @Config(minSdk = LOLLIPOP) public void setBackupEnabled_setToFalse_shouldDisableBackup() { backupManager.setBackupEnabled(false); assertThat(backupManager.isBackupEnabled()).isFalse(); }
@Test @Config(minSdk = LOLLIPOP) public void setBackupEnabled_setToTrue_shouldEnableBackup() { backupManager.setBackupEnabled(true); assertThat(backupManager.isBackupEnabled()).isTrue(); }
@Test @Config(minSdk = LOLLIPOP) public void setBackupEnabled_multipleInstances_shouldBeEnabled() { // BackupManager is used by creating new instances, but all of them talk to the same // BackupManagerService in Android, so methods that route through the service will share states. backupManager.setBackupEnabled(true); assertThat(new BackupManager(ApplicationProvider.getApplicationContext()).isBackupEnabled()) .isTrue(); }
@Test @Config(minSdk = LOLLIPOP) public void isBackupEnabled_noPermission_shouldThrowSecurityException() { shadowOf((Application) ApplicationProvider.getApplicationContext()) .denyPermissions(android.Manifest.permission.BACKUP); try { backupManager.isBackupEnabled(); fail("SecurityException should be thrown"); } catch (SecurityException e) { // pass } }