@Test
public void testRedirectToSame() throws Exception {

    mockWebServer.enqueue(new MockResponse().setResponseCode(301).
            setBody("redirect").setHeader("Location", baseUrl + "/fooey"));
    mockWebServer.enqueue(new MockResponse().setResponseCode(301).
            setBody("redirect").setHeader("Location", baseUrl + "/fooey"));
    mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody("yay!"));
    SimpleUrlConnectionFactory urlFactory = new SimpleUrlConnectionFactory();
    try {
        InputStream inputStream = urlFactory.getStream(Uri.parse(baseUrl.toString()));
        Assert.fail("Redirect to the same URL should fail");
    } catch (IOException e) {
        Assert.assertNotNull(e);
    }
}