title: Intercept outgoing HTTP requests
body: <p>so I'm looking for a library or some way of intercepting any outgoing HTTP requests from my Java application? Why? Because I want to unit test an API integration and since I'm using a library (wrapper) for that API, I can't modify any of it's code. It's not my code that's actually making the HTTP requests.</p>
  
  <p>So, I need to intercept them, view them and assert they are correct according to the API's documentation.</p>
  
  <p>I've tried looking online, but I couldn't find the exact thing I'm looking for. Most libraries out there will let me do it, only if I configure the requests themselves properly, but I can't do that, since they're made by an API wrapper, not my code.</p>
  
  <p>Cheers</p>
  
  <p>P.S Some example code</p>
  
  <pre><code>String path = "/some/path";
  String repoOwner = "John Doe";
  String repoName = "John repo"
  
  GitHubClient client = new GitHubClient();
  client.setCredentials(this.username, this.password);
  
  RepositoryService repositoryService = new RepositoryService(client);
  CommitService commitService = new CommitService(client);
  
  Repository repo = repositoryService.getRepository(repoOwner, repoName);
  
  List&lt;RepositoryCommit&gt; commits = commitService.getCommits(repo, null, path);
  </code></pre>
  
  <p>This will use the API wrapper to get all the commits in a given repository. Suppose I wanted to see the HTTP requests this code is making and then I wanted to Unit Test them and assert they are correct. How would I do that? Is there any way to intercept them, catch them kind of like an exception, and do stuff with them, such as assertions?</p>