@Test public void verifyNone() { github.create("netflix", "feign", "velo_at_github", "preposterous hacker"); mockClient.verifyTimes(HttpMethod.POST, "/repos/netflix/feign/contributors", 1); try { mockClient.verifyTimes(HttpMethod.POST, "/repos/netflix/feign/contributors", 0); fail(); } catch (VerificationAssertionError e) { assertThat(e.getMessage(), containsString("Do not wanted")); assertThat(e.getMessage(), containsString("POST")); assertThat(e.getMessage(), containsString("/repos/netflix/feign/contributors")); } try { mockClient.verifyTimes(HttpMethod.POST, "/repos/netflix/feign/contributors", 3); fail(); } catch (VerificationAssertionError e) { assertThat(e.getMessage(), containsString("Wanted")); assertThat(e.getMessage(), containsString("POST")); assertThat(e.getMessage(), containsString("/repos/netflix/feign/contributors")); assertThat(e.getMessage(), containsString("'3'")); assertThat(e.getMessage(), containsString("'1'")); } }
public List<Request> verifyTimes(final HttpMethod method, final String url, final int times) { if (times < 0) { throw new IllegalArgumentException("times must be a non negative number"); } if (times == 0) { verifyNever(method, url); return Collections.emptyList(); } RequestKey requestKey = RequestKey.builder(method, url).build(); if (!requests.containsKey(requestKey)) { throw new VerificationAssertionError("Wanted: '%s' but never invoked! Got: %s", requestKey, requests.keySet()); } List<Request> result = requests.get(requestKey); if (result.size() != times) { throw new VerificationAssertionError("Wanted: '%s' to be invoked: '%s' times but got: '%s'!", requestKey, times, result.size()); } return result; }
MockClient implements Client { public List<Request> verifyTimes(final HttpMethod method, final String url, final int times) { if (times < 0) { throw new IllegalArgumentException("times must be a non negative number"); } if (times == 0) { verifyNever(method, url); return Collections.emptyList(); } RequestKey requestKey = RequestKey.builder(method, url).build(); if (!requests.containsKey(requestKey)) { throw new VerificationAssertionError("Wanted: '%s' but never invoked! Got: %s", requestKey, requests.keySet()); } List<Request> result = requests.get(requestKey); if (result.size() != times) { throw new VerificationAssertionError("Wanted: '%s' to be invoked: '%s' times but got: '%s'!", requestKey, times, result.size()); } return result; } }
MockClient implements Client { public List<Request> verifyTimes(final HttpMethod method, final String url, final int times) { if (times < 0) { throw new IllegalArgumentException("times must be a non negative number"); } if (times == 0) { verifyNever(method, url); return Collections.emptyList(); } RequestKey requestKey = RequestKey.builder(method, url).build(); if (!requests.containsKey(requestKey)) { throw new VerificationAssertionError("Wanted: '%s' but never invoked! Got: %s", requestKey, requests.keySet()); } List<Request> result = requests.get(requestKey); if (result.size() != times) { throw new VerificationAssertionError("Wanted: '%s' to be invoked: '%s' times but got: '%s'!", requestKey, times, result.size()); } return result; } MockClient();  MockClient(boolean sequential); }
MockClient implements Client { public List<Request> verifyTimes(final HttpMethod method, final String url, final int times) { if (times < 0) { throw new IllegalArgumentException("times must be a non negative number"); } if (times == 0) { verifyNever(method, url); return Collections.emptyList(); } RequestKey requestKey = RequestKey.builder(method, url).build(); if (!requests.containsKey(requestKey)) { throw new VerificationAssertionError("Wanted: '%s' but never invoked! Got: %s", requestKey, requests.keySet()); } List<Request> result = requests.get(requestKey); if (result.size() != times) { throw new VerificationAssertionError("Wanted: '%s' to be invoked: '%s' times but got: '%s'!", requestKey, times, result.size()); } return result; } MockClient();  MockClient(boolean sequential); @Override synchronized Response execute(Request request, Request.Options options); MockClient ok(HttpMethod method, String url, InputStream responseBody); MockClient ok(HttpMethod method, String url, String responseBody); MockClient ok(HttpMethod method, String url, byte[] responseBody); MockClient ok(HttpMethod method, String url); MockClient ok(RequestKey requestKey, InputStream responseBody); MockClient ok(RequestKey requestKey, String responseBody); MockClient ok(RequestKey requestKey, byte[] responseBody); MockClient ok(RequestKey requestKey); MockClient add(HttpMethod method, String url, int status, InputStream responseBody); MockClient add(HttpMethod method, String url, int status, String responseBody); MockClient add(HttpMethod method, String url, int status, byte[] responseBody); MockClient add(HttpMethod method, String url, int status); MockClient add(HttpMethod method, String url, Response.Builder response); MockClient add(RequestKey requestKey, int status, InputStream responseBody); MockClient add(RequestKey requestKey, int status, String responseBody); MockClient add(RequestKey requestKey, int status, byte[] responseBody); MockClient add(RequestKey requestKey, int status); MockClient add(RequestKey requestKey, Response.Builder response); @Deprecated MockClient add(HttpMethod method, String url, Response response); MockClient noContent(HttpMethod method, String url); Request verifyOne(HttpMethod method, String url); List<Request> verifyTimes(final HttpMethod method, final String url, final int times); void verifyNever(HttpMethod method, String url); void verifyStatus(); void resetRequests(); }
MockClient implements Client { public List<Request> verifyTimes(final HttpMethod method, final String url, final int times) { if (times < 0) { throw new IllegalArgumentException("times must be a non negative number"); } if (times == 0) { verifyNever(method, url); return Collections.emptyList(); } RequestKey requestKey = RequestKey.builder(method, url).build(); if (!requests.containsKey(requestKey)) { throw new VerificationAssertionError("Wanted: '%s' but never invoked! Got: %s", requestKey, requests.keySet()); } List<Request> result = requests.get(requestKey); if (result.size() != times) { throw new VerificationAssertionError("Wanted: '%s' to be invoked: '%s' times but got: '%s'!", requestKey, times, result.size()); } return result; } MockClient();  MockClient(boolean sequential); @Override synchronized Response execute(Request request, Request.Options options); MockClient ok(HttpMethod method, String url, InputStream responseBody); MockClient ok(HttpMethod method, String url, String responseBody); MockClient ok(HttpMethod method, String url, byte[] responseBody); MockClient ok(HttpMethod method, String url); MockClient ok(RequestKey requestKey, InputStream responseBody); MockClient ok(RequestKey requestKey, String responseBody); MockClient ok(RequestKey requestKey, byte[] responseBody); MockClient ok(RequestKey requestKey); MockClient add(HttpMethod method, String url, int status, InputStream responseBody); MockClient add(HttpMethod method, String url, int status, String responseBody); MockClient add(HttpMethod method, String url, int status, byte[] responseBody); MockClient add(HttpMethod method, String url, int status); MockClient add(HttpMethod method, String url, Response.Builder response); MockClient add(RequestKey requestKey, int status, InputStream responseBody); MockClient add(RequestKey requestKey, int status, String responseBody); MockClient add(RequestKey requestKey, int status, byte[] responseBody); MockClient add(RequestKey requestKey, int status); MockClient add(RequestKey requestKey, Response.Builder response); @Deprecated MockClient add(HttpMethod method, String url, Response response); MockClient noContent(HttpMethod method, String url); Request verifyOne(HttpMethod method, String url); List<Request> verifyTimes(final HttpMethod method, final String url, final int times); void verifyNever(HttpMethod method, String url); void verifyStatus(); void resetRequests();  }