title: Mocking Jersey Client
body: <p>I am trying to mock the Jeresy webservice call. I have stubbed the WebService.Resource get() method. I am getting the ClientHandlerException. Looks like its calling the real method instead of the stub. Am I missing something in the way the method is stubbed?</p>
  <p>when(webResourceBuilderMock.get(ClientResponse.class)).thenReturn(clientResponseMock );</p>
  <p>Exception:
  Embedded exception: Wrapped Exception Class -&gt; class com.sun.jersey.api.client.ClientHandlerException
  com.sun.jersey.api.client.ClientHandlerException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
  at com.sun.jersey.api.client.filter.LoggingFilter.handle(LoggingFilter.java:217)
  at com.sun.jersey.api.client.Client.handle(Client.java:652)
  at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
  at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
  at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509)
  at xxx.xx.xx.xx.xxx.xxxx.WebServiceClientImpl1.getCreditCardDetails(WebServiceClientImpl1.java:173)
  at xxx.xx.xx.xx.xxx.xxxx.WebServiceClientTest.testAWebServiceClient(WebServiceClientTest.java:121)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.jav</p>
  <p>WebServiceClientImpl.java</p>
  <pre><code>            String wsURL = appendResorcePath(&quot;/xx/xx/xx/&quot; + id + &quot;/xxx&quot;);
              ObjectMapper objectMapper = new ObjectMapper();
              ClientConfig clientConfig = new DefaultClientConfig();
              clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
              Client restClient = Client.create(clientConfig);
              WebResource webResource = restClient.resource(wsURL);
              restClient.addFilter(new com.sun.jersey.api.client.filter.LoggingFilter(printStream));
              WebResource.Builder webResourceBuilder = webResource.accept(MediaType.APPLICATION_JSON);
              webResourceBuilder = webResourceBuilder.header(Constants.AUTHORIZATION, Constants.BASIC + createAuthString()).type(MediaType.APPLICATION_JSON_TYPE);
              clientResp = webResourceBuilder.get(ClientResponse.class);
              
              
  </code></pre>
  <p>Test Class Code:</p>
  <pre><code>    WebResource webResourceMock = Mockito.mock(WebResource.class);
      WebResource.Builder webResourceBuilderMock = Mockito.mock(WebResource.Builder.class);
      ClientResponse clientResponseMock = Mockito.mock(ClientResponse.class);
      clientResponseMock.setStatus(200);
      ObjectMapper objectMapperMock = Mockito.mock(ObjectMapper.class);
      
      when(webResourceMock.accept(MediaType.APPLICATION_JSON)).thenReturn(webResourceBuilderMock);
      when(webResourceBuilderMock.header(ArgumentMatchers.anyString(),ArgumentMatchers.anyString())).thenReturn(webResourceBuilderMock);
      when(webResourceBuilderMock.get(ClientResponse.class)).thenReturn(clientResponseMock );
              
  </code></pre>