package org.scribe.model; import static org.junit.Assert.*; import org.junit.Assume; import org.junit.Test; import org.scribe.exceptions.OAuthException; import java.io.IOException; import java.net.URL; import java.net.HttpURLConnection; public class TestResponse { @Test public void test() throws IOException { // invalid url try{ Response r = new Response(null); fail(); }catch(NullPointerException npe){} // unknown url try{ Response r = new Response((HttpURLConnection) new URL("http://www.thisisnotanexistingurlxyzsomethingelse.com").openConnection()); fail(); }catch(OAuthException oae){} URL url = new URL("http://www.facebook.com"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); Response r = new Response(conn); assertTrue(r.isSuccessful()); assertTrue(r.getCode() >= 200 && r.getCode() < 400); assertTrue(r.getMessage() != null); assertTrue(r.getBody() != null); assertTrue(r.getStream() != null); assertTrue(r.getHeaders().size() != 0); assertTrue(r.getHeader("Content-Length") != null); } }