use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getUserTestException.
@Test(expected = WTFDYUMException.class)
public void getUserTestException() throws Exception {
when(twitter.users()).thenReturn(usersResources);
when(usersResources.showUser(123L)).thenThrow(new TwitterException("msg"));
sut.getUser(new Principal(1L, "", ""), 123L);
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getUsersTwitterExceptionTest.
@Test
public void getUsersTwitterExceptionTest() throws Exception {
final User userMock = mock(User.class);
when(userMock.getName()).thenReturn("name");
when(userMock.getScreenName()).thenReturn("screenName");
when(userMock.getProfileImageURL()).thenReturn("profile img url");
when(userMock.getURL()).thenReturn("user url");
final ResponseList<User> users = new ResponseListMockForTest<User>();
final long[] ids = new long[100];
final Random rand = new Random();
for (int i = 0; i < 100; i++) {
users.add(userMock);
final long id = rand.nextLong();
when(userMock.getId()).thenReturn(id);
ids[i] = id;
}
when(twitter.users()).thenReturn(usersResources);
when(usersResources.lookupUsers(ids)).thenThrow(TwitterException.class);
try {
sut.getUsers(new Principal(1L, "", ""), ids);
Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
} catch (WTFDYUMException e) {
assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
}
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method sendDirectMessageTest.
@Test
public void sendDirectMessageTest() throws Exception {
final Principal principal = new Principal(123L, "toktok", "secsecret");
sut.sendDirectMessage(principal, 555L, "text");
verify(twitter, times(1)).sendDirectMessage(555L, "text");
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method sendDirectMessageTestException.
@Test
public void sendDirectMessageTestException() throws Exception {
when(twitter.sendDirectMessage(444L, "text")).thenThrow(new TwitterException("msg"));
try {
sut.sendDirectMessage(new Principal(412L, "", ""), 444L, "text");
Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
} catch (final WTFDYUMException e) {
assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
}
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getFollowersMultiplePageTest.
@Test
public void getFollowersMultiplePageTest() throws Exception {
final Optional<Principal> principal = Optional.of(new Principal(123L, "toktok", "secsecret"));
final IDs firstPageMock = mock(IDs.class);
final IDs secondPageMock = mock(IDs.class);
final RateLimitStatus firstPageRateLimitMock = mock(RateLimitStatus.class);
when(firstPageRateLimitMock.getRemaining()).thenReturn(1);
when(firstPageMock.getRateLimitStatus()).thenReturn(firstPageRateLimitMock);
when(firstPageMock.hasNext()).thenReturn(true);
when(firstPageMock.getIDs()).thenReturn(new long[] { 12L, 34L, 44L, 42L, 42L, 999L });
when(firstPageMock.getNextCursor()).thenReturn(42L);
final RateLimitStatus secondPageRateLimitMock = mock(RateLimitStatus.class);
when(secondPageRateLimitMock.getRemaining()).thenReturn(0);
when(secondPageMock.getRateLimitStatus()).thenReturn(secondPageRateLimitMock);
when(secondPageMock.hasNext()).thenReturn(false);
when(secondPageMock.getIDs()).thenReturn(new long[] { 1001L, 1002L, 1003L });
when(twitter.getFollowersIDs(444L, -1)).thenReturn(firstPageMock);
when(twitter.getFollowersIDs(444L, 42)).thenReturn(secondPageMock);
final Set<Long> followers = sut.getFollowers(444L, principal);
assertThat(followers).isNotNull();
assertThat(followers).containsOnly(12L, 34L, 44L, 42L, 999L, 1001L, 1002L, 1003L);
verify(twitter, times(1)).setOAuthAccessToken(new AccessToken("toktok", "secsecret"));
}
Aggregations