@Override public void onTweetRemove(Tweet tweet) throws FunctionalException { if (!tweet.isNotification()) { User currentUser = userService.getCurrentUser(); this.userLineRepository.removeTweetFromUserline(currentUser, tweet.getTweetId()); } }
/** GET /users/suggestions -> suggest users to follow */ @RequestMapping( value = "/rest/users/suggestions", method = RequestMethod.GET, produces = "application/json") @ResponseBody public Collection<User> suggestions() { User currentUser = userService.getCurrentUser(); final String login = currentUser.getLogin(); if (log.isDebugEnabled()) { log.debug("REST request to get the last active tweeters list (except " + login + ")."); } Collection<String> exceptions = userService.getFriendsForUser(login); exceptions.add(login); Collection<Tweet> tweets = timelineService.getDayline(""); Map<String, User> users = new HashMap<String, User>(); for (Tweet tweet : tweets) { if (exceptions.contains(tweet.getLogin())) continue; users.put(tweet.getLogin(), userService.getUserProfileByLogin(tweet.getLogin())); if (users.size() == 3) break; // suggestions list limit } return users.values(); }
@Test(expected = ConstraintViolationException.class) public void shouldNotCreateATweetBecauseContentEmpty() { String login = "******"; String content = ""; Tweet tweet = new Tweet(); tweet.setContent(content); tweet.setLogin(login); tweetRepository.createTweet(login, content); }
@Test(expected = ValidationException.class) public void shouldNotCreateATweetBecauseLoginNull() { String login = null; String content = "content"; Tweet tweet = new Tweet(); tweet.setContent(content); tweet.setLogin(login); tweetRepository.createTweet(login, content); }
@Test public void shouldCreateATweet() { String login = "******"; String content = "content"; Tweet tweet = new Tweet(); tweet.setContent(content); tweet.setLogin(login); assertThat(tweetRepository.createTweet(login, content), notNullValue()); }
@Override public void onTweetPost(Tweet tweet) { User currentUser = userService.getCurrentUser(); userLineRepository.addTweetToUserline(currentUser, tweet.getTweetId()); }