コード例 #1
0
  @Test
  public void testAsyncTasks() {
    Robolectric.getBackgroundScheduler().pause();

    TestRequest request = new TestRequest();
    api.makeCall(request, responseCallbacks);

    // setting pending http response
    Robolectric.addPendingHttpResponse(200, "Test Response");

    // executing task
    Robolectric.getBackgroundScheduler().runOneTask();

    HttpRequestInfo sentHttpRequestData = Robolectric.getSentHttpRequestInfo(0);
    HttpRequest sentHttpRequest = sentHttpRequestData.getHttpRequest();

    // Testing URL
    assertThat(sentHttpRequest.getRequestLine().getUri(), equalTo("www.disney.com"));

    // Testing Headers
    assertThat(sentHttpRequest.getHeaders("mickey")[0].getValue(), equalTo("mouse"));
  }
コード例 #2
0
  @Before
  public void setUp() throws Exception {

    ShadowLog.stream = System.out;
    transcript = new Transcript();

    context = new Activity();

    ObsDetails obsDetails = ObsDetails.getInstance();
    obsDetails.setCompanyCode("coco");
    obsDetails.setUsername("david");

    final String[] fList = context.fileList();
    boolean configExists = false;
    f =
        new File(
            HttpMessageConverterTest.class.getClassLoader().getResource(TOKEN_FILE_NAME).toURI());
    Assert.assertTrue(f.exists());

    for (String fname : fList) {
      configExists = configExists || TOKEN_FILE_NAME.equals(fname);
    }
    try {

      f =
          new File(
              HttpMessageConverterTest.class.getClassLoader().getResource(TOKEN_FILE_NAME).toURI());
      Assert.assertTrue(f.exists());

      tokenConfiguration = (new TokenConfiguration()).load(f, "lucky13".toCharArray());
      if (tokenConfiguration.getDomains().size() == 0) {
        TokenConfiguration.save(tokenConfiguration, f, "lucky13".toCharArray());
        setupFacade.init();

      } else {
        Logger.debug("Unable to create token Configuration");
      }
    } catch (Exception e) {
      Logger.debug("HomeMenu" + "Exception thrown: " + e.getMessage());
    }

    Robolectric.getBackgroundScheduler().pause();
    Robolectric.getUiThreadScheduler().pause();
  }