Skip to content

Instantly share code, notes, and snippets.

@Peddro
Last active January 10, 2019 10:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peddro/ea03b31026d7d6ed8d32d23a96316ab5 to your computer and use it in GitHub Desktop.
Save Peddro/ea03b31026d7d6ed8d32d23a96316ab5 to your computer and use it in GitHub Desktop.
class RxCallInstruction : Instruction() {
override fun getDescription(): String {
return "Should wait until login completes."
}
override fun checkCondition(): Boolean {
return RxCounter.isIdle()
}
}
object RxCounter {
val counter = AtomicInteger()
fun increment() {
counter.getAndIncrement()
}
fun decrement() {
counter.decrementAndGet()
}
fun isIdle(): Boolean = counter.get() == 0
}
fun <T> Observable<T>.testSchedulers(): Observable<T> =
observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe { RxCounter.increment() }
.doAfterTerminate { RxCounter.decrement() }
@LargeTest
@RunWith(AndroidJUnit4::class)
class Test : BaseTest() {
@get:Rule
val mActivityTestRule = ActivityTestRule(MainActivity::class.java, true, false)
@Before
fun setUp() {
val signIn = SignInFragment.newInstance()
signIn.presenter
.signIn(validEmail, validPassword, false)
.testSchedulers()
.subscribe()
}
@Test
fun checkEmptyOrders() {
ConditionWatcher.waitForCondition(RxCallInstruction())
mActivityTestRule.launchActivity(Intent())
testForEmptyOrders()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment