@Test public void failedToConnectWithHttpUrl() throws Exception { String urlString = "http: URL url = mock(URL.class); whenNew(URL.class).withAnyArguments().thenReturn(url); when(url.getProtocol()).thenReturn("http"); HttpClient.CallTemplate callTemplate = mock(HttpClient.CallTemplate.class); ServiceCallback serviceCallback = mock(ServiceCallback.class); DefaultHttpClient httpClient = new DefaultHttpClient(); mockCall(); httpClient.callAsync(urlString, "", new HashMap<String, String>(), callTemplate, serviceCallback); verify(serviceCallback).onCallFailed(any(IOException.class)); verifyZeroInteractions(callTemplate); verifyZeroInteractions(serviceCallback); }
@Override public ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, final ServiceCallback serviceCallback) { final DefaultHttpClientCallTask task = new DefaultHttpClientCallTask(url, method, headers, callTemplate, serviceCallback, this, mCompressionEnabled); try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (final RejectedExecutionException e) { HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { serviceCallback.onCallFailed(e); } }); } return new ServiceCall() { @Override public void cancel() { task.cancel(true); } }; }
DefaultHttpClient implements HttpClient, DefaultHttpClientCallTask.Tracker { @Override public ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, final ServiceCallback serviceCallback) { final DefaultHttpClientCallTask task = new DefaultHttpClientCallTask(url, method, headers, callTemplate, serviceCallback, this, mCompressionEnabled); try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (final RejectedExecutionException e) { HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { serviceCallback.onCallFailed(e); } }); } return new ServiceCall() { @Override public void cancel() { task.cancel(true); } }; } }
DefaultHttpClient implements HttpClient, DefaultHttpClientCallTask.Tracker { @Override public ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, final ServiceCallback serviceCallback) { final DefaultHttpClientCallTask task = new DefaultHttpClientCallTask(url, method, headers, callTemplate, serviceCallback, this, mCompressionEnabled); try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (final RejectedExecutionException e) { HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { serviceCallback.onCallFailed(e); } }); } return new ServiceCall() { @Override public void cancel() { task.cancel(true); } }; } DefaultHttpClient();  DefaultHttpClient(boolean compressionEnabled); }
DefaultHttpClient implements HttpClient, DefaultHttpClientCallTask.Tracker { @Override public ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, final ServiceCallback serviceCallback) { final DefaultHttpClientCallTask task = new DefaultHttpClientCallTask(url, method, headers, callTemplate, serviceCallback, this, mCompressionEnabled); try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (final RejectedExecutionException e) { HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { serviceCallback.onCallFailed(e); } }); } return new ServiceCall() { @Override public void cancel() { task.cancel(true); } }; } DefaultHttpClient();  DefaultHttpClient(boolean compressionEnabled); @Override ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, final ServiceCallback serviceCallback); @Override synchronized void onStart(DefaultHttpClientCallTask task); @Override synchronized void onFinish(DefaultHttpClientCallTask task); @Override synchronized void close(); @Override void reopen(); }
DefaultHttpClient implements HttpClient, DefaultHttpClientCallTask.Tracker { @Override public ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, final ServiceCallback serviceCallback) { final DefaultHttpClientCallTask task = new DefaultHttpClientCallTask(url, method, headers, callTemplate, serviceCallback, this, mCompressionEnabled); try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (final RejectedExecutionException e) { HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { serviceCallback.onCallFailed(e); } }); } return new ServiceCall() { @Override public void cancel() { task.cancel(true); } }; } DefaultHttpClient();  DefaultHttpClient(boolean compressionEnabled); @Override ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, final ServiceCallback serviceCallback); @Override synchronized void onStart(DefaultHttpClientCallTask task); @Override synchronized void onFinish(DefaultHttpClientCallTask task); @Override synchronized void close(); @Override void reopen(); static final String METHOD_GET; static final String METHOD_POST; static final String METHOD_DELETE; static final String CONTENT_TYPE_KEY; }