コード例 #1
0
 @Test(expected = MissingAuthorizationException.class)
 public void currentUser_noAccessToken() {
   FacebookTemplate facebook =
       new FacebookTemplate(); // use anonymous FacebookTemplate in this test
   MockRestServiceServer mockServer =
       MockRestServiceServer.createServer(facebook.getRestTemplate());
   mockServer
       .expect(requestTo("https://graph.facebook.com/me"))
       .andExpect(method(GET))
       .andRespond(
           withBadRequest()
               .body(jsonResource("testdata/error-current-user-no-token"))
               .contentType(MediaType.APPLICATION_JSON));
   facebook.userOperations().getUserProfile();
 }
コード例 #2
0
 @Test(expected = UncategorizedApiException.class)
 public void htmlErrorResponse() {
   try {
     FacebookTemplate facebook =
         new FacebookTemplate(); // use anonymous FacebookTemplate in this test
     MockRestServiceServer mockServer =
         MockRestServiceServer.createServer(facebook.getRestTemplate());
     mockServer
         .expect(requestTo("https://graph.facebook.com/123456/picture?type=normal"))
         .andExpect(method(GET))
         .andRespond(
             withBadRequest()
                 .body(new ClassPathResource("testdata/error-not-json.html", getClass()))
                 .contentType(MediaType.TEXT_HTML));
     facebook.userOperations().getUserProfileImage("123456");
     fail("Expected UncategorizedApiException");
   } catch (UncategorizedApiException e) {
     assertTrue(e.getCause() instanceof HttpClientErrorException);
     throw e;
   }
 }