@Test public void invalidToken() throws Exception { try { mockServer.expect(requestTo("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,emailAddress,headline,industry,site-standard-profile-request,public-profile-url,picture-url,summary)?format=json&oauth2_access_token=ACCESS_TOKEN")) .andExpect(method(GET)) .andRespond(withStatus(HttpStatus.UNAUTHORIZED).body(jsonResource("error_invalid_token")).contentType(MediaType.APPLICATION_JSON)); linkedIn.profileOperations().getUserProfile(); fail(); } catch (NotAuthorizedException e) { assertEquals("Invalid access token.", e.getMessage()); } }