Skip to content
Snippets Groups Projects
Unverified Commit 7579950a authored by apopovsap's avatar apopovsap Committed by GitHub
Browse files

Tests/general (#396)


* add SettingsNavigationHelperTest.kt and TimeAndDateExtensionsTest.kt unitTests

* afterMerge

* after Merge with current dev. Functions from SettingsNavigationHelper moved to ExternalActionHelper

Co-authored-by: default avatarJakob Möller <jakob.moeller@sap.com>
parent 829816a6
No related branches found
No related tags found
No related merge requests found
package de.rki.coronawarnapp.util package de.rki.coronawarnapp.util
import android.content.Context
import android.content.pm.ApplicationInfo
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import de.rki.coronawarnapp.CoronaWarnApplication
import io.mockk.MockKAnnotations
import io.mockk.Runs import io.mockk.Runs
import io.mockk.every import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.just import io.mockk.just
import io.mockk.mockk import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.unmockkAll
import io.mockk.verify import io.mockk.verify
import org.junit.After
import org.junit.Before
import org.junit.Test import org.junit.Test
/**
* ExternalActionHelper test.
*/
class ExternalActionHelperTest { class ExternalActionHelperTest {
/** @MockK
* Test activity called. private lateinit var context: Context
*/
@MockK
private lateinit var applicationInfo: ApplicationInfo
@Before
fun setUp() {
MockKAnnotations.init(this)
mockkObject(CoronaWarnApplication)
}
@Test
fun toConnectionsTest() {
every { context.startActivity(any()) } just Runs
ExternalActionHelper.toConnections(context = context)
verify(exactly = 1) { context.startActivity(any()) }
}
@Test
fun toNotificationsTest() {
every { context.startActivity(any()) } just Runs
every { context.packageName } returns "package_name"
every { context.applicationInfo } returns applicationInfo
ExternalActionHelper.toNotifications(context = context)
verify(exactly = 1) { context.startActivity(any()) }
}
@Test
fun toMainSettingsTest() {
every { context.startActivity(any()) } just Runs
ExternalActionHelper.toConnections(context = context)
verify(exactly = 1) { context.startActivity(any()) }
}
@Test @Test
fun testCall() { fun openUrlTest() {
val fragment = mockk<Fragment>() val fragment = mockk<Fragment>()
every { fragment.startActivity(any()) } just Runs every { fragment.startActivity(any()) } just Runs
ExternalActionHelper.call(fragment, "+77777777777") ExternalActionHelper.openUrl(fragment = fragment, url = "url_path")
verify(exactly = 1) { fragment.startActivity(any()) } verify(exactly = 1) { fragment.startActivity(any()) }
} }
}
@Test
fun callTest() {
val fragment = mockk<Fragment>()
every { fragment.startActivity(any()) } just Runs
ExternalActionHelper.call(fragment = fragment, uri = "call_path")
verify(exactly = 1) { fragment.startActivity(any()) }
}
@Test
fun shareTextTest() {
val fragment = mockk<Fragment>()
every { fragment.startActivity(any()) } just Runs
ExternalActionHelper.shareText(fragment = fragment, text = "text", title = "title")
verify(exactly = 1) { fragment.startActivity(any()) }
}
@After
fun cleanUp() {
unmockkAll()
}
}
\ No newline at end of file
package de.rki.coronawarnapp.util
import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.util.TimeAndDateExtensions.calculateDays
import de.rki.coronawarnapp.util.TimeAndDateExtensions.getCurrentHourUTC
import io.mockk.MockKAnnotations
import io.mockk.mockkObject
import io.mockk.unmockkAll
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.Instant
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.util.concurrent.TimeUnit
/**
* TimeAndDateExtensions test.
*/
class TimeAndDateExtensionsTest {
@Before
fun setUp() {
MockKAnnotations.init(this)
mockkObject(CoronaWarnApplication)
}
@Test
fun getCurrentHourUTCTest() {
val result = getCurrentHourUTC()
MatcherAssert.assertThat(result, CoreMatchers.`is`(DateTime(Instant.now(), DateTimeZone.UTC).hourOfDay().get()))
}
@Test
fun calculateDaysTest() {
val lFirstDate = DateTime(2019, 1, 1, 1, 1).millis
val lSecondDate = DateTime(2020, 1, 1, 1, 1).millis
val result = calculateDays(firstDate = lFirstDate, secondDate = lSecondDate)
MatcherAssert.assertThat(result, CoreMatchers.`is`(TimeUnit.MILLISECONDS.toDays(lSecondDate - lFirstDate)))
}
@After
fun cleanUp() {
unmockkAll()
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment