add tests
This commit is contained in:
parent
b84d86acfb
commit
16df4918e2
@ -5,13 +5,7 @@
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
<SelectionState runConfigName="testOtpTextField">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
<SelectionState runConfigName="preivewTimerText">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
<SelectionState runConfigName="PreviewBaseTimerText">
|
||||
<SelectionState runConfigName="EmailValidationTest">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
|
@ -13,6 +13,7 @@
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
|
||||
|
@ -2,23 +2,39 @@ package com.example.netwrok_datastore
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.example.netwrok_datastore.domain.validator.EmailValidator
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.runners.Parameterized
|
||||
import org.junit.runners.Parameterized.Parameters
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@RunWith(Parameterized::class)
|
||||
class EmailValidationTest(val email: String, val resultTest: Boolean) {
|
||||
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.example.netwrok_datastore", appContext.packageName)
|
||||
fun testValidationEmail(){
|
||||
|
||||
val result = EmailValidator().validate(email)
|
||||
assertEquals(result, resultTest)
|
||||
}
|
||||
|
||||
|
||||
companion object{
|
||||
@JvmStatic
|
||||
@Parameters
|
||||
fun getData() = listOf(
|
||||
arrayOf("test", false),
|
||||
arrayOf("@", false),
|
||||
arrayOf("test@", true),
|
||||
arrayOf("test.ru", false)
|
||||
)
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import com.example.netwrok_datastore.data.AuthRepository
|
||||
import com.example.netwrok_datastore.data.local.LocalStorage
|
||||
import com.example.netwrok_datastore.data.remote.NetworkResponse
|
||||
import com.example.netwrok_datastore.data.remote.dto.request.RegistrationRequest
|
||||
import com.example.netwrok_datastore.domain.validator.EmailValidator
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
@ -13,6 +14,7 @@ class AuthUseCase(private val localStorage: LocalStorage,
|
||||
suspend fun registration(registrationRequest: RegistrationRequest): Flow<NetworkResponse> = flow{
|
||||
try {
|
||||
emit(NetworkResponse.Loading)
|
||||
if (!EmailValidator().validate(registrationRequest.email)) emit(NetworkResponse.Error("Validation Error"))
|
||||
val result = authRepository.registration(registrationRequest)
|
||||
localStorage.setToken(result.second)
|
||||
emit(NetworkResponse.Success(result))
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.example.netwrok_datastore.domain.validator
|
||||
|
||||
class EmailValidator: Validator {
|
||||
override fun <T> validate(value: T): Boolean {
|
||||
val email = value as String
|
||||
return email.contains("@")
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.example.netwrok_datastore.domain.validator
|
||||
|
||||
interface Validator {
|
||||
fun <T> validate(value: T): Boolean
|
||||
}
|
Loading…
Reference in New Issue
Block a user