use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class CronServiceTest method checkCredentialsTestInvalid.
@Test
public void checkCredentialsTestInvalid() throws Exception {
final Principal principal = principal(1L);
when(twitterService.verifyCredentials(principal)).thenReturn(false);
sut.checkCredentials();
verify(userService, times(1)).addEvent(1L, new Event(EventType.INVALID_TWITTER_CREDENTIALS, ""));
verify(userService, times(1)).applyLimit(1L, UserLimitType.CREDENTIALS_INVALID);
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class CronServiceTest method checkCredentialsTest.
@Test
public void checkCredentialsTest() throws Exception {
final Principal principal = principal(1L);
when(twitterService.verifyCredentials(principal)).thenReturn(true);
sut.checkCredentials();
verify(userService, times(1)).resetLimit(1L, UserLimitType.CREDENTIALS_INVALID);
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class PrincipalServiceTest method saveUpdateTest.
@Test
public void saveUpdateTest() {
final Principal u = new Principal(12L, "tokdf", "secrrr");
when(principalRedisTemplate.opsForValue()).thenReturn(valueOperations);
when(longRedisTemplate.opsForSet()).thenReturn(setOperations);
sut.saveUpdate(u);
verify(valueOperations, times(1)).set("12", u);
verify(setOperations, times(1)).add("MEMBERS", 12L);
}
use of com.jeanchampemont.wtfdyum.dto.Principal 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.dto.Principal 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);
}
Aggregations