Skip to content

Instantly share code, notes, and snippets.

@atomgomba
Created March 4, 2019 13:26
Show Gist options
  • Save atomgomba/e7c03bf20033ef770c7c9de9455affbd to your computer and use it in GitHub Desktop.
Save atomgomba/e7c03bf20033ef770c7c9de9455affbd to your computer and use it in GitHub Desktop.
Android LifecycleOwner for unit testing
import androidx.lifecycle.Lifecycle.State
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
/**
* @author Károly Kiripolszky <karcsi@ekezet.com>
*/
class TestLifecycleOwner(state: State = State.STARTED) : LifecycleOwner {
private val lifecycle = LifecycleRegistry(this)
init {
lifecycle.markState(state)
}
override fun getLifecycle() = lifecycle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment