• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.volley.mock;
18 
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.io.OutputStream;
22 import java.net.HttpURLConnection;
23 import java.net.MalformedURLException;
24 import java.net.URL;
25 
26 public class MockHttpURLConnection extends HttpURLConnection {
27 
28     private boolean mDoOutput;
29     private String mRequestMethod;
30     private OutputStream mOutputStream;
31 
MockHttpURLConnection()32     public MockHttpURLConnection() throws MalformedURLException {
33         super(new URL("http://foo.com"));
34         mDoOutput = false;
35         mRequestMethod = "GET";
36         mOutputStream = new ByteArrayOutputStream();
37     }
38 
39     @Override
setDoOutput(boolean flag)40     public void setDoOutput(boolean flag) {
41         mDoOutput = flag;
42     }
43 
44     @Override
getDoOutput()45     public boolean getDoOutput() {
46         return mDoOutput;
47     }
48 
49     @Override
setRequestMethod(String method)50     public void setRequestMethod(String method) {
51         mRequestMethod = method;
52     }
53 
54     @Override
getRequestMethod()55     public String getRequestMethod() {
56         return mRequestMethod;
57     }
58 
59     @Override
getOutputStream()60     public OutputStream getOutputStream() {
61         return mOutputStream;
62     }
63 
64     @Override
disconnect()65     public void disconnect() {
66     }
67 
68     @Override
usingProxy()69     public boolean usingProxy() {
70         return false;
71     }
72 
73     @Override
connect()74     public void connect() throws IOException {
75     }
76 
77 }
78