INT-1553 removed ConnectionParser, added tests for Twitter4JTemplate

This commit is contained in:
Oleg Zhurakousky
2010-11-08 12:02:51 -05:00
parent 4aaac0f04b
commit c5b072b2a8
3 changed files with 89 additions and 54 deletions

View File

@@ -15,16 +15,103 @@
*/
package org.springframework.integration.twitter.core;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.integration.test.util.TestUtils;
import twitter4j.Paging;
import twitter4j.StatusUpdate;
import twitter4j.Twitter;
import twitter4j.http.AccessToken;
import twitter4j.http.Authorization;
import twitter4j.http.OAuthAuthorization;
/**
* Validates that all calls are delegated properly top Twitter
*
* @author Oleg Zhurakousky
*
*/
public class Twitter4jTemplateTests {
Twitter4jTemplate template;
Twitter twitter;
@Before
public void prepare() throws Exception{
template = new Twitter4jTemplate();
Field twitterField = Twitter4jTemplate.class.getDeclaredField("twitter");
twitterField.setAccessible(true);
twitter = mock(Twitter.class);
twitterField.set(template, twitter);
}
@Test
public void testOauthConstructor() throws Exception{
template = new Twitter4jTemplate("a", "b", "c", "d");
Twitter twitter = (Twitter) TestUtils.getPropertyValue(template, "twitter");
Authorization auth = twitter.getAuthorization();
assertTrue(twitter.getAuthorization() instanceof OAuthAuthorization);
AccessToken accessToken = ((OAuthAuthorization)auth).getOAuthAccessToken();
assertEquals("c", accessToken.getToken());
assertEquals("d", accessToken.getTokenSecret());
}
@Test
public void testProfileId(){
public void testProfileId() throws Exception{
when(twitter.getScreenName()).thenReturn("kermit");
assertEquals("kermit", template.getProfileId());
}
@Test
public void testRateLimitStatus() throws Exception{
template.getRateLimitStatus();
verify(twitter, times(1)).getRateLimitStatus();
}
@Test
public void testGetDirectMessages() throws Exception{
template.getDirectMessages();
template.getDirectMessages(new Paging());
verify(twitter, times(1)).getDirectMessages();
verify(twitter, times(1)).getDirectMessages(Mockito.any(Paging.class));
}
@Test
public void testGetMentions() throws Exception{
template.getMentions();
template.getMentions(new Paging());
verify(twitter, times(1)).getMentions();
verify(twitter, times(1)).getMentions(Mockito.any(Paging.class));
}
@Test
public void testGetFriendsTimeline() throws Exception{
template.getFriendsTimeline();
template.getFriendsTimeline(new Paging());
verify(twitter, times(1)).getFriendsTimeline();
verify(twitter, times(1)).getFriendsTimeline(Mockito.any(Paging.class));
}
@Test
public void testSendDirectMessage() throws Exception{
template.sendDirectMessage("kermit", "hello");
template.sendDirectMessage(1, "hello");
verify(twitter, times(1)).sendDirectMessage("kermit", "hello");
verify(twitter, times(1)).sendDirectMessage(1, "hello");
}
@Test
public void testUpdateStatus() throws Exception{
StatusUpdate statusUpdate = new StatusUpdate("writing twitter test");
template.updateStatus(statusUpdate);
verify(twitter, times(1)).updateStatus(statusUpdate);
}
}