fix tests

This commit is contained in:
Felix 2020-06-13 16:53:02 +02:00
parent 7090e9a2f3
commit a829ca4505
13 changed files with 58 additions and 36 deletions

View file

@ -32,9 +32,6 @@ android {
versionName = project.property("versionName") as String
println "Setting versionName from property: $versionName"
}
buildConfigField "String", "STREAMING_API_BASE_URL", "\"https://streaming.media.ccc.de\""
buildConfigField "String", "STREAMING_API_OFFERS_PATH", "\"/streams/v2.json\""
}
signingConfigs {

View file

@ -5,4 +5,7 @@ import android.app.Application
object StageInit : ChaosflixInitializer {
override fun init(application: Application) {}
const val streamingApiBaseUrl = "https://streaming.media.ccc.de"
const val streamingApiPath = "/streams/v2.json"
}

View file

@ -6,13 +6,11 @@ import java.io.File
class ChaosflixStageConfiguration(context: Context) : StageConfiguration {
override val versionName: String = BuildConfig.VERSION_NAME
override val versionCode: Int = BuildConfig.VERSION_CODE
override val recordingUrl = context.resources.getString(R.string.recording_url)
?: throw error("Recording Url not definded")
override val eventInfoUrl = context.resources.getString(R.string.event_info_url)
?: throw error("EventInfo Url not definded")
override val recordingUrl = context.resources.getString(R.string.recording_url) ?: throw error("Recording Url not definded")
override val eventInfoUrl = context.resources.getString(R.string.event_info_url) ?: throw error("EventInfo Url not definded")
override val cacheDir: File? = context.cacheDir
override val streamingApiBaseUrl = BuildConfig.STREAMING_API_BASE_URL
override val streamingApiPath = BuildConfig.STREAMING_API_OFFERS_PATH
override val streamingApiBaseUrl = StageInit.streamingApiBaseUrl
override val streamingApiPath = StageInit.streamingApiPath
override val appcenterId: String? = BuildConfig.APPCENTER_ID
override val externalFilesDir: File? = android.os.Environment.getExternalStorageDirectory()
}

View file

@ -1,7 +1,11 @@
import de.nicidienase.chaosflix.ChaosflixApplication
import de.nicidienase.chaosflix.ChaosflixInitializer
package de.nicidienase.chaosflix
import android.app.Application
object StageInit : ChaosflixInitializer {
override fun init(application: ChaosflixApplication) {}
override fun init(application: Application) {}
const val streamingApiBaseUrl = "https://streaming.media.ccc.de"
const val streamingApiPath = "/streams/v2.json"
}

View file

@ -1,6 +1,10 @@
import de.nicidienase.chaosflix.ChaosflixApplication
import de.nicidienase.chaosflix.ChaosflixInitializer
package de.nicidienase.chaosflix
import android.app.Application
object StageInit : ChaosflixInitializer {
override fun init(chaosflixApplication: ChaosflixApplication) {}
override fun init(application: Application) {}
const val streamingApiBaseUrl = "https://streaming.media.ccc.de"
const val streamingApiPath = "/streams/v2.json"
}

View file

@ -68,7 +68,7 @@ class ApiFactory(stageConfiguration: StageConfiguration) {
return@Interceptor chain.proceed(requestWithUseragent)
}
companion object : SingletonHolder<ApiFactory, de.nicidienase.chaosflix.StageConfiguration>(::ApiFactory) {
companion object : SingletonHolder<ApiFactory, StageConfiguration>(::ApiFactory) {
private const val DEFAULT_TIMEOUT = 30L
private const val CACHE_SIZE = 1024L * 5 // 5MB

View file

@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test
class ChaosflixUtilTest {
val api = ApiFactory.getInstance("https://api.media.ccc.de", "https://c3voc.de", null).recordingApi
val api = ApiFactory.getInstance(TestStageConfig).recordingApi
@Test
fun testGPN19() = genericTest("gpn19", false)

View file

@ -0,0 +1,16 @@
package de.nicidienase.chaosflix.common
import de.nicidienase.chaosflix.StageConfiguration
import java.io.File
object TestStageConfig : StageConfiguration {
override val versionName: String = "0.1"
override val versionCode: Int = 1
override val recordingUrl: String = "https://api.media.ccc.de"
override val eventInfoUrl: String = "https://c3voc.de"
override val cacheDir: File? = null
override val externalFilesDir: File? = null
override val streamingApiBaseUrl: String = "https://streaming.media.ccc.de"
override val streamingApiPath: String = "/streams/v2.json"
override val appcenterId: String? = null
}

View file

@ -1,5 +1,6 @@
package de.nicidienase.chaosflix.common.mediadata
import de.nicidienase.chaosflix.common.TestStageConfig
import de.nicidienase.chaosflix.common.mediadata.entities.eventinfo.EventInfo
import de.nicidienase.chaosflix.common.mediadata.network.ApiFactory
import java.util.Date
@ -11,7 +12,7 @@ import org.junit.jupiter.api.Test
class EventInfoServiceTest {
private val apiFactory = ApiFactory.getInstance("https://api.media.ccc.de", "https://c3voc.de", null)
private val apiFactory = ApiFactory.getInstance(TestStageConfig)
private val api = apiFactory.eventInfoApi
@BeforeEach

View file

@ -1,6 +1,6 @@
package de.nicidienase.chaosflix.common.mediadata
import de.nicidienase.chaosflix.common.AnalyticsWrapperImpl
import de.nicidienase.chaosflix.common.AnalyticsWrapper
import de.nicidienase.chaosflix.common.ChaosflixDatabase
import de.nicidienase.chaosflix.common.InstantExecutorExtension
import de.nicidienase.chaosflix.common.mediadata.entities.recording.ConferenceDto
@ -15,7 +15,6 @@ import io.mockk.every
import io.mockk.impl.annotations.RelaxedMockK
import io.mockk.junit5.MockKExtension
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.slot
import io.mockk.unmockkAll
import io.mockk.verify
@ -39,6 +38,9 @@ internal class MediaRepositoryTest {
@RelaxedMockK
private lateinit var recordingApi: RecordingApi
@RelaxedMockK
private lateinit var analyticsWrapper: AnalyticsWrapper
private var database: ChaosflixDatabase = mockk {
every { conferenceGroupDao() } returns mockk(relaxed = true)
every { conferenceDao() } returns mockk(relaxed = true)
@ -57,8 +59,7 @@ internal class MediaRepositoryTest {
@BeforeEach
fun setup() {
mockkObject(AnalyticsWrapperImpl)
mediaRepository = MediaRepository(recordingApi, database)
mediaRepository = MediaRepository(recordingApi, database, analyticsWrapper)
}
@AfterEach
@ -72,7 +73,7 @@ internal class MediaRepositoryTest {
Response.error(404, ResponseBody.create(mediaTypeJson, emptyJson))
mediaRepository.updateSingleEvent("foo")
coVerify(exactly = 1) { recordingApi.getEventByGUIDSuspending("foo") }
verify(exactly = 0) { AnalyticsWrapperImpl.trackException(any()) }
verify(exactly = 0) { analyticsWrapper.trackException(any()) }
}
@Test
@ -81,7 +82,7 @@ internal class MediaRepositoryTest {
val result = mediaRepository.updateSingleEvent("foo")
assertThat(null, equalTo(result))
coVerify(exactly = 1) { recordingApi.getEventByGUIDSuspending("foo") }
verify(exactly = 1) { AnalyticsWrapperImpl.trackException(any()) }
verify(exactly = 1) { analyticsWrapper.trackException(any()) }
}
@Test

View file

@ -1,7 +1,7 @@
package de.nicidienase.chaosflix.common.mediadata
import androidx.lifecycle.MutableLiveData
import de.nicidienase.chaosflix.common.AnalyticsWrapperImpl
import de.nicidienase.chaosflix.common.AnalyticsWrapper
import de.nicidienase.chaosflix.common.InstantExecutorExtension
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.LiveConference
import de.nicidienase.chaosflix.common.mediadata.network.StreamingApi
@ -20,7 +20,6 @@ import okhttp3.ResponseBody
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import retrofit2.Response
@ -34,14 +33,12 @@ internal class StreamingRepositoryTest {
@RelaxedMockK
private lateinit var _streamingConferences: MutableLiveData<List<LiveConference>>
@RelaxedMockK
private lateinit var analyticsWrapper: AnalyticsWrapper
@InjectMockKs
private lateinit var streamingRepository: StreamingRepository
@BeforeEach
fun setup() {
mockkObject(AnalyticsWrapperImpl)
}
@AfterEach
fun cleanup() {
unmockkAll()
@ -60,15 +57,15 @@ internal class StreamingRepositoryTest {
coEvery { streamingApi.getStreamingConferences() } throws SSLHandshakeException("")
streamingRepository.update()
coVerify(exactly = 0) { _streamingConferences.postValue(any()) }
verify(exactly = 1) { AnalyticsWrapperImpl.trackException(any()) }
verify(exactly = 1) { analyticsWrapper.trackException(any()) }
}
@Test
fun handle404() = runBlocking {
coEvery { streamingApi.getStreamingConferences() } returns Response.error(404, ResponseBody.create(MediaType.get("text/plain"), "not found"))
mockkObject(AnalyticsWrapperImpl)
mockkObject(analyticsWrapper)
streamingRepository.update()
coVerify(exactly = 0) { _streamingConferences.postValue(any()) }
verify(exactly = 0) { AnalyticsWrapperImpl.trackException(any()) }
verify(exactly = 0) { analyticsWrapper.trackException(any()) }
}
}

View file

@ -1,5 +1,6 @@
package de.nicidienase.chaosflix.common.mediadata.network
import de.nicidienase.chaosflix.common.TestStageConfig
import de.nicidienase.chaosflix.common.mediadata.MediaRepository
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.equalTo
@ -10,7 +11,7 @@ import org.junit.jupiter.api.Test
class RecordingServiceTest {
private val apiFactory = ApiFactory.getInstance("https://api.media.ccc.de", "https://c3voc.de", null)
private val apiFactory = ApiFactory.getInstance(TestStageConfig)
private val api = apiFactory.recordingApi
@BeforeEach

View file

@ -12,7 +12,7 @@ import org.robolectric.RobolectricTestRunner
class ParcelableTest {
@Test
fun PlaybackItemParcelableTest() {
fun playbackItemParcelableTest() {
val playbackItem = PlaybackItem("title", "subtitle", "asdlökfjasd", "http://foo.bar/test")
assertTrue(playbackItem.equals(PlaybackItem.createFromParcel(writeToParcel(playbackItem))))
}