package com.sduduzog.slimlauncher import android.arch.lifecycle.LiveData import android.arch.lifecycle.Observer import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit object LiveDataTestUtil { @Throws(InterruptedException::class) fun getValue(liveData: LiveData): T { val data = arrayOfNulls(1) val latch = CountDownLatch(1) val observer = object : Observer { override fun onChanged(o: T?) { data[0] = o latch.countDown() liveData.removeObserver(this) } } liveData.observeForever(observer) latch.await(2, TimeUnit.SECONDS) return data[0] as T } }