use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method verifyCredentialsTestTrue.
@Test
public void verifyCredentialsTestTrue() throws TwitterException {
when(twitter.verifyCredentials()).thenReturn(null);
final boolean result = sut.verifyCredentials(new Principal(12L, "tre", "tr"));
assertThat(result).isTrue();
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getUserTest.
@Test
public void getUserTest() throws Exception {
final User userMock = mock(User.class);
when(twitter.users()).thenReturn(usersResources);
when(usersResources.showUser(123L)).thenReturn(userMock);
when(userMock.getId()).thenReturn(123L);
when(userMock.getName()).thenReturn("name");
when(userMock.getScreenName()).thenReturn("screenName");
when(userMock.getProfileImageURL()).thenReturn("profile img url");
when(userMock.getURL()).thenReturn("user url");
final com.jeanchampemont.wtfdyum.dto.User result = sut.getUser(new Principal(1L, "", ""), 123L);
assertThat(result).isNotNull();
assertThat(result.getId()).isEqualTo(123L);
assertThat(result.getName()).isEqualTo("name");
assertThat(result.getScreenName()).isEqualTo("screenName");
assertThat(result.getProfileImageURL()).isEqualTo("profile img url");
assertThat(result.getURL()).isEqualTo("user url");
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method tweetTestException.
@Test(expected = WTFDYUMException.class)
public void tweetTestException() throws Exception {
when(twitter.updateStatus("my brand new tweet")).thenThrow(new TwitterException(""));
sut.tweet(new Principal(144L, "tok", "toksec"), "my brand new tweet");
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getFollowersTest.
@Test
public void getFollowersTest() throws Exception {
final Optional<Principal> principal = Optional.of(new Principal(123L, "toktok", "secsecret"));
final IDs idsMock = mock(IDs.class);
when(twitter.getFollowersIDs(444L, -1)).thenReturn(idsMock);
final RateLimitStatus rateLimitStatusMock = mock(RateLimitStatus.class);
when(idsMock.getRateLimitStatus()).thenReturn(rateLimitStatusMock);
when(rateLimitStatusMock.getRemaining()).thenReturn(1);
when(idsMock.getIDs()).thenReturn(new long[] { 12L, 34L, 44L, 42L, 42L, 999L });
final Set<Long> followers = sut.getFollowers(444L, principal);
assertThat(followers).isNotNull();
assertThat(followers.contains(12L));
assertThat(followers.contains(34L));
assertThat(followers.contains(44L));
assertThat(followers.contains(42L));
assertThat(followers.contains(999L));
verify(twitter, times(1)).setOAuthAccessToken(new AccessToken("toktok", "secsecret"));
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getUsersMultiplePageTest.
@Test
public void getUsersMultiplePageTest() 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[150];
final long[] first100 = new long[100];
final long[] next50 = new long[50];
final Random rand = new Random();
for (int i = 0; i < 150; i++) {
users.add(userMock);
final long id = rand.nextLong();
when(userMock.getId()).thenReturn(id);
ids[i] = id;
if (i < 100) {
first100[i] = id;
} else {
next50[i - 100] = id;
}
}
final ResponseList<User> first100Users = new ResponseListMockForTest<>();
first100Users.addAll(users.subList(0, 100));
final ResponseList<User> next50Users = new ResponseListMockForTest<>();
next50Users.addAll(users.subList(100, 150));
when(twitter.users()).thenReturn(usersResources);
when(usersResources.lookupUsers(first100)).thenReturn(first100Users);
when(usersResources.lookupUsers(next50)).thenReturn(next50Users);
final List<com.jeanchampemont.wtfdyum.dto.User> result = sut.getUsers(new Principal(1L, "", ""), ids);
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(150);
}
Aggregations