From 52705b8cd5ca6e5994290a4b463ea4e1020bc751 Mon Sep 17 00:00:00 2001 From: Dimitar Gochev Date: Thu, 8 Dec 2022 11:08:35 -0500 Subject: [PATCH] afterObserve.invoke() only if latch is satisfied `getOrAwaitValue` in `LiveDataTestUtil` should invoke `afterObserve` only if the latch is satisfied (i.e. data was changed) --- .../example/livedatabuilder/util/LiveDataTestUtil.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LiveDataSample/app/src/test/java/com/android/example/livedatabuilder/util/LiveDataTestUtil.kt b/LiveDataSample/app/src/test/java/com/android/example/livedatabuilder/util/LiveDataTestUtil.kt index 27b8ff3f..6877d6c9 100644 --- a/LiveDataSample/app/src/test/java/com/android/example/livedatabuilder/util/LiveDataTestUtil.kt +++ b/LiveDataSample/app/src/test/java/com/android/example/livedatabuilder/util/LiveDataTestUtil.kt @@ -43,10 +43,10 @@ fun LiveData.getOrAwaitValue( } this.observeForever(observer) - afterObserve.invoke() - // Don't wait indefinitely if the LiveData is not set. - if (!latch.await(time, timeUnit)) { + if (latch.await(time, timeUnit)) { + afterObserve.invoke() + } else { this.removeObserver(observer) throw TimeoutException("LiveData value was never set.") }