mike.cole
02/13/2017, 3:14 PM@Test
fun testLoginSuccess() {
val latch = CountDownLatch(1)
val deferred = deferred<JSONObject, Exception>()
testMiddlewareResult = deferred.promise
// Some Fragment specific setup
sut?.loginButton?.performClick() // success and fail blocks get added in the Fragment
deferred.promise.always { // This is how we know the Fragment has had a chance to execute the success or fail
latch.countDown()
}
deferred.resolve(JSONObject())
latch.await(200, TimeUnit.MILLISECONDS) // Wait very briefly for all of this to happen across threading
// My assertions go here
}