diff --git a/.idea/misc.xml b/.idea/misc.xml
index aa4030e..d266da5 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/appupdatewrapper/build.gradle b/appupdatewrapper/build.gradle
index b9086be..595d72d 100644
--- a/appupdatewrapper/build.gradle
+++ b/appupdatewrapper/build.gradle
@@ -38,15 +38,12 @@ android {
defaultConfig {
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargetSdkVersion
- versionCode versionCode
- versionName versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
- debuggable true
minifyEnabled false
}
release {
@@ -62,7 +59,7 @@ dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api 'androidx.core:core-ktx:1.7.0'
- kapt 'androidx.lifecycle:lifecycle-common-java8:2.4.0'
+ api 'androidx.lifecycle:lifecycle-common:2.4.0'
api 'com.google.android.play:core:1.10.2'
implementation 'com.jakewharton.timber:timber:5.0.1'
@@ -73,7 +70,8 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
- testImplementation 'org.robolectric:robolectric:4.7.2'
+ testImplementation 'org.robolectric:robolectric:4.7.3'
+ testImplementation 'androidx.lifecycle:lifecycle-runtime-testing:2.4.0'
}
dokkaJavadoc.configure {
diff --git a/appupdatewrapper/src/main/java/com/motorro/appupdatewrapper/AppUpdateStateMachine.kt b/appupdatewrapper/src/main/java/com/motorro/appupdatewrapper/AppUpdateStateMachine.kt
index 782f6fb..db19b30 100644
--- a/appupdatewrapper/src/main/java/com/motorro/appupdatewrapper/AppUpdateStateMachine.kt
+++ b/appupdatewrapper/src/main/java/com/motorro/appupdatewrapper/AppUpdateStateMachine.kt
@@ -16,10 +16,9 @@
package com.motorro.appupdatewrapper
import androidx.annotation.VisibleForTesting
+import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.Lifecycle.Event.*
-import androidx.lifecycle.LifecycleObserver
-import androidx.lifecycle.OnLifecycleEvent
+import androidx.lifecycle.LifecycleOwner
import com.google.android.play.core.appupdate.AppUpdateManager
/**
@@ -59,7 +58,7 @@ internal class AppUpdateLifecycleStateMachine(
override val updateManager: AppUpdateManager,
override val view: AppUpdateView,
override val flowBreaker: UpdateFlowBreaker = UpdateFlowBreaker.alwaysOn()
-): AppUpdateStateMachine, AppUpdateWrapper, LifecycleObserver, Tagged {
+): AppUpdateStateMachine, AppUpdateWrapper, DefaultLifecycleObserver, Tagged {
/**
* Current update state
*/
@@ -94,23 +93,19 @@ internal class AppUpdateLifecycleStateMachine(
}
}
- @OnLifecycleEvent(ON_START)
- fun onStart() {
+ override fun onStart(owner: LifecycleOwner) {
currentUpdateState.onStart()
}
- @OnLifecycleEvent(ON_RESUME)
- fun onResume() {
+ override fun onResume(owner: LifecycleOwner) {
currentUpdateState.onResume()
}
- @OnLifecycleEvent(ON_RESUME)
- fun onPause() {
+ override fun onPause(owner: LifecycleOwner) {
currentUpdateState.onPause()
}
- @OnLifecycleEvent(ON_STOP)
- fun onStop() {
+ override fun onStop(owner: LifecycleOwner) {
currentUpdateState.onStop()
}
diff --git a/appupdatewrapper/src/test/java/com/motorro/appupdatewrapper/AppUpdateLifecycleStateMachineTest.kt b/appupdatewrapper/src/test/java/com/motorro/appupdatewrapper/AppUpdateLifecycleStateMachineTest.kt
index 401dd3b..f63390a 100644
--- a/appupdatewrapper/src/test/java/com/motorro/appupdatewrapper/AppUpdateLifecycleStateMachineTest.kt
+++ b/appupdatewrapper/src/test/java/com/motorro/appupdatewrapper/AppUpdateLifecycleStateMachineTest.kt
@@ -16,9 +16,13 @@
package com.motorro.appupdatewrapper
import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.Lifecycle.State.*
+import androidx.lifecycle.Lifecycle.State.INITIALIZED
+import androidx.lifecycle.testing.TestLifecycleOwner
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.nhaarman.mockitokotlin2.*
+import com.nhaarman.mockitokotlin2.mock
+import com.nhaarman.mockitokotlin2.never
+import com.nhaarman.mockitokotlin2.spy
+import com.nhaarman.mockitokotlin2.verify
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -27,16 +31,14 @@ import kotlin.test.assertTrue
@RunWith(AndroidJUnit4::class)
class AppUpdateLifecycleStateMachineTest: TestAppTest() {
- private lateinit var lifecycle: Lifecycle
+ private lateinit var lifecycleOwner: TestLifecycleOwner
private lateinit var stateMachine: AppUpdateLifecycleStateMachine
private lateinit var state: AppUpdateState
@Before
fun init() {
- lifecycle = mock {
- on { currentState } doReturn DESTROYED
- }
- stateMachine = AppUpdateLifecycleStateMachine(lifecycle, mock(), mock(), mock())
+ lifecycleOwner = TestLifecycleOwner(INITIALIZED)
+ stateMachine = AppUpdateLifecycleStateMachine(lifecycleOwner.lifecycle, mock(), mock(), mock())
state = spy()
}
@@ -46,7 +48,7 @@ class AppUpdateLifecycleStateMachineTest: TestAppTest() {
stateMachine.setUpdateState(state)
assertEquals(stateMachine, state.stateMachine)
- stateMachine.onStart()
+ lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_START)
verify(state).onStart()
}
@@ -65,24 +67,22 @@ class AppUpdateLifecycleStateMachineTest: TestAppTest() {
}
@Test
- fun callsStateOnStartIfLifecycleStarted() {
- whenever(lifecycle.currentState).thenReturn(STARTED)
+ fun followsLifecycle() {
stateMachine.setUpdateState(state)
- verify(state).onStart()
- verify(state, never()).onResume()
- }
- @Test
- fun callsStateOnStartAndOnResumedIfLifecycleResumed() {
- whenever(lifecycle.currentState).thenReturn(RESUMED)
- stateMachine.setUpdateState(state)
+ lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_START)
verify(state).onStart()
+ lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
verify(state).onResume()
+ lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
+ verify(state).onPause()
+ lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
+ verify(state).onStop()
}
@Test
fun initializes() {
- verify(lifecycle).addObserver(stateMachine)
+ assertEquals(1, lifecycleOwner.observerCount)
assertTrue { stateMachine.currentUpdateState is None}
}
@@ -90,7 +90,7 @@ class AppUpdateLifecycleStateMachineTest: TestAppTest() {
fun cleansUp() {
stateMachine.setUpdateState(state)
stateMachine.cleanup()
- verify(lifecycle).removeObserver(stateMachine)
- assertTrue { stateMachine.currentUpdateState is None}
+ assertEquals(0, lifecycleOwner.observerCount)
+ assertTrue { stateMachine.currentUpdateState is None }
}
}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 13db35f..986dbd9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ apply from: 'gradle/maven-publish-config.gradle'
apply plugin: 'io.github.gradle-nexus.publish-plugin'
buildscript {
- ext.kotlin_version = '1.6.0'
+ ext.kotlin_version = '1.6.10'
ext.dokka_version = '1.6.0'
repositories {
google()
@@ -21,9 +21,9 @@ buildscript {
}
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.0.3'
+ classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
+ classpath 'org.ajoberstar.grgit:grgit-gradle:4.1.1'
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath "io.github.gradle-nexus:publish-plugin:1.0.0"
}
diff --git a/testapp/src/main/java/com/motorro/appupdatewrapper/testapp/TestUpdateActivity.kt b/testapp/src/main/java/com/motorro/appupdatewrapper/testapp/TestUpdateActivity.kt
index 3119bc5..1e3d73e 100644
--- a/testapp/src/main/java/com/motorro/appupdatewrapper/testapp/TestUpdateActivity.kt
+++ b/testapp/src/main/java/com/motorro/appupdatewrapper/testapp/TestUpdateActivity.kt
@@ -34,11 +34,13 @@ class TestUpdateActivity : AppCompatActivity(), AppUpdateView {
// To pass 'activity result' as fake update manager does not start activities
fun passActivityResult(requestCode: Int, resultCode: Int) {
+ @Suppress("DEPRECATION")
onActivityResult(requestCode, resultCode, null)
}
// Passes an activity result to wrapper to check for play-core interaction
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ @Suppress("DEPRECATION")
super.onActivityResult(requestCode, resultCode, data)
if (updateWrapper.checkActivityResult(requestCode, resultCode)) {
// Result handled and processed