Пример #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);
  }
Пример #2
0
 /**
  * It's valid to call exec with a non-string key, but we'd better blow up already before casting a
  * random object to String, or converting it using toString()
  */
 @Test
 public void canceledWhenNonStringKey() throws InterruptedException {
   getter.exec(new Object());
   assertEquals(
       "Getter was not correctly cancelled for non-String url", getter.getStatus(), Task.CANCELED);
 }