Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anddep 1207 mvp binding test utils #20

Open
wants to merge 19 commits into
base: dev/G-0.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions buildSrc/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,51 @@
"type": "implementation"
}
]
},
{
"name": "core-mvp-binding-tests",
"dir": "lib-core-mvp-binding-tests",
"artifact_name": "core-mvp-binding-tests",
"third_party_dependencies": [
{
"name": "io.kotest:kotest-runner-junit5",
"type": "implementation"
},
{
"name": "io.mockk:mockk",
"type": "implementation"
}
],
"android_standard_dependencies": [
{
"name": "core-mvp-binding",
"type": "implementation"
},
{
"name": "core-ui",
"type": "implementation"
},
{
"name": "core-navigation",
"type": "implementation"
},
{
"name": "core-mvp",
"type": "implementation"
},
{
"name": "mvp-dialog",
"type": "implementation"
},
{
"name": "connection",
"type": "implementation"
},
{
"name": "rx-extension",
"type": "implementation"
}
]
}
],
"samples": [
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ ext {
"com.squareup.okhttp3:logging-interceptor" : "4.4.1", //https://vk.cc/7UFwTd
"junit:junit" : "4.13", //https://goo.gl/hEcfw1
"org.mockito:mockito-core" : "3.3.3", //https://bit.ly/3bw7XGe
"io.kotest:kotest-runner-junit5" : "4.4.1", //https://bit.ly/3g8bgJd
"io.mockk:mockk" : "1.10.6", //https://bit.ly/3wUGGc3
"org.powermock:powermock-classloading-xstream" : "2.0.7", //https://goo.gl/hEcfw1
"org.powermock:powermock-module-junit4" : "2.0.7", //https://goo.gl/hEcfw1
"org.powermock:powermock-module-junit4-rule" : "2.0.7", //https://goo.gl/hEcfw1
Expand Down
1 change: 1 addition & 0 deletions common/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## 0.5.0-alpha
##### Sample-common
* ANDDEP-1207 Fixed sample's dependencies
* ANDDEP-785 added method scrollToBottom() in RecyclerViewUtils
* ANDDEP-991 added method checkIfSnackbarIsVisible(String)
* ANDDEP-978 Fix common dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import dagger.Module
import dagger.Provides
import ru.surfstudio.android.activity.holder.ActiveActivityHolder
import ru.surfstudio.android.connection.ConnectionProvider
import ru.surfstudio.android.connection.ConnectionProviderImpl
import ru.surfstudio.android.core.ui.navigation.activity.navigator.GlobalNavigator
import ru.surfstudio.android.core.ui.navigation.activity.navigator.GlobalNavigatorImpl
import ru.surfstudio.android.dagger.scope.PerApplication
import ru.surfstudio.android.rx.extension.scheduler.SchedulersProvider
import ru.surfstudio.android.rx.extension.scheduler.SchedulersProviderImpl
Expand Down Expand Up @@ -40,7 +42,7 @@ class DefaultAppModule(
context: Context,
activityHolder: ActiveActivityHolder
): GlobalNavigator {
return GlobalNavigator(context, activityHolder)
return GlobalNavigatorImpl(context, activityHolder)
}

@Provides
Expand All @@ -50,6 +52,6 @@ class DefaultAppModule(
@Provides
@PerApplication
internal fun provideConnectionQualityProvider(context: Context): ConnectionProvider {
return ConnectionProvider(context)
return ConnectionProviderImpl(context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ru.surfstudio.android.core.ui.event.ScreenEventDelegateManager
import ru.surfstudio.android.core.ui.navigation.activity.navigator.ActivityNavigator
import ru.surfstudio.android.core.ui.navigation.activity.navigator.ActivityNavigatorForActivity
import ru.surfstudio.android.core.ui.navigation.fragment.FragmentNavigator
import ru.surfstudio.android.core.ui.navigation.fragment.FragmentNavigatorImpl
import ru.surfstudio.android.core.ui.permission.PermissionManager
import ru.surfstudio.android.core.ui.permission.PermissionManagerForActivity
import ru.surfstudio.android.core.ui.provider.ActivityProvider
Expand Down Expand Up @@ -97,7 +98,7 @@ class DefaultActivityModule(private val persistentScope: ActivityPersistentScope
@Provides
@PerActivity
internal fun provideFragmentNavigator(activityProvider: ActivityProvider): FragmentNavigator {
return FragmentNavigator(activityProvider)
return FragmentNavigatorImpl(activityProvider)
}

@Provides
Expand Down
4 changes: 2 additions & 2 deletions connection/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

## 0.5.0-alpha
##### Connection
* TODO
* ANDDEP-1207 extracted ConnectionProvider interface
## 0.4.0
##### Connection
* Added method for checking Wi-Fi connection in [ConnectionProvider](lib-connection/src/main/java/ru/surfstudio/android/connection/ConnectionProvider.java)
* Added method for checking Wi-Fi connection in [ConnectionProvider](lib-connection/src/main/java/ru/surfstudio/android/connection/ConnectionProvider.kt)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.surfstudio.android.connection

import android.content.Context
import android.net.NetworkInfo
import io.reactivex.Observable

/**
* Provider, позволяющий подписаться на событие изменения состояния соединения
*/
interface ConnectionProvider {

fun observeConnectionChanges(): Observable<Boolean>

fun isConnected(): Boolean

fun isDisconnected(): Boolean

fun isConnectedFast(): Boolean

/**
* Проверка на подключение к Wi-Fi
*
* @return подключен ли девайс к Wi-Fi, или к мобильной сети
*/
fun isConnectedToWifi(): Boolean

fun getNetworkInfo(context: Context): NetworkInfo?
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@

import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;

/**
* Provider, позволяющий подписаться на событие изменения состояния соединения
*/
public class ConnectionProvider {
public class ConnectionProviderImpl implements ConnectionProvider {
private static final long LAST_CONNECTION_QUALITY_RESULT_CACHE_TIME = 60L * 1000; //1 мин

private ConnectionReceiver receiver;
private Context context;
private boolean lastConnectionResultFast = false;
private long lastConnectionResultTime = 0;

public ConnectionProvider(Context context) {
public ConnectionProviderImpl(Context context) {
this.context = context;
this.receiver = new ConnectionReceiver(context);

Expand All @@ -45,18 +42,22 @@ public ConnectionProvider(Context context) {
context.registerReceiver(receiver, intentFilter);
}

@Override
public Observable<Boolean> observeConnectionChanges() {
return receiver.observeConnectionChanges();
}

@Override
public boolean isConnected() {
return receiver.isConnected();
}

@Override
public boolean isDisconnected() {
return !receiver.isConnected();
}

@Override
public boolean isConnectedFast() {
long currentTime = System.currentTimeMillis();
if (currentTime - lastConnectionResultTime > LAST_CONNECTION_QUALITY_RESULT_CACHE_TIME) {
Expand All @@ -66,22 +67,13 @@ public boolean isConnectedFast() {
return lastConnectionResultFast;
}

/**
* Проверка на подключение к Wi-Fi
*
* @return подключен ли девайс к Wi-Fi, или к мобильной сети
*/
@Override
public boolean isConnectedToWifi() {
NetworkInfo info = getNetworkInfo(context);
return info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI;
}

/**
* Get the network info
*
* @param context
* @return
*/
@Override
public NetworkInfo getNetworkInfo(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo();
Expand Down
6 changes: 6 additions & 0 deletions core-mvp-binding/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## 0.5.0-alpha
##### Core-mvp-binding
* ANDDEP-1207 extracted relation's source/target interfaces
* ANDDEP-687 Added "androidx.constraintlayout:constraintlayout" dependency with "implementation" type
* Clearing `BaseRxFragmentView.viewDisposable` move from onDestroy to onDestroyView
* ANDDEP-671 Renamed loadable to response
Expand All @@ -19,6 +20,11 @@ Added state checker methods to Request.
* ANDDEP-968 `Loading.kt`: added class `SimpleLoading`;
* ANDDEP-968 `RequestUi.kt`: added fields `isLoading`, `hasData`, `hasError`;
* ANDDEP-1048 Fixing wrong docs links and docs structure

## 0.5.0-alpha
##### Core-mvp-binding-tests
* ANDDEP-1207 Init module

## 0.3.0
##### Core-mvp-binding
* Renamed `onViewDetached ()` -> `onViewDetach ()`
1 change: 1 addition & 0 deletions core-mvp-binding/lib-core-mvp-binding-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
1 change: 1 addition & 0 deletions core-mvp-binding/lib-core-mvp-binding-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apply from: "$rootDir/buildSrc/baseDeployBuild.gradle"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="ru.surfstudio.android.core.mvp.binding.test" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package ru.surfstudio.android.core.mvp.binding.test

import io.kotest.core.spec.style.AnnotationSpec
import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import io.reactivex.functions.Consumer
import ru.surfstudio.android.connection.ConnectionProvider
import ru.surfstudio.android.core.mvp.binding.rx.relation.Related
import ru.surfstudio.android.core.mvp.binding.rx.relation.mvp.*
import ru.surfstudio.android.core.mvp.binding.rx.ui.BaseRxPresenter
import ru.surfstudio.android.core.mvp.binding.rx.ui.BindModel
import ru.surfstudio.android.core.mvp.binding.test.navigation.TestActivityNavigator
import ru.surfstudio.android.core.mvp.binding.test.navigation.TestDialogNavigator
import ru.surfstudio.android.core.mvp.binding.test.navigation.TestFragmentNavigator
import ru.surfstudio.android.core.mvp.binding.test.navigation.TestTabFragmentNavigator
import ru.surfstudio.android.core.mvp.error.ErrorHandler
import ru.surfstudio.android.core.mvp.presenter.BasePresenterDependency
import ru.surfstudio.android.core.ui.event.ScreenEventDelegateManager
import ru.surfstudio.android.core.ui.navigation.activity.navigator.ActivityNavigator
import ru.surfstudio.android.core.ui.state.ScreenState
import ru.surfstudio.android.rx.extension.scheduler.SchedulersProvider

object TEST : ActionSource, ActionTarget, StateSource, StateTarget, CommandSource, CommandTarget

/**
* Базовый класс для тестирования презентера
* @param PT тип презентера
* @param BMT тип bind-модели
*/
abstract class BasePresenterTest<PT : BaseRxPresenter, BMT : BindModel> : AnnotationSpec(), Related<TEST> {

lateinit var presenter: PT
lateinit var bm: BMT

var activityNavigator = TestActivityNavigator()
var fragmentNavigator = TestFragmentNavigator()
var tabFragmentNavigator = TestTabFragmentNavigator()
var dialogNavigator = TestDialogNavigator()

var connectionProvider = TestConnectionProvider()

var basePresenterDependency = createBasePresenterDependency()

abstract fun createBindModel(): BMT

abstract fun createPresenter(bm: BMT): PT

fun createBasePresenterDependency(
schedulersProvider: SchedulersProvider = TestSchedulersProvider(),
screenState: ScreenState = TestScreenState(),
eventDelegateManager: ScreenEventDelegateManager = TestScreenEventDelegateManager(),
errorHandler: ErrorHandler = TestErrorHandler(),
connectionProvider: ConnectionProvider = this.connectionProvider,
activityNavigator: ActivityNavigator = this.activityNavigator
): BasePresenterDependency = BasePresenterDependency(
schedulersProvider,
screenState,
eventDelegateManager,
errorHandler,
connectionProvider,
activityNavigator
)

/**
* Инициализация презентера
*
* Следует вызывать перед выполением каждого теста
*/
fun setUpPresenter() {
bm = createBindModel()
presenter = createPresenter(bm)
presenter.onFirstLoad()
}

/**
* Востановление превоначального состояния окружения
*
* Следует вызывать после каждого теста
*/
fun resetPresenter() {
resetNavigators()
connectionProvider.reset()
presenter.onDestroy()
}

/**
* Пересоздание презентера
*/
fun recreatePresenter() {
if (::presenter.isInitialized) {
resetPresenter()
}
setUpPresenter()
}

fun resetNavigators() {
activityNavigator.reset()
fragmentNavigator.reset()
tabFragmentNavigator.reset()
dialogNavigator.reset()
}

override fun relationEntity() = TEST

override fun <T> subscribe(
observable: Observable<out T>,
onNext: Consumer<T>,
onError: (Throwable) -> Unit
): Disposable {
throw NotImplementedError()
}
}
Loading