@Test public void feed() { List<FeedItem> feedItems = Arrays.asList(new FeedItem(USERID, USERNAME, FEEDTEXT, Date.from(LocalDateTime.now().plusDays(1).toInstant(ZoneOffset.UTC))), new FeedItem(USERID, USERNAME, FEEDTEXT + "2")); when(repo.findByUserid(eq(USERID))) .thenReturn(toFuture(feedItems)); when(user.findId(USERNAME)).thenReturn(Single.just(USERID)); 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 size", 2, content.size()); FeedItem item = content.get(0); assertNotNull("null item id", item.getId()); assertEquals("wrong item userid", USERID, item.getUserid()); assertEquals("wrong item username", USERNAME, item.getUsername()); assertEquals("wrong item text", FEEDTEXT, item.getText()); verify(repo).findByUserid(eq(USERID)); 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);  }