JobsResource extends Resource { public CallSpec<List<PartialJob>, HttpError> getJobsRecommendationsForUser(String userId) { return Resource.<List<PartialJob>, HttpError>newGetSpec(api, "/v1/users/{user_id}/jobs/recommendations") .pathParam("user_id", userId) .responseAs(list(PartialJob.class, "job_recommendations", "items")) .build(); } JobsResource(XingApi api); CallSpec<Job, HttpError> getJobById(String jobId); CallSpec<List<PartialJob>, HttpError> getJobsByCriteria(String criteria); CallSpec<List<PartialJob>, HttpError> getJobsRecommendationsForUser(String userId);  }
@Test public void getJobsRecommendations() throws Exception { server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); Response<List<PartialJob>, HttpError> response = resource.getJobsRecommendationsForUser("some_id").execute(); assertThat(response.body().get(0).id()).isEqualTo("61723_4cae01"); assertThat(response.body().get(0).contact().jobCompany().name()).isEqualTo("Rails Heroes"); }
@Test public void getJobsRecommendationsWithPagination() throws Exception { server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); CallSpec<List<PartialJob>, HttpError> spec = resource.getJobsRecommendationsForUser("some_id"); spec.execute(); CallSpec<List<PartialJob>, HttpError> clonedSpec = spec.clone(); Response<List<PartialJob>, HttpError> response = clonedSpec.queryParam("limit", 10) .queryParam("offset", 1) .execute(); assertThat(response.body().get(0).id()).isEqualTo("61723_4cae01"); }
@Test(expected = IllegalStateException.class) public void getJobsRecommendationsReusingCallSpecShouldThrowException() throws Exception { server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); CallSpec<List<PartialJob>, HttpError> spec = resource.getJobsRecommendationsForUser("some_id"); spec.execute(); spec.execute(); }