Last active
January 10, 2019 10:14
-
-
Save Peddro/ea03b31026d7d6ed8d32d23a96316ab5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RxCallInstruction : Instruction() { | |
override fun getDescription(): String { | |
return "Should wait until login completes." | |
} | |
override fun checkCondition(): Boolean { | |
return RxCounter.isIdle() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object RxCounter { | |
val counter = AtomicInteger() | |
fun increment() { | |
counter.getAndIncrement() | |
} | |
fun decrement() { | |
counter.decrementAndGet() | |
} | |
fun isIdle(): Boolean = counter.get() == 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> Observable<T>.testSchedulers(): Observable<T> = | |
observeOn(AndroidSchedulers.mainThread()) | |
.doOnSubscribe { RxCounter.increment() } | |
.doAfterTerminate { RxCounter.decrement() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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