Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #299 from corona-warn-app/dev
Browse files Browse the repository at this point in the history
0.8.10
  • Loading branch information
jakobmoellerdev authored Jun 9, 2020
2 parents 9aada86 + 80f030a commit 498de61
Show file tree
Hide file tree
Showing 289 changed files with 29,090 additions and 26,441 deletions.
11 changes: 6 additions & 5 deletions Corona-Warn-App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ android {
applicationId 'de.rki.coronawarnapp'
minSdkVersion 23
targetSdkVersion 29
versionCode 16
versionName "0.8.9"
versionCode 17
versionName "0.8.10"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildConfigField "String", "DOWNLOAD_CDN_URL", "\"$DOWNLOAD_CDN_URL\""
buildConfigField "String", "SUBMISSION_CDN_URL", "\"$SUBMISSION_CDN_URL\""
buildConfigField "String", "VERIFICATION_CDN_URL", "\"$VERIFICATION_CDN_URL\""
buildConfigField "String", "EXPORT_SIGNATURE_ID", "\"de.rki.coronawarnapp-dev\""
buildConfigField "String", "EXPORT_SIGNATURE_ID", "\"de.rki.coronawarnapp\""

//override URLs with local variables
Properties properties = new Properties()
Expand Down Expand Up @@ -181,7 +181,8 @@ dependencies {
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:truth:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

androidTestImplementation "io.mockk:mockk-android:1.10.0"
debugImplementation 'androidx.fragment:fragment-testing:1.2.4'

// Play Services
implementation 'com.google.android.play:core:1.7.3'
Expand All @@ -194,7 +195,7 @@ dependencies {
// HTTP
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation ('com.squareup.retrofit2:converter-protobuf:2.9.0') {
implementation('com.squareup.retrofit2:converter-protobuf:2.9.0') {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
implementation("com.squareup.okhttp3:logging-interceptor:4.7.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.rki.coronawarnapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment

/**
* Test fragment with test view, [TextView] required for view lifecycle owner.
*
* @see [Fragment.getViewLifecycleOwner]
*/
class TestFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return TextView(this.context)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package de.rki.coronawarnapp.nearby

import androidx.fragment.app.Fragment
import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.common.api.Status
import com.google.android.gms.nearby.exposurenotification.TemporaryExposureKey
import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.TestFragment
import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.unmockkAll
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

/**
* InternalExposureNotificationPermissionHelper test.
*/
@RunWith(AndroidJUnit4::class)
class InternalExposureNotificationPermissionHelperTest {
private lateinit var scenario: FragmentScenario<TestFragment>
private var fail = false
private var startSuccess = false
private var sharingSuccess = false
private val callback = object : InternalExposureNotificationPermissionHelper.Callback {
override fun onFailure(exception: Exception?) {
fail = true
}

override fun onStartPermissionGranted() {
startSuccess = true
}

override fun onKeySharePermissionGranted(keys: List<TemporaryExposureKey>) {
sharingSuccess = true
}
}

/**
* Launch test fragment, required for view lifecycle owner.
*
* @see [InternalExposureNotificationPermissionHelper]
* @see [Fragment.getViewLifecycleOwner]
*/
@Before
fun setUp() {
fail = false
startSuccess = false
sharingSuccess = false
mockkObject(InternalExposureNotificationClient)
scenario = launchFragmentInContainer<TestFragment>()
}

/**
* Test tracing permission request assuming EN Client is enabled.
*/
@Test
fun testRequestPermissionToStartTracingENIsEnabled() {
coEvery { InternalExposureNotificationClient.asyncIsEnabled() } returns true
scenario.onFragment {
val helper = InternalExposureNotificationPermissionHelper(it, callback)
helper.requestPermissionToStartTracing()
}
assertThat(fail, `is`(false))
assertThat(startSuccess, `is`(true))
}

/**
* Test tracing permission request assuming EN Client is disabled.
*/
@Test
fun testRequestPermissionToStartTracingENIsNotEnabled() {
coEvery { InternalExposureNotificationClient.asyncIsEnabled() } returns false
// not every device/emulator has access to exposure notifications Google API:
coEvery { InternalExposureNotificationClient.asyncStart() } returns mockk()

scenario.onFragment {
val helper = InternalExposureNotificationPermissionHelper(it, callback)
helper.requestPermissionToStartTracing()
}
assertThat(fail, `is`(false))
assertThat(startSuccess, `is`(true))
}

/**
* Test tracing permission request exception handling.
*/
@Test
fun testRequestPermissionToStartTracingExceptionHandling() {
coEvery { InternalExposureNotificationClient.asyncIsEnabled() } returns false

// not every device/emulator has access to exposure notifications Google API:
coEvery { InternalExposureNotificationClient.asyncStart() } throws mockApiException(Status.RESULT_CANCELED)

scenario.onFragment {
val helper = InternalExposureNotificationPermissionHelper(it, callback)
helper.requestPermissionToStartTracing()
}
assertThat(fail, `is`(true))
assertThat(startSuccess, `is`(false))
}

/**
* Test keys sharing permission request.
*/
@Test
fun testRequestPermissionToShareKeys() {
// not every device/emulator has access to exposure notifications Google API:
coEvery { InternalExposureNotificationClient.asyncGetTemporaryExposureKeyHistory() } returns mockk()

scenario.onFragment {
val helper = InternalExposureNotificationPermissionHelper(it, callback)
helper.requestPermissionToShareKeys()
}
assertThat(fail, `is`(false))
assertThat(sharingSuccess, `is`(true))
}

/**
* Test keys sharing permission request exception handling.
*/
@Test
fun testRequestPermissionToShareKeysException() {
// not every device/emulator has access to exposure notifications Google API:
coEvery {
InternalExposureNotificationClient.asyncGetTemporaryExposureKeyHistory()
} throws mockApiException(Status.RESULT_CANCELED)

scenario.onFragment {
val helper = InternalExposureNotificationPermissionHelper(it, callback)
helper.requestPermissionToShareKeys()
}
assertThat(fail, `is`(true))
assertThat(sharingSuccess, `is`(false))
}

private fun mockApiException(status: Status): ApiException {
mockkObject(LocalBroadcastManager.getInstance(CoronaWarnApplication.getAppContext()))
val exception = ApiException(status)
// don't need a dialog for exception
every {
LocalBroadcastManager.getInstance(CoronaWarnApplication.getAppContext())
.sendBroadcast(any())
} returns true
return exception
}

@After
fun cleanUp() {
unmockkAll()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class ExposureSummaryDaoTest {
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
db = Room.inMemoryDatabaseBuilder(
context, AppDatabase::class.java).build()
context, AppDatabase::class.java
).build()
dao = db.exposureSummaryDao()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class KeyCacheDaoTest {
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
db = Room.inMemoryDatabaseBuilder(
context, AppDatabase::class.java).build()
context, AppDatabase::class.java
).build()
keyCacheDao = db.dateDao()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class TracingIntervalDaoTest {
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
db = Room.inMemoryDatabaseBuilder(
context, AppDatabase::class.java).build()
context, AppDatabase::class.java
).build()
dao = db.tracingIntervalDao()
}

Expand Down
4 changes: 2 additions & 2 deletions Corona-Warn-App/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<application
android:name="de.rki.coronawarnapp.CoronaWarnApplication"
android:allowBackup="false"
android:icon="@drawable/ic_app_launch_icon"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@drawable/ic_app_launch_icon"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

Expand Down
Loading

0 comments on commit 498de61

Please sign in to comment.