diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CameraPermissionHelperTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CameraPermissionHelperTest.kt new file mode 100644 index 0000000000000000000000000000000000000000..954ab825e56cd05d8ee6a99d16ec586f29c98302 --- /dev/null +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CameraPermissionHelperTest.kt @@ -0,0 +1,53 @@ +package de.rki.coronawarnapp.util + +import android.content.Context +import de.rki.coronawarnapp.CoronaWarnApplication +import de.rki.coronawarnapp.util.CameraPermissionHelper.hasCameraPermission +import io.mockk.MockKAnnotations +import io.mockk.every +import io.mockk.impl.annotations.MockK +import io.mockk.mockkObject +import io.mockk.unmockkAll +import org.hamcrest.CoreMatchers +import org.hamcrest.MatcherAssert +import org.junit.After +import org.junit.Before +import org.junit.Test + + +class CameraPermissionHelperTest { + + @MockK + private lateinit var context: Context + + @Before + fun setUp() { + MockKAnnotations.init(this) + mockkObject(CoronaWarnApplication) + } + + + /** + * Test call order is correct. + */ + @Test + fun hasCameraPermissionTest() { + every { context.checkPermission(any(), any(), any()) } returns 0 + + val result = hasCameraPermission(context) + MatcherAssert.assertThat(result, CoreMatchers.`is`(true)) + } + + @Test + fun hasNotCameraPermissionTest() { + every { context.checkPermission(any(), any(), any()) } returns 1 + + val result = hasCameraPermission(context) + MatcherAssert.assertThat(result, CoreMatchers.`is`(false)) + } + + @After + fun cleanUp() { + unmockkAll() + } +} \ No newline at end of file