package twitter4j; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.FileNotFoundException; import org.junit.Test; import twitter4j.internal.http.HttpResponseCode; public class TestTwitterException { @Test public void testConstructor() { NullPointerException th = new NullPointerException(); TwitterException twitEx = new TwitterException(th); assertNotNull(twitEx); assertFalse(twitEx.isCausedByNetworkIssue()); } @Test public void testConstructor2() { String s = "Hans"; TwitterException twitEx = new TwitterException(s); assertNotNull(twitEx); assertEquals(twitEx.getMessage(), s); } @Test public void testConstructor3() { FileNotFoundException th = new FileNotFoundException(); String s = "Hans"; TwitterException twitEx = new TwitterException(s, th); assertNotNull(twitEx); assertEquals(twitEx.getMessage(), s); assertTrue(twitEx.isCausedByNetworkIssue()); } @Test public void testConstructor4() { NullPointerException th = new NullPointerException(); String s = "Hans"; int statusCode = 23; TwitterException twitEx = new TwitterException(s, th, statusCode); assertNotNull(twitEx); String message = twitEx.getMessage(); assertNotNull(message); assertTrue(message.startsWith(statusCode+"")); assertTrue(message.endsWith(s)); assertEquals(twitEx.getStatusCode(), statusCode); } @Test public void testExceededRateLimitation() { NullPointerException th = new NullPointerException(); String s = "Hans"; int statusCode = 404; TwitterException twitEx = new TwitterException(s, th, statusCode); assertFalse(twitEx.exceededRateLimitation()); assertNull(twitEx.getRateLimitStatus()); assertTrue(twitEx.resourceNotFound()); } @Test public void testExceededRateLimitation2() { NullPointerException th = new NullPointerException(); String s = "Hans"; int statusCode = HttpResponseCode.BAD_REQUEST; TwitterException twitEx = new TwitterException(s, th, statusCode); assertFalse(twitEx.exceededRateLimitation()); assertFalse(twitEx.resourceNotFound()); } @Test public void testExceededRateLimitation3() { NullPointerException th = new NullPointerException(); String s = "Hans"; int statusCode = HttpResponseCode.ENHANCE_YOUR_CLAIM; TwitterException twitEx = new TwitterException(s, th, statusCode); assertTrue(twitEx.exceededRateLimitation()); } @Test public void testExceededRateLimitation4() { NullPointerException th = new NullPointerException(); String s = "Hans"; int statusCode = HttpResponseCode.TOO_MANY_REQUESTS; TwitterException twitEx = new TwitterException(s, th, statusCode); assertTrue(twitEx.exceededRateLimitation()); } }