@Test public void addingObserverShouldTriggerAComputation() { TestComputable computable = new TestComputable(1); mLifecycleOwner.handleEvent(Lifecycle.Event.ON_CREATE); final AtomicInteger mValue = new AtomicInteger(-1); computable.getLiveData().observe(mLifecycleOwner, new Observer<Integer>() { @Override public void onChanged(@Nullable Integer integer) { mValue.set(integer); } }); verify(mTaskExecutor, never()).executeOnDiskIO(any(Runnable.class)); assertThat(mValue.get(), is(-1)); mLifecycleOwner.handleEvent(Lifecycle.Event.ON_START); verify(mTaskExecutor).executeOnDiskIO(computable.mRefreshRunnable); assertThat(mValue.get(), is(1)); }
@SuppressWarnings("WeakerAccess") @NonNull public LiveData<T> getLiveData() { return mLiveData; }
ComputableLiveData { @SuppressWarnings("WeakerAccess") @NonNull public LiveData<T> getLiveData() { return mLiveData; } }
ComputableLiveData { @SuppressWarnings("WeakerAccess") @NonNull public LiveData<T> getLiveData() { return mLiveData; } @SuppressWarnings("WeakerAccess")  ComputableLiveData(); }
ComputableLiveData { @SuppressWarnings("WeakerAccess") @NonNull public LiveData<T> getLiveData() { return mLiveData; } @SuppressWarnings("WeakerAccess")  ComputableLiveData(); @SuppressWarnings("WeakerAccess") @NonNull LiveData<T> getLiveData(); void invalidate(); }
ComputableLiveData { @SuppressWarnings("WeakerAccess") @NonNull public LiveData<T> getLiveData() { return mLiveData; } @SuppressWarnings("WeakerAccess")  ComputableLiveData(); @SuppressWarnings("WeakerAccess") @NonNull LiveData<T> getLiveData(); void invalidate();  }