aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/xtremelabs/robolectric/shadows/ShadowAndroidHttpClient.java
blob: 184896ab3ab3f1f108a9518291c8f73bb21479b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.xtremelabs.robolectric.shadows;

import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

import android.content.Context;
import android.net.http.AndroidHttpClient;

import java.io.IOException;

@Implements(AndroidHttpClient.class)
public class ShadowAndroidHttpClient {
    @RealObject private AndroidHttpClient client;

    private HttpClient httpClient = new DefaultHttpClient();

    @Implementation
    public static AndroidHttpClient newInstance(String userAgent) {
        return Robolectric.newInstanceOf(AndroidHttpClient.class);
    }

    @Implementation
    public static AndroidHttpClient newInstance(String userAgent, Context context) {
        return Robolectric.newInstanceOf(AndroidHttpClient.class);
    }

    @Implementation
    public HttpParams getParams() {
        return httpClient.getParams();
    }

    @Implementation
    public ClientConnectionManager getConnectionManager() {
        return httpClient.getConnectionManager();
    }

    @Implementation
    public HttpResponse execute(HttpUriRequest httpUriRequest) throws IOException, ClientProtocolException {
        return httpClient.execute(httpUriRequest);
    }

    @Implementation
    public HttpResponse execute(HttpUriRequest httpUriRequest, HttpContext httpContext) throws IOException, ClientProtocolException {
        return httpClient.execute(httpUriRequest, httpContext);
    }

    @Implementation
    public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest) throws IOException, ClientProtocolException {
        return httpClient.execute(httpHost, httpRequest);
    }

    @Implementation
    public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) throws IOException, ClientProtocolException {
        return httpClient.execute(httpHost, httpRequest, httpContext);
    }

    @Implementation
    public <T> T execute(HttpUriRequest httpUriRequest, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
        return httpClient.execute(httpUriRequest, responseHandler);
    }

    @Implementation
    public <T> T execute(HttpUriRequest httpUriRequest, ResponseHandler<? extends T> responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException {
        return httpClient.execute(httpUriRequest, responseHandler, httpContext);
    }

    @Implementation
    public <T> T execute(HttpHost httpHost, HttpRequest httpRequest, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
        return httpClient.execute(httpHost, httpRequest, responseHandler);
    }

    @Implementation
    public <T> T execute(HttpHost httpHost, HttpRequest httpRequest, ResponseHandler<? extends T> responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException {
        return httpClient.execute(httpHost, httpRequest, responseHandler, httpContext);
    }
}