@Test public void feedNotFound() { when(user.findId(USERNAME)).thenReturn(Single.just(null)); FeedService service = new FeedService(user, repo, feedItemSubmitter); Observable<List<FeedItem>> feed = service.feed(USERNAME); assertNotNull("feed was null", feed); List<FeedItem> content = feed.toBlocking().first(); assertEquals("wrong feed size", 1, content.size()); FeedItem item = content.get(0); assertEquals("wrong item text", "Unknown user: "+USERNAME, item.getText()); verify(user).findId(USERNAME); }
public Observable<List<FeedItem>> feed(String username) { return user.findId(username).toObservable() .flatMap(userid -> { if (StringUtils.hasText(userid)) { return Observable.from(repo.findByUserid(userid)); } else { return Observable.just(singletonFeed("Unknown user: " + username)); } }) .flatMapIterable(feedItems -> feedItems) .toSortedList((feedItem1, feedItem2) -> feedItem2.getCreated().compareTo(feedItem1.getCreated())); }
FeedService { public Observable<List<FeedItem>> feed(String username) { return user.findId(username).toObservable() .flatMap(userid -> { if (StringUtils.hasText(userid)) { return Observable.from(repo.findByUserid(userid)); } else { return Observable.just(singletonFeed("Unknown user: " + username)); } }) .flatMapIterable(feedItems -> feedItems) .toSortedList((feedItem1, feedItem2) -> feedItem2.getCreated().compareTo(feedItem1.getCreated())); } }
FeedService { public Observable<List<FeedItem>> feed(String username) { return user.findId(username).toObservable() .flatMap(userid -> { if (StringUtils.hasText(userid)) { return Observable.from(repo.findByUserid(userid)); } else { return Observable.just(singletonFeed("Unknown user: " + username)); } }) .flatMapIterable(feedItems -> feedItems) .toSortedList((feedItem1, feedItem2) -> feedItem2.getCreated().compareTo(feedItem1.getCreated())); }  }
FeedService { public Observable<List<FeedItem>> feed(String username) { return user.findId(username).toObservable() .flatMap(userid -> { if (StringUtils.hasText(userid)) { return Observable.from(repo.findByUserid(userid)); } else { return Observable.just(singletonFeed("Unknown user: " + username)); } }) .flatMapIterable(feedItems -> feedItems) .toSortedList((feedItem1, feedItem2) -> feedItem2.getCreated().compareTo(feedItem1.getCreated())); }  Observable<List<FeedItem>> feed(String username); Single<FeedItem> addFeedItem(String username, String text); @ServiceActivator(inputChannel = Sink.INPUT) @SuppressWarnings("unused") void propagate(FeedItem feedItem); }
FeedService { public Observable<List<FeedItem>> feed(String username) { return user.findId(username).toObservable() .flatMap(userid -> { if (StringUtils.hasText(userid)) { return Observable.from(repo.findByUserid(userid)); } else { return Observable.just(singletonFeed("Unknown user: " + username)); } }) .flatMapIterable(feedItems -> feedItems) .toSortedList((feedItem1, feedItem2) -> feedItem2.getCreated().compareTo(feedItem1.getCreated())); }  Observable<List<FeedItem>> feed(String username); Single<FeedItem> addFeedItem(String username, String text); @ServiceActivator(inputChannel = Sink.INPUT) @SuppressWarnings("unused") void propagate(FeedItem feedItem);  }