@Test public void thatPlaneInfoIsSummedUpCombinedWithObservables() throws Exception { WaitMonitor monitor = new WaitMonitor(); // error handler function Action1<Throwable> exceptionConsumer = (e) -> { e.printStackTrace(); monitor.complete(); }; String[] planeTypes = {"Boeing 777", "Boeing 747", "Boeing 737", "Airbus A330"}; Observable.from(planeTypes) .flatMap(this::fetchArticle) .map(this::parsePlaneInfo) .subscribe( (planeInfo) -> { Summary.printCounter(planeInfo.typeName, planeInfo.numberBuild); }, exceptionConsumer, monitor::complete); monitor.waitFor(10000, TimeUnit.MILLISECONDS); }
@Test public void thatPlaneBuildCountIsFetchedSynchronously() throws Exception { // get article on 777 String article777 = fetchArticle("Boeing 777"); // extract number of built planes String buildCount777 = parseBuildCount(article777); Summary.printCounter("777", buildCount777); // get article on 747 String article747 = fetchArticle("Boeing 747"); // extract number of built planes String buildCount747 = parseBuildCount(article747); Summary.printCounter("747", buildCount747); }