From 8ec369f3e7bba11b6f34320aa7c625cd4434e99c Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Tue, 12 Jul 2022 11:58:02 +0300 Subject: [PATCH] PR#98 Fix code analysis errors --- app/src/test/java/org/fnives/test/showcase/di/DITest.kt | 2 +- .../fnives/test/showcase/ui/auth/AuthViewModelTest.kt | 9 ++------- .../test/showcase/ui/auth/CodeKataAuthViewModel.kt | 2 +- .../fnives/test/showcase/ui/home/MainViewModelTest.kt | 2 +- .../test/showcase/ui/splash/SplashViewModelTest.kt | 2 +- gradlescripts/testdependencies.gradle | 2 +- gradlescripts/versions.gradle | 6 +++--- .../android/testutil/InstantExecutorExtension.kt | 3 ++- .../test/showcase/android/testutil/TestMainDispatcher.kt | 4 ++-- 9 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/test/java/org/fnives/test/showcase/di/DITest.kt b/app/src/test/java/org/fnives/test/showcase/di/DITest.kt index bc950e5..087272f 100644 --- a/app/src/test/java/org/fnives/test/showcase/di/DITest.kt +++ b/app/src/test/java/org/fnives/test/showcase/di/DITest.kt @@ -1,8 +1,8 @@ package org.fnives.test.showcase.di import android.content.Context -import org.fnives.test.showcase.model.network.BaseUrl import org.fnives.test.showcase.android.testutil.StandardTestMainDispatcher +import org.fnives.test.showcase.model.network.BaseUrl import org.fnives.test.showcase.ui.auth.AuthViewModel import org.fnives.test.showcase.ui.home.MainViewModel import org.fnives.test.showcase.ui.splash.SplashViewModel diff --git a/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt b/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt index 0a1ee75..d1008bf 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt @@ -4,11 +4,11 @@ import com.jraska.livedata.test import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import org.fnives.test.showcase.android.testutil.InstantExecutorExtension +import org.fnives.test.showcase.android.testutil.StandardTestMainDispatcher import org.fnives.test.showcase.core.login.LoginUseCase import org.fnives.test.showcase.model.auth.LoginCredentials import org.fnives.test.showcase.model.auth.LoginStatus import org.fnives.test.showcase.model.shared.Answer -import org.fnives.test.showcase.android.testutil.StandardTestMainDispatcher import org.fnives.test.showcase.ui.shared.Event import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName @@ -44,11 +44,6 @@ internal class AuthViewModelTest { @DisplayName("GIVEN initialized viewModel WHEN observed THEN loading false other fields are empty") @Test fun initialSetup() { - var a = "" - repeat(1200 / 2) { - a += "a " - } - System.err.println(a+"b") val usernameTestObserver = sut.username.test() val passwordTestObserver = sut.password.test() val loadingTestObserver = sut.loading.test() @@ -174,7 +169,7 @@ internal class AuthViewModelTest { @ParameterizedTest(name = "GIVEN answer success loginStatus {0} WHEN login called THEN error {1} is shown") fun invalidStatusResultsInErrorState( loginStatus: LoginStatus, - errorType: AuthViewModel.ErrorType + errorType: AuthViewModel.ErrorType, ) { runBlocking { whenever(mockLoginUseCase.invoke(anyOrNull())).doReturn(Answer.Success(loginStatus)) diff --git a/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt b/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt index 94c7055..3d55565 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt @@ -2,8 +2,8 @@ package org.fnives.test.showcase.ui.auth import kotlinx.coroutines.ExperimentalCoroutinesApi import org.fnives.test.showcase.android.testutil.InstantExecutorExtension -import org.fnives.test.showcase.core.login.LoginUseCase import org.fnives.test.showcase.android.testutil.StandardTestMainDispatcher +import org.fnives.test.showcase.core.login.LoginUseCase import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test diff --git a/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt b/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt index 8e7402f..f4d521c 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt @@ -5,6 +5,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking import org.fnives.test.showcase.android.testutil.InstantExecutorExtension +import org.fnives.test.showcase.android.testutil.StandardTestMainDispatcher import org.fnives.test.showcase.core.content.AddContentToFavouriteUseCase import org.fnives.test.showcase.core.content.FetchContentUseCase import org.fnives.test.showcase.core.content.GetAllContentUseCase @@ -15,7 +16,6 @@ import org.fnives.test.showcase.model.content.ContentId import org.fnives.test.showcase.model.content.FavouriteContent import org.fnives.test.showcase.model.content.ImageUrl import org.fnives.test.showcase.model.shared.Resource -import org.fnives.test.showcase.android.testutil.StandardTestMainDispatcher import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test diff --git a/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt b/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt index 4277a8d..adcd7c7 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt @@ -3,8 +3,8 @@ package org.fnives.test.showcase.ui.splash import com.jraska.livedata.test import kotlinx.coroutines.ExperimentalCoroutinesApi import org.fnives.test.showcase.android.testutil.InstantExecutorExtension -import org.fnives.test.showcase.core.login.IsUserLoggedInUseCase import org.fnives.test.showcase.android.testutil.StandardTestMainDispatcher +import org.fnives.test.showcase.core.login.IsUserLoggedInUseCase import org.fnives.test.showcase.ui.shared.Event import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName diff --git a/gradlescripts/testdependencies.gradle b/gradlescripts/testdependencies.gradle index 05ed31e..34c0afb 100644 --- a/gradlescripts/testdependencies.gradle +++ b/gradlescripts/testdependencies.gradle @@ -37,7 +37,7 @@ project.ext { // ------------------VERSIONS------------------ def testing_junit5_version = propertyOrNull('junit5_version') ?: "5.7.0" - def testing_junit4_version = propertyOrNull('juni4_version') ?: "4.12" + def testing_junit4_version = propertyOrNull('juni4_version') ?: "4.13.2" def testing_robolectric_version = propertyOrNull('robolectric_version') ?: "4.7" def testing_androidx_code_version = propertyOrNull('androidx_test_version') ?: "1.4.0" def testing_androidx_junit_version = propertyOrNull('androidx_junit_version') ?: "1.1.3" diff --git a/gradlescripts/versions.gradle b/gradlescripts/versions.gradle index 5362774..42bc419 100644 --- a/gradlescripts/versions.gradle +++ b/gradlescripts/versions.gradle @@ -1,7 +1,7 @@ project.ext { - androidx_core_version = "1.7.0" + androidx_core_version = "1.8.0" androidx_appcompat_version = "1.4.1" - androidx_material_version = "1.5.0" + androidx_material_version = "1.6.1" androidx_constraintlayout_version = "2.1.3" androidx_livedata_version = "2.4.0" androidx_swiperefreshlayout_version = "1.1.0" @@ -28,7 +28,7 @@ project.ext { testing_kotlin_mockito_version = "4.0.0" junit5_version = "5.7.0" testing_json_assert_version = "1.5.0" - testing_junit4_version = "4.12" + testing_junit4_version = "4.13.2" testing_robolectric_version = "4.7" espresso_version = "3.4.0" } \ No newline at end of file diff --git a/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/InstantExecutorExtension.kt b/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/InstantExecutorExtension.kt index a3b109e..f64f387 100644 --- a/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/InstantExecutorExtension.kt +++ b/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/InstantExecutorExtension.kt @@ -12,7 +12,8 @@ import org.junit.jupiter.api.extension.ExtensionContext * * reference: https://developer.android.com/reference/androidx/arch/core/executor/testing/InstantTaskExecutorRule * - * A JUnit5 Extensions that swaps the background executor used by the Architecture Components with a different one which executes each task synchronously. + * A JUnit5 Extensions that swaps the background executor used by the Architecture Components with a different + * one which executes each task synchronously. * You can use this extension for your host side tests that use Architecture Components. */ @SuppressLint("RestrictedApi") diff --git a/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/TestMainDispatcher.kt b/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/TestMainDispatcher.kt index c7db54e..265e0ec 100644 --- a/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/TestMainDispatcher.kt +++ b/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/TestMainDispatcher.kt @@ -17,7 +17,7 @@ abstract class TestMainDispatcher : BeforeEachCallback, AfterEachCallback { protected abstract var createdTestDispatcher: TestDispatcher? - abstract fun createDispatcher() : TestDispatcher + abstract fun createDispatcher(): TestDispatcher final override fun beforeEach(context: ExtensionContext?) { val testDispatcher = createDispatcher() @@ -29,4 +29,4 @@ abstract class TestMainDispatcher : BeforeEachCallback, AfterEachCallback { Dispatchers.resetMain() createdTestDispatcher = null } -} \ No newline at end of file +}