Clear unused and fix tests
This commit is contained in:
@@ -7,8 +7,6 @@ interface PreferencesStorage {
|
|||||||
|
|
||||||
val baseUrlKey: Preferences.Key<String>
|
val baseUrlKey: Preferences.Key<String>
|
||||||
|
|
||||||
val authHeaderKey: Preferences.Key<String>
|
|
||||||
|
|
||||||
val isDisclaimerAcceptedKey: Preferences.Key<Boolean>
|
val isDisclaimerAcceptedKey: Preferences.Key<Boolean>
|
||||||
|
|
||||||
suspend fun <T> getValue(key: Preferences.Key<T>): T?
|
suspend fun <T> getValue(key: Preferences.Key<T>): T?
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ class PreferencesStorageImpl @Inject constructor(
|
|||||||
|
|
||||||
override val baseUrlKey = stringPreferencesKey("baseUrl")
|
override val baseUrlKey = stringPreferencesKey("baseUrl")
|
||||||
|
|
||||||
override val authHeaderKey = stringPreferencesKey("authHeader")
|
|
||||||
|
|
||||||
override val isDisclaimerAcceptedKey = booleanPreferencesKey("isDisclaimedAccepted")
|
override val isDisclaimerAcceptedKey = booleanPreferencesKey("isDisclaimedAccepted")
|
||||||
|
|
||||||
override suspend fun <T> getValue(key: Preferences.Key<T>): T? {
|
override suspend fun <T> getValue(key: Preferences.Key<T>): T? {
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ interface AuthModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideAuthServiceFactory(retrofitBuilder: RetrofitBuilder,
|
fun provideAuthServiceFactory(
|
||||||
|
retrofitBuilder: RetrofitBuilder,
|
||||||
baseURLStorage: BaseURLStorage,
|
baseURLStorage: BaseURLStorage,
|
||||||
): ServiceFactory<AuthService> = retrofitBuilder.createServiceFactory(baseURLStorage)
|
): ServiceFactory<AuthService> = retrofitBuilder.createServiceFactory(baseURLStorage)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package gq.kirmanak.mealient.ui.auth
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class AuthenticatorActivity : AppCompatActivity() {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".ui.auth.AuthenticatorActivity">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
|
||||||
android:id="@+id/toolbar_holder"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:liftOnScroll="true">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
style="@style/Widget.MaterialComponents.Toolbar.Primary"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?actionBarSize"
|
|
||||||
app:layout_scrollFlags="scroll|snap" />
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
<androidx.fragment.app.FragmentContainerView
|
|
||||||
android:id="@+id/nav_host"
|
|
||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
app:defaultNavHost="true"
|
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/toolbar_holder"
|
|
||||||
app:navGraph="@navigation/authenticator_graph" />
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/authenticator_graph"
|
|
||||||
app:startDestination="@id/authenticationFragment2">
|
|
||||||
|
|
||||||
<fragment
|
|
||||||
android:id="@+id/authenticationFragment2"
|
|
||||||
android:name="gq.kirmanak.mealient.ui.auth.AuthenticationFragment"
|
|
||||||
android:label="fragment_authentication"
|
|
||||||
tools:layout="@layout/fragment_authentication" />
|
|
||||||
</navigation>
|
|
||||||
@@ -32,7 +32,7 @@ class AuthDataSourceImplTest {
|
|||||||
fun setUp() {
|
fun setUp() {
|
||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
subject = AuthDataSourceImpl(authServiceFactory, NetworkModule.createJson())
|
subject = AuthDataSourceImpl(authServiceFactory, NetworkModule.createJson())
|
||||||
coEvery { authServiceFactory.provideService() } returns authService
|
coEvery { authServiceFactory.provideService(any(), eq(false)) } returns authService
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -71,7 +71,9 @@ class AuthDataSourceImplTest {
|
|||||||
|
|
||||||
@Test(expected = MalformedUrl::class)
|
@Test(expected = MalformedUrl::class)
|
||||||
fun `when authenticate and provideService throws then MalformedUrl`() = runTest {
|
fun `when authenticate and provideService throws then MalformedUrl`() = runTest {
|
||||||
coEvery { authServiceFactory.provideService() } throws MalformedUrl(RuntimeException())
|
coEvery {
|
||||||
|
authServiceFactory.provideService(any(), eq(false))
|
||||||
|
} throws MalformedUrl(RuntimeException())
|
||||||
callAuthenticate()
|
callAuthenticate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class RetrofitServiceFactoryTest {
|
|||||||
fun setUp() {
|
fun setUp() {
|
||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
subject = retrofitBuilder.createServiceFactory(baseURLStorage)
|
subject = retrofitBuilder.createServiceFactory(baseURLStorage)
|
||||||
coEvery { retrofitBuilder.buildRetrofit(any()) } returns retrofit
|
coEvery { retrofitBuilder.buildRetrofit(any(), eq(true)) } returns retrofit
|
||||||
every { retrofit.create(eq(VersionService::class.java)) } returns versionService
|
every { retrofit.create(eq(VersionService::class.java)) } returns versionService
|
||||||
coEvery { baseURLStorage.requireBaseURL() } returns TEST_BASE_URL
|
coEvery { baseURLStorage.requireBaseURL() } returns TEST_BASE_URL
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ class RetrofitServiceFactoryTest {
|
|||||||
fun `when provideService called twice then builder called once`() = runTest {
|
fun `when provideService called twice then builder called once`() = runTest {
|
||||||
subject.provideService()
|
subject.provideService()
|
||||||
subject.provideService()
|
subject.provideService()
|
||||||
coVerifyAll { retrofitBuilder.buildRetrofit(eq(TEST_BASE_URL)) }
|
coVerifyAll { retrofitBuilder.buildRetrofit(eq(TEST_BASE_URL), eq(true)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -61,8 +61,8 @@ class RetrofitServiceFactoryTest {
|
|||||||
subject.provideService()
|
subject.provideService()
|
||||||
subject.provideService("new url")
|
subject.provideService("new url")
|
||||||
coVerifyAll {
|
coVerifyAll {
|
||||||
retrofitBuilder.buildRetrofit(eq(TEST_BASE_URL))
|
retrofitBuilder.buildRetrofit(eq(TEST_BASE_URL), eq(true))
|
||||||
retrofitBuilder.buildRetrofit(eq("new url"))
|
retrofitBuilder.buildRetrofit(eq("new url"), eq(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,30 +18,30 @@ class PreferencesStorageImplTest : HiltRobolectricTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when getValue without writes then null`() = runTest {
|
fun `when getValue without writes then null`() = runTest {
|
||||||
assertThat(subject.getValue(subject.authHeaderKey)).isNull()
|
assertThat(subject.getValue(subject.baseUrlKey)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException::class)
|
@Test(expected = IllegalStateException::class)
|
||||||
fun `when requireValue without writes then throws IllegalStateException`() = runTest {
|
fun `when requireValue without writes then throws IllegalStateException`() = runTest {
|
||||||
subject.requireValue(subject.authHeaderKey)
|
subject.requireValue(subject.baseUrlKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when getValue after write then returns value`() = runTest {
|
fun `when getValue after write then returns value`() = runTest {
|
||||||
subject.storeValues(Pair(subject.authHeaderKey, "test"))
|
subject.storeValues(Pair(subject.baseUrlKey, "test"))
|
||||||
assertThat(subject.getValue(subject.authHeaderKey)).isEqualTo("test")
|
assertThat(subject.getValue(subject.baseUrlKey)).isEqualTo("test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when storeValue then valueUpdates emits`() = runTest {
|
fun `when storeValue then valueUpdates emits`() = runTest {
|
||||||
subject.storeValues(Pair(subject.authHeaderKey, "test"))
|
subject.storeValues(Pair(subject.baseUrlKey, "test"))
|
||||||
assertThat(subject.valueUpdates(subject.authHeaderKey).first()).isEqualTo("test")
|
assertThat(subject.valueUpdates(subject.baseUrlKey).first()).isEqualTo("test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when remove value then getValue returns null`() = runTest {
|
fun `when remove value then getValue returns null`() = runTest {
|
||||||
subject.storeValues(Pair(subject.authHeaderKey, "test"))
|
subject.storeValues(Pair(subject.baseUrlKey, "test"))
|
||||||
subject.removeValues(subject.authHeaderKey)
|
subject.removeValues(subject.baseUrlKey)
|
||||||
assertThat(subject.getValue(subject.authHeaderKey)).isNull()
|
assertThat(subject.getValue(subject.baseUrlKey)).isNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user