FriendsTemplate extends AbstractVKontakteOperations implements FriendsOperations { @Override public List<VKontakteProfile> get() { requireAuthorization(); Properties props = new Properties(); props.put("fields", "uid,first_name,last_name,photo,photo_medium,photo_big,contacts,bdate"); URI uri = URIBuilder.fromUri(makeOperationURL("friends.get", props)).build(); VKontakteProfiles profiles = restTemplate.getForObject(uri, VKontakteProfiles.class); checkForError(profiles); return profiles.getProfiles(); } FriendsTemplate(RestTemplate restTemplate, String accessToken, boolean isAuthorizedForUser); @Override List<VKontakteProfile> get(); @Override List<VKontakteProfile> get(String userId);  }
@Test public void get_currentUser() throws ParseException { mockServer.expect(requestTo("https: .andExpect(method(GET)) .andRespond(withResponse(jsonResource("list-of-profiles"), responseHeaders)); List<VKontakteProfile> friends = vkontakte.friendsOperations().get(); assertFriends(friends); }
@Test(expected = MissingAuthorizationException.class) public void get_currentUser_unauthorized() { unauthorizedVKontakte.friendsOperations().get(); }
@Test public void get_byUserId() throws ParseException { mockServer.expect(requestTo("https: .andExpect(method(GET)) .andRespond(withResponse(jsonResource("list-of-profiles"), responseHeaders)); List<VKontakteProfile> friends = vkontakte.friendsOperations().get("123"); assertFriends(friends); }
@Test(expected = MissingAuthorizationException.class) public void getFriends_byUserId_unauthorized() { unauthorizedVKontakte.friendsOperations().get("123"); }
@Test(expected = VKontakteErrorException.class) public void get_expiredToken() { mockServer.expect(requestTo("https: .andExpect(method(GET)) .andRespond(withResponse(jsonResource("error-code-5"), responseHeaders)); vkontakte.friendsOperations().get("123"); }