Пример #1
0
  @Ignore
  @Test
  public void responseCodesIn400RangeAreConsideredBad() throws IOException, InterruptedException {
    final String url = "http://github.com/TantalumMobile";

    /*
     * Setup test
     */
    // Return a unauthorized response code, no response body
    when(platformUtils.getHttpGetConn(eq(url), any(Vector.class), any(Vector.class)))
        .thenReturn(httpConn);
    when(httpConn.getResponseCode()).thenReturn(HttpGetter.HTTP_401_UNAUTHORIZED);
    when(httpConn.getLength()).thenReturn(0L);

    /*
     * Execute
     */
    final Object returnValue = getter.exec(url);

    /*
     * Assert
     */
    verify(httpConn).close();
    assertEquals("Return null when get is unsuccessful", null, returnValue);
    assertEquals(HttpGetter.HTTP_401_UNAUTHORIZED, getter.getResponseCode());
    assertTrue("Task was not correctly cancelled after error", cancelCalled);
  }