From 9f489678f2d337bbb6c8c5df1e57d070eb25585c Mon Sep 17 00:00:00 2001
From: apopovsap <66370584+apopovsap@users.noreply.github.com>
Date: Mon, 22 Jun 2020 11:28:41 +0300
Subject: [PATCH] add CameraPermissionHelperTest.kt (#432)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Jakob Möller <jakob.moeller@sap.com>
---
 .../util/CameraPermissionHelperTest.kt        | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CameraPermissionHelperTest.kt

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 000000000..954ab825e
--- /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
-- 
GitLab