@Test public void shouldSaveRegime() throws Exception { when(regimenRepository.getByNameAndCategory(anyString(), any(Regimen.RegimeType.class))).thenReturn(null); TestSubscriber<Regimen> subscriber = new TestSubscriber<>(); presenter.saveRegimes(getInventoryViewModels(), Regimen.RegimeType.Adults).subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); ArgumentCaptor<Regimen> regimenArgumentCaptor = ArgumentCaptor.forClass(Regimen.class); verify(regimenRepository).create(regimenArgumentCaptor.capture()); Regimen regimen = regimenArgumentCaptor.getValue(); assertThat(regimen.getName(), is("3TC 150mg")); assertThat(regimen.getType(), is(Regimen.RegimeType.Adults)); assertThat(regimen.isCustom(), is(true)); }
public Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType) { final String regimenName = viewModel.getShortCode(); return Observable.create((Observable.OnSubscribe<Regimen>) subscriber -> { Regimen regimen = null; try { regimen = regimenRepository.getByNameAndCategory(regimenName, regimeType); if (regimen == null) { regimen = new Regimen(); regimen.setType(regimeType); regimen.setCode(regimeType + regimenName); regimen.setName(regimenName); regimen.setCustom(true); regimenRepository.create(regimen); } } catch (LMISException e) { new LMISException(e, "ProductPresenter.saveRegimes").reportToFabric(); subscriber.onError(e); } subscriber.onNext(regimen); subscriber.onCompleted(); }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }
ProductPresenter extends Presenter { public Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType) { final String regimenName = viewModel.getShortCode(); return Observable.create((Observable.OnSubscribe<Regimen>) subscriber -> { Regimen regimen = null; try { regimen = regimenRepository.getByNameAndCategory(regimenName, regimeType); if (regimen == null) { regimen = new Regimen(); regimen.setType(regimeType); regimen.setCode(regimeType + regimenName); regimen.setName(regimenName); regimen.setCustom(true); regimenRepository.create(regimen); } } catch (LMISException e) { new LMISException(e, "ProductPresenter.saveRegimes").reportToFabric(); subscriber.onError(e); } subscriber.onNext(regimen); subscriber.onCompleted(); }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } }
ProductPresenter extends Presenter { public Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType) { final String regimenName = viewModel.getShortCode(); return Observable.create((Observable.OnSubscribe<Regimen>) subscriber -> { Regimen regimen = null; try { regimen = regimenRepository.getByNameAndCategory(regimenName, regimeType); if (regimen == null) { regimen = new Regimen(); regimen.setType(regimeType); regimen.setCode(regimeType + regimenName); regimen.setName(regimenName); regimen.setCustom(true); regimenRepository.create(regimen); } } catch (LMISException e) { new LMISException(e, "ProductPresenter.saveRegimes").reportToFabric(); subscriber.onError(e); } subscriber.onNext(regimen); subscriber.onCompleted(); }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  }
ProductPresenter extends Presenter { public Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType) { final String regimenName = viewModel.getShortCode(); return Observable.create((Observable.OnSubscribe<Regimen>) subscriber -> { Regimen regimen = null; try { regimen = regimenRepository.getByNameAndCategory(regimenName, regimeType); if (regimen == null) { regimen = new Regimen(); regimen.setType(regimeType); regimen.setCode(regimeType + regimenName); regimen.setName(regimenName); regimen.setCustom(true); regimenRepository.create(regimen); } } catch (LMISException e) { new LMISException(e, "ProductPresenter.saveRegimes").reportToFabric(); subscriber.onError(e); } subscriber.onNext(regimen); subscriber.onCompleted(); }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  @Override void attachView(BaseView v); Observable<List<RegimeProductViewModel>> loadRegimeProducts(Regimen.RegimeType type); Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType); Observable<List<InventoryViewModel>> loadEmergencyProducts(); }
ProductPresenter extends Presenter { public Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType) { final String regimenName = viewModel.getShortCode(); return Observable.create((Observable.OnSubscribe<Regimen>) subscriber -> { Regimen regimen = null; try { regimen = regimenRepository.getByNameAndCategory(regimenName, regimeType); if (regimen == null) { regimen = new Regimen(); regimen.setType(regimeType); regimen.setCode(regimeType + regimenName); regimen.setName(regimenName); regimen.setCustom(true); regimenRepository.create(regimen); } } catch (LMISException e) { new LMISException(e, "ProductPresenter.saveRegimes").reportToFabric(); subscriber.onError(e); } subscriber.onNext(regimen); subscriber.onCompleted(); }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  @Override void attachView(BaseView v); Observable<List<RegimeProductViewModel>> loadRegimeProducts(Regimen.RegimeType type); Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType); Observable<List<InventoryViewModel>> loadEmergencyProducts();  }