Add test to ensure legacy storage access
This commit is contained in:
parent
236c65d8ed
commit
d9b8f69f59
2 changed files with 53 additions and 0 deletions
|
@ -17,6 +17,8 @@ android {
|
||||||
setProperty("archivesBaseName","BRouterApp." + defaultConfig.versionName)
|
setProperty("archivesBaseName","BRouterApp." + defaultConfig.versionName)
|
||||||
|
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets.main.assets.srcDirs += new File(project.buildDir, 'assets')
|
sourceSets.main.assets.srcDirs += new File(project.buildDir, 'assets')
|
||||||
|
@ -99,6 +101,10 @@ dependencies {
|
||||||
implementation project(':brouter-expressions')
|
implementation project(':brouter-expressions')
|
||||||
implementation project(':brouter-util')
|
implementation project(':brouter-util')
|
||||||
|
|
||||||
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
|
||||||
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
task generateProfiles(type: Exec) {
|
task generateProfiles(type: Exec) {
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package btools.routingapp;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Environment;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class BRouterActivityTest {
|
||||||
|
@Rule
|
||||||
|
public ActivityScenarioRule<BRouterActivity> rule = new ActivityScenarioRule<>(BRouterActivity.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void storageDirectories() {
|
||||||
|
ActivityScenario<BRouterActivity> scenario = rule.getScenario();
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
List<File> storageDirectories = activity.getStorageDirectories();
|
||||||
|
|
||||||
|
// Before Android Q (10) legacy storage access is possible
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
|
assertThat(storageDirectories, hasItem(Environment.getExternalStorageDirectory()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// When targeting older SDK we can access legacy storage on any android version
|
||||||
|
if (activity.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.Q) {
|
||||||
|
assertThat(storageDirectories, hasItem(Environment.getExternalStorageDirectory()));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(storageDirectories, not(empty()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue