use of com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest 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);
}
use of com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getUsersTwitterExceptionButJustOneUserLookedUpTest.
@Test
public void getUsersTwitterExceptionButJustOneUserLookedUpTest() 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[1];
users.add(userMock);
final long id = new Random().nextLong();
when(userMock.getId()).thenReturn(id);
ids[0] = id;
when(twitter.users()).thenReturn(usersResources);
TwitterException exception = mock(TwitterException.class);
when(exception.getErrorCode()).thenReturn(17);
when(usersResources.lookupUsers(ids)).thenThrow(exception);
List<com.jeanchampemont.wtfdyum.dto.User> result = sut.getUsers(new Principal(1L, "", ""), ids);
assertThat(result).isNotNull().isEmpty();
}
use of com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getUsersTest.
@Test
public void getUsersTest() 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)).thenReturn(users);
final List<com.jeanchampemont.wtfdyum.dto.User> result = sut.getUsers(new Principal(1L, "", ""), ids);
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(100);
}
use of com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest 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);
}
}
Aggregations