-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup infrastructure for mockingWhisperNConnection
Co-authored-by: Samantha Prestrelski <sprestrelski@users.noreply.github.com>
- Loading branch information
1 parent
545508c
commit ede6d35
Showing
9 changed files
with
166 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/code/client/Model/CustomHttpConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package code.client.Model; | ||
|
||
import java.net.ProtocolException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public interface CustomHttpConnection { | ||
int getResponseCode() throws IOException; | ||
|
||
InputStream getInputStream() throws IOException; | ||
|
||
OutputStream getOutputStream() throws IOException; | ||
|
||
InputStream getErrorStream() throws IOException; | ||
|
||
void setRequestMethod(String method) throws ProtocolException; | ||
|
||
void setRequestProperty(String key, String value); | ||
|
||
void setDoOutput(boolean output); | ||
|
||
void disconnect(); | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/code/client/Model/MockHttpConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package code.client.Model; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class MockHttpConnection implements CustomHttpConnection { | ||
private int responseCode; | ||
private InputStream inputStream; | ||
private OutputStream outputStream; | ||
|
||
public MockHttpConnection(int responseCode, InputStream inputStream, OutputStream outputStream) { | ||
this.responseCode = responseCode; | ||
this.inputStream = inputStream; | ||
this.outputStream = outputStream; | ||
} | ||
|
||
@Override | ||
public int getResponseCode() throws IOException { | ||
return responseCode; | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() { | ||
return inputStream; | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() { | ||
return outputStream; | ||
} | ||
|
||
@Override | ||
public InputStream getErrorStream() { | ||
return inputStream; | ||
} | ||
|
||
@Override | ||
public void setRequestMethod(String method) { | ||
} | ||
|
||
@Override | ||
public void setRequestProperty(String key, String value) { | ||
|
||
} | ||
|
||
@Override | ||
public void setDoOutput(boolean output) { | ||
} | ||
|
||
@Override | ||
public void disconnect() { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
app/src/main/java/code/client/Model/RealHttpConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package code.client.Model; | ||
|
||
import java.net.HttpURLConnection; | ||
import java.net.ProtocolException; | ||
import java.net.URL; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class RealHttpConnection implements CustomHttpConnection { | ||
private HttpURLConnection connection; | ||
|
||
public RealHttpConnection(String API_ENDPOINT) | ||
throws URISyntaxException, IOException { | ||
URL url = new URI(API_ENDPOINT).toURL(); | ||
this.connection = (HttpURLConnection) url.openConnection(); | ||
} | ||
|
||
@Override | ||
public int getResponseCode() throws IOException { | ||
return connection.getResponseCode(); | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() throws IOException { | ||
return connection.getInputStream(); | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() throws IOException { | ||
return connection.getOutputStream(); | ||
} | ||
|
||
@Override | ||
public InputStream getErrorStream() throws IOException { | ||
return connection.getErrorStream(); | ||
} | ||
|
||
@Override | ||
public void setRequestMethod(String method) throws ProtocolException { | ||
connection.setRequestMethod(method); | ||
} | ||
|
||
@Override | ||
public void setRequestProperty(String key, String value) { | ||
connection.setRequestProperty(key, value); | ||
} | ||
|
||
@Override | ||
public void setDoOutput(boolean output) { | ||
connection.setDoOutput(output); | ||
} | ||
|
||
@Override | ||
public void disconnect() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters