diff --git a/app/build.gradle b/app/build.gradle index e4859fc2..44c2211b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/dev/java/de/nicidienase/chaosflix/StageInit.kt b/app/src/dev/java/de/nicidienase/chaosflix/StageInit.kt index d19f9351..130006c4 100644 --- a/app/src/dev/java/de/nicidienase/chaosflix/StageInit.kt +++ b/app/src/dev/java/de/nicidienase/chaosflix/StageInit.kt @@ -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" } diff --git a/app/src/main/java/de/nicidienase/chaosflix/ChaosflixStageConfiguration.kt b/app/src/main/java/de/nicidienase/chaosflix/ChaosflixStageConfiguration.kt index ca30413e..6e348bda 100644 --- a/app/src/main/java/de/nicidienase/chaosflix/ChaosflixStageConfiguration.kt +++ b/app/src/main/java/de/nicidienase/chaosflix/ChaosflixStageConfiguration.kt @@ -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() } diff --git a/app/src/mock/java/de/nicidienase/chaosflix/StageInit.kt b/app/src/mock/java/de/nicidienase/chaosflix/StageInit.kt index 9b15a81d..130006c4 100644 --- a/app/src/mock/java/de/nicidienase/chaosflix/StageInit.kt +++ b/app/src/mock/java/de/nicidienase/chaosflix/StageInit.kt @@ -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" } diff --git a/app/src/prod/java/de/nicidienase/chaosflix/StageInit.kt b/app/src/prod/java/de/nicidienase/chaosflix/StageInit.kt index 0a1605f4..31c735e5 100644 --- a/app/src/prod/java/de/nicidienase/chaosflix/StageInit.kt +++ b/app/src/prod/java/de/nicidienase/chaosflix/StageInit.kt @@ -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" } diff --git a/common/src/main/java/de/nicidienase/chaosflix/common/mediadata/network/ApiFactory.kt b/common/src/main/java/de/nicidienase/chaosflix/common/mediadata/network/ApiFactory.kt index a63644a5..86ef939a 100644 --- a/common/src/main/java/de/nicidienase/chaosflix/common/mediadata/network/ApiFactory.kt +++ b/common/src/main/java/de/nicidienase/chaosflix/common/mediadata/network/ApiFactory.kt @@ -68,7 +68,7 @@ class ApiFactory(stageConfiguration: StageConfiguration) { return@Interceptor chain.proceed(requestWithUseragent) } - companion object : SingletonHolder(::ApiFactory) { + companion object : SingletonHolder(::ApiFactory) { private const val DEFAULT_TIMEOUT = 30L private const val CACHE_SIZE = 1024L * 5 // 5MB diff --git a/common/src/test/java/de/nicidienase/chaosflix/common/ChaosflixUtilTest.kt b/common/src/test/java/de/nicidienase/chaosflix/common/ChaosflixUtilTest.kt index aafa30a6..38d64273 100644 --- a/common/src/test/java/de/nicidienase/chaosflix/common/ChaosflixUtilTest.kt +++ b/common/src/test/java/de/nicidienase/chaosflix/common/ChaosflixUtilTest.kt @@ -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) diff --git a/common/src/test/java/de/nicidienase/chaosflix/common/TestStageConfig.kt b/common/src/test/java/de/nicidienase/chaosflix/common/TestStageConfig.kt new file mode 100644 index 00000000..561f1ce6 --- /dev/null +++ b/common/src/test/java/de/nicidienase/chaosflix/common/TestStageConfig.kt @@ -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 +} diff --git a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/EventInfoServiceTest.kt b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/EventInfoServiceTest.kt index c89125fc..ae6e9833 100644 --- a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/EventInfoServiceTest.kt +++ b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/EventInfoServiceTest.kt @@ -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 diff --git a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/MediaRepositoryTest.kt b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/MediaRepositoryTest.kt index 04395798..4506cfc9 100644 --- a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/MediaRepositoryTest.kt +++ b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/MediaRepositoryTest.kt @@ -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 diff --git a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/StreamingRepositoryTest.kt b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/StreamingRepositoryTest.kt index 5c9d5385..52ec5f4c 100644 --- a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/StreamingRepositoryTest.kt +++ b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/StreamingRepositoryTest.kt @@ -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> + @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()) } } } diff --git a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/network/RecordingServiceTest.kt b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/network/RecordingServiceTest.kt index 84ab02a5..37a24127 100644 --- a/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/network/RecordingServiceTest.kt +++ b/common/src/test/java/de/nicidienase/chaosflix/common/mediadata/network/RecordingServiceTest.kt @@ -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 diff --git a/touch/src/test/java/de/nicidienase/chaosflix/touch/ParcelableTest.kt b/touch/src/test/java/de/nicidienase/chaosflix/touch/ParcelableTest.kt index 41546b44..da8263c0 100644 --- a/touch/src/test/java/de/nicidienase/chaosflix/touch/ParcelableTest.kt +++ b/touch/src/test/java/de/nicidienase/chaosflix/touch/ParcelableTest.kt @@ -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)))) }