WallTemplate extends AbstractVKontakteOperations implements WallOperations { @Override public String post(String message) { requireAuthorization(); Properties props = new Properties(); props.put("message", message); URI uri = URIBuilder.fromUri(makeOperationURL("wall.post", props)).build(); Posts posts = restTemplate.getForObject(uri, Posts.class); checkForError(posts); return posts.getPost().getPostId(); } WallTemplate(RestTemplate restTemplate, String accessToken, boolean isAuthorizedForUser); @Override String post(String message);  }
@Test public void post() { mockServer.expect(requestTo("https: .andExpect(method(GET)) .andRespond(withResponse(jsonResource("wall-post-response"), responseHeaders)); String postId = vkontakte.wallOperations().post("hello"); assertEquals("511", postId); }
@Test(expected = VKontakteErrorException.class) public void post_expiredToken() { mockServer.expect(requestTo("https: .andExpect(method(GET)) .andRespond(withResponse(jsonResource("error-code-5"), responseHeaders)); vkontakte.wallOperations().post("hello"); }
@Test(expected = MissingAuthorizationException.class) public void post_unauthorized() { unauthorizedVKontakte.wallOperations().post("hello"); }