use of com.jeanchampemont.wtfdyum.dto.User in project WTFDYUM by jchampemont.
the class AbstractFeatureStrategyTest method unfollowers.
protected List<User> unfollowers(final Principal principal, final Set<Long> followersIds, final BiConsumer<OngoingStubbing<Set<Long>>, Set<Long>> l) throws WTFDYUMException {
final Set<Long> unfollowers = new HashSet<>(Arrays.asList(10L, 11L));
l.accept(when(followersService.getUnfollowers(principal.getUserId(), followersIds)), unfollowers);
// unfollowers 10 and 11 details :
final User user10 = new User();
user10.setId(10L);
user10.setScreenName("user10");
final User user11 = new User();
user11.setId(11L);
user11.setScreenName("user11");
when(twitterService.getUsers(principal, 10L, 11L)).thenReturn(Arrays.asList(user10, user11));
return Arrays.asList(user10, user11);
}
use of com.jeanchampemont.wtfdyum.dto.User in project WTFDYUM by jchampemont.
the class TwitterServiceImpl method getUsers.
@Override
public List<User> getUsers(final Principal principal, final long... ids) throws WTFDYUMException {
final List<User> result = new ArrayList<>();
if (ids.length == 0) {
return result;
}
try {
final List<twitter4j.User> users = new ArrayList<>();
for (int i = 0; i <= (ids.length - 1) / 100; i++) {
final ResponseList<twitter4j.User> lookupUsers = twitter(principal).users().lookupUsers(Arrays.copyOfRange(ids, i * 100, Math.min((i + 1) * 100, ids.length)));
users.addAll(lookupUsers);
}
for (final twitter4j.User u : users) {
result.add(mapper.map(u, User.class));
}
} catch (final TwitterException e) {
if (e.getErrorCode() == 17) {
log.debug("Error while getUsers for ids: " + Arrays.toString(ids) + ". Seems like those users are not on twitter anymore.");
} else {
log.debug("Error while getUsers for ids: " + Arrays.toString(ids), e);
throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR);
}
}
return result;
}
use of com.jeanchampemont.wtfdyum.dto.User in project WTFDYUM by jchampemont.
the class TweetUnfollowFeatureStrategy method cron.
@Override
public Set<Event> cron(final Long userId) throws WTFDYUMException {
final Set<Event> result = new HashSet<>();
final Principal principal = principalService.get(userId);
final Set<Long> followers = twitterService.getFollowers(userId, Optional.ofNullable(principal));
final Set<Long> unfollowersId = followersService.getUnfollowers(userId, followers);
final List<User> unfollowers = twitterService.getUsers(principal, Longs.toArray(unfollowersId));
for (final User unfollower : unfollowers) {
result.add(new Event(EventType.UNFOLLOW, unfollower.getScreenName()));
twitterService.tweet(principal, String.format(unfollowTweetText, unfollower.getScreenName()));
}
return result;
}
use of com.jeanchampemont.wtfdyum.dto.User in project WTFDYUM by jchampemont.
the class NotifyUnfollowFeatureStrategyTest method cronTest.
@Test
public void cronTest() throws Exception {
final Principal principal = principal(1L);
final Set<Long> followers = followers(principal, (s, f) -> s.thenReturn(f));
final List<User> unfollowers = unfollowers(principal, followers, (s, u) -> s.thenReturn(u));
final Set<Event> events = sut.cron(1L);
verifyUnfollowDM(principal, unfollowers.get(0));
verifyUnfollowDM(principal, unfollowers.get(1));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(0).getScreenName())));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(1).getScreenName())));
}
use of com.jeanchampemont.wtfdyum.dto.User in project WTFDYUM by jchampemont.
the class TweetUnfollowFeatureStrategyTest method cronTest.
@Test
public void cronTest() throws Exception {
final Principal principal = principal(1L);
final Set<Long> followers = followers(principal, (s, f) -> s.thenReturn(f));
final List<User> unfollowers = unfollowers(principal, followers, (s, u) -> s.thenReturn(u));
final Set<Event> events = sut.cron(1L);
verifyUnfollowTweet(principal, unfollowers.get(0));
verifyUnfollowTweet(principal, unfollowers.get(1));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(0).getScreenName())));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(1).getScreenName())));
}
Aggregations