Skip to content

Instantly share code, notes, and snippets.

var imagePath: File = File(getContext().getExternalFilesDir(null), "images")
var newFile: File = File(imagePath, "default_image.jpg")
var contentUri: Uri = getUriForFile(getContext(), "com.mydomain.authority", newFile)
class EncryptedFileProvider : FileProvider() {
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private var masterKeyAlias: String = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {
if (uri.path.isNullOrEmpty()) {
return null
@RunWith(AndroidJUnit4::class)
class AdvancedExampleTest {
lateinit var scenario: ActivityScenario<MainActivity>
@Test
fun launchMainActivityWithLongDisplayNameExtra() {
val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java)
.putExtra(
INTENT_EXTRA_DISPLAY_NAME,
val context: Context = getInstrumentation().targetContext
fun getString(id: Int): String? {
return context.resources.getString(id)
}
fun getCurrentActivity(): Activity? {
var currentActivity: Activity? = null
getInstrumentation().runOnMainSync {
run {
dependencies {
androidTestImplementation 'androidx.test:core-ktx:1.2.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
androidTestImplementation "com.google.truth:truth:0.44"
}
private const val USER_NAME = "test@gmail.com"
private const val VALID_PASSWORD = "123456"
private const val INVALID_PASSWORD = "12345" // Password must be >5 characters
@RunWith(AndroidJUnit4::class)
class BasicExampleTest {
/**
* Use [activityScenarioRule] to create and launch the activity under test before each test,
* and close it after each test. This is a replacement for
private const val USER_NAME = "test@gmail.com"
private const val VALID_PASSWORD = "123456"
@RunWith(AndroidJUnit4::class)
class IntentsExampleTest {
/**
* Use [IntentsTestRule] to initialize Espresso-Intents before each test
* and releases Espresso-Intents after each test run.
*/
dependencies {
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test.ext:truth:1.0.0'
androidTestImplementation 'com.google.truth:truth:0.42'
@oaviad
oaviad / copyTo.kt
Created May 6, 2020 07:27
shared pref copy func
fun SharedPreferences.copyTo(dest: SharedPreferences) {
for (entry in all.entries) {
val key = entry.key
val value: Any? = entry.value
dest.set(key, value)
}
}
fun SharedPreferences.copyTo(dest: SharedPreferences) {
for (entry in all.entries) {
val key = entry.key
val value: Any? = entry.value
dest.set(key, value)
}
}
inline fun SharedPreferences.edit(operation: (SharedPreferences.Editor) -> Unit) {
val editor = this.edit()