### Question:
MainViewModel extends ActorViewModel { @Command(MSG_SEARCH_FOR_CITY_RESULT) void onSearchForCityResult(Optional<City> foundCity) { foundCity.map(this::addNewFavoriteCityAndSaveToPreferences) .defaultIfEmpty(false) .whenNot(Boolean::booleanValue) .then(searchForCityFailure::onNext) .invoke(() -> searchCityInProgress.onNext(false)); } @SuppressLint("RestrictedApi")  MainViewModel(); @RestrictTo(TESTS)  MainViewModel(Scheduler scheduler); void onCleared();  }### Answer:
@Test public void onSearchForCityResultWithValidResultThenHideProgress() { boolean[] result = {false}; viewModel.searchCityInProgress .subscribeOn(scheduler) .observeOn(scheduler) .subscribe(status -> result[0] = status); scheduler.triggerActions(); viewModel.searchForCity.onNext(true); scheduler.triggerActions(); viewModel.onSearchForCityResult(Chain.optional(mockCity())); scheduler.triggerActions(); assertFalse(result[0]); }
@Test public void onSearchForCityResultWithInvalidResultThenHideProgress() { boolean[] result = {false}; viewModel.searchCityInProgress .subscribeOn(scheduler) .observeOn(scheduler) .subscribe(status -> result[0] = status); scheduler.triggerActions(); viewModel.searchForCity.onNext(true); scheduler.triggerActions(); viewModel.onSearchForCityResult(Chain.optional(null)); scheduler.triggerActions(); assertFalse(result[0]); }