MainActivityTest.java 文件源码

java
阅读 40 收藏 0 点赞 0 评论 0

项目:android-architecture-components 作者:
@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));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号