@Before
public void waitForDbCreation() throws Throwable {
final CountDownLatch latch = new CountDownLatch(1);
final LiveData<Boolean> databaseCreated = AppDatabase.getInstance(
InstrumentationRegistry.getTargetContext(), new AppExecutors())
.getDatabaseCreated();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
databaseCreated.observeForever(new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean aBoolean) {
if (Boolean.TRUE.equals(aBoolean)) {
databaseCreated.removeObserver(this);
latch.countDown();
}
}
});
}
});
MatcherAssert.assertThat("database should've initialized",
latch.await(1, TimeUnit.MINUTES), CoreMatchers.is(true));
}
MainActivityTest.java 文件源码
java
阅读 40
收藏 0
点赞 0
评论 0
项目:android-architecture-components
作者:
评论列表
文章目录