@Test public void testDemoResponseError404() { reset(mainSceneMock); MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); MockResponse response = new MockResponse(); response.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND); getErrorMockWebServer().enqueue(response); presenter.onSceneAdded(mainSceneMock, null); testScheduler.triggerActions(); verify(mainSceneMock, times(1)).showErrorDialog("Lost!"); verify(mainSceneMock, times(0)).setApiText(anyString()); }
@Override public void onSceneAdded(MainScene scene, Bundle data) { super.onSceneAdded(scene, data); disposable = pokeSource.getPokemonAbilityStringObservable("12") .subscribeOn(provider.io()) .observeOn(provider.ui()) .subscribe(new Consumer<String>() { @Override public void accept(@NonNull String pokemonAbility) throws Exception { if (getScene() != null) { getScene().setApiText(pokemonAbility); } } }, new Consumer<Throwable>() { @Override public void accept(@NonNull Throwable throwable) throws Exception { if (throwable instanceof HttpException) { if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) { if (getScene() != null) { getScene().showErrorDialog("Lost!"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) { if (getScene() != null) { getScene().showErrorDialog("Fire on the Server"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) { if (getScene() != null) { getScene().showErrorDialog("You shall not pass!"); } } } else { if (getScene() != null) { getScene().showErrorDialog(throwable.getMessage()); } } throwable.printStackTrace(); } }); }
MainPresenterImpl extends BasePresenter<MainScene> implements MainPresenter { @Override public void onSceneAdded(MainScene scene, Bundle data) { super.onSceneAdded(scene, data); disposable = pokeSource.getPokemonAbilityStringObservable("12") .subscribeOn(provider.io()) .observeOn(provider.ui()) .subscribe(new Consumer<String>() { @Override public void accept(@NonNull String pokemonAbility) throws Exception { if (getScene() != null) { getScene().setApiText(pokemonAbility); } } }, new Consumer<Throwable>() { @Override public void accept(@NonNull Throwable throwable) throws Exception { if (throwable instanceof HttpException) { if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) { if (getScene() != null) { getScene().showErrorDialog("Lost!"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) { if (getScene() != null) { getScene().showErrorDialog("Fire on the Server"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) { if (getScene() != null) { getScene().showErrorDialog("You shall not pass!"); } } } else { if (getScene() != null) { getScene().showErrorDialog(throwable.getMessage()); } } throwable.printStackTrace(); } }); } }
MainPresenterImpl extends BasePresenter<MainScene> implements MainPresenter { @Override public void onSceneAdded(MainScene scene, Bundle data) { super.onSceneAdded(scene, data); disposable = pokeSource.getPokemonAbilityStringObservable("12") .subscribeOn(provider.io()) .observeOn(provider.ui()) .subscribe(new Consumer<String>() { @Override public void accept(@NonNull String pokemonAbility) throws Exception { if (getScene() != null) { getScene().setApiText(pokemonAbility); } } }, new Consumer<Throwable>() { @Override public void accept(@NonNull Throwable throwable) throws Exception { if (throwable instanceof HttpException) { if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) { if (getScene() != null) { getScene().showErrorDialog("Lost!"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) { if (getScene() != null) { getScene().showErrorDialog("Fire on the Server"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) { if (getScene() != null) { getScene().showErrorDialog("You shall not pass!"); } } } else { if (getScene() != null) { getScene().showErrorDialog(throwable.getMessage()); } } throwable.printStackTrace(); } }); } @Inject  MainPresenterImpl(BaseSchedulerProvider schedulerProvider, PokeDataSource dataSource); }
MainPresenterImpl extends BasePresenter<MainScene> implements MainPresenter { @Override public void onSceneAdded(MainScene scene, Bundle data) { super.onSceneAdded(scene, data); disposable = pokeSource.getPokemonAbilityStringObservable("12") .subscribeOn(provider.io()) .observeOn(provider.ui()) .subscribe(new Consumer<String>() { @Override public void accept(@NonNull String pokemonAbility) throws Exception { if (getScene() != null) { getScene().setApiText(pokemonAbility); } } }, new Consumer<Throwable>() { @Override public void accept(@NonNull Throwable throwable) throws Exception { if (throwable instanceof HttpException) { if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) { if (getScene() != null) { getScene().showErrorDialog("Lost!"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) { if (getScene() != null) { getScene().showErrorDialog("Fire on the Server"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) { if (getScene() != null) { getScene().showErrorDialog("You shall not pass!"); } } } else { if (getScene() != null) { getScene().showErrorDialog(throwable.getMessage()); } } throwable.printStackTrace(); } }); } @Inject  MainPresenterImpl(BaseSchedulerProvider schedulerProvider, PokeDataSource dataSource); @Override void onSceneAdded(MainScene scene, Bundle data); @Override void onSceneRemoved(); }
MainPresenterImpl extends BasePresenter<MainScene> implements MainPresenter { @Override public void onSceneAdded(MainScene scene, Bundle data) { super.onSceneAdded(scene, data); disposable = pokeSource.getPokemonAbilityStringObservable("12") .subscribeOn(provider.io()) .observeOn(provider.ui()) .subscribe(new Consumer<String>() { @Override public void accept(@NonNull String pokemonAbility) throws Exception { if (getScene() != null) { getScene().setApiText(pokemonAbility); } } }, new Consumer<Throwable>() { @Override public void accept(@NonNull Throwable throwable) throws Exception { if (throwable instanceof HttpException) { if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) { if (getScene() != null) { getScene().showErrorDialog("Lost!"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) { if (getScene() != null) { getScene().showErrorDialog("Fire on the Server"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) { if (getScene() != null) { getScene().showErrorDialog("You shall not pass!"); } } } else { if (getScene() != null) { getScene().showErrorDialog(throwable.getMessage()); } } throwable.printStackTrace(); } }); } @Inject  MainPresenterImpl(BaseSchedulerProvider schedulerProvider, PokeDataSource dataSource); @Override void onSceneAdded(MainScene scene, Bundle data); @Override void onSceneRemoved();  }