Skip to content

Instantly share code, notes, and snippets.

@mneedham
Created July 27, 2013 14:27
Show Gist options
  • Select an option

  • Save mneedham/6095019 to your computer and use it in GitHub Desktop.

Select an option

Save mneedham/6095019 to your computer and use it in GitHub Desktop.
Jersey Client Example
@Test
public void jerseyClientExample() {
Foo foo = new Foo(Client.create());
// some code here to fake the call to google to make it return 200
String result = foo.doSomething();
assertEquals("win", result);
}
class Foo {
private Client httpClient;
public Foo(Client httpClient) {
this.httpClient = httpClient;
}
public String doSomething() {
ClientResponse response = httpClient.resource("http://www.google.com").get(ClientResponse.class);
if(response.getStatus() >= 100 && response.getStatus() < 400) {
return "win";
} else {
return "fail";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment