Skip to content

Commit

Permalink
Merge pull request #434 from Microsoft/develop
Browse files Browse the repository at this point in the history
v0.8.1
  • Loading branch information
guperrot authored May 11, 2017
2 parents 098f421 + 913f0a8 commit e5defad
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {

sSharedPreferences = getSharedPreferences("Sasquatch", Context.MODE_PRIVATE);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().build());

/* Set custom log URL if one was configured in settings. */
String logUrl = sSharedPreferences.getString(LOG_URL_KEY, getString(R.string.log_url));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ private static String dump(HttpURLConnection urlConnection) throws IOException {
stream = urlConnection.getInputStream();
else
stream = urlConnection.getErrorStream();
InputStreamReader in = new InputStreamReader(stream, CHARSET_NAME);
char[] buffer = new char[READ_BUFFER_SIZE];
int len;
while ((len = in.read(buffer)) > 0)
builder.append(buffer, 0, len);
return builder.toString();
try {
InputStreamReader in = new InputStreamReader(stream, CHARSET_NAME);
char[] buffer = new char[READ_BUFFER_SIZE];
int len;
while ((len = in.read(buffer)) > 0)
builder.append(buffer, 0, len);
return builder.toString();
} finally {
stream.close();
}
}

private static String doCall(String urlString, String method, Map<String, String> headers, CallTemplate callTemplate) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
Expand Down Expand Up @@ -186,7 +188,8 @@ public void get200() throws Exception {
when(urlConnection.getResponseCode()).thenReturn(200);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
when(urlConnection.getOutputStream()).thenReturn(buffer);
when(urlConnection.getInputStream()).thenReturn(new ByteArrayInputStream("OK".getBytes()));
ByteArrayInputStream inputStream = spy(new ByteArrayInputStream("OK".getBytes()));
when(urlConnection.getInputStream()).thenReturn(inputStream);

/* Configure API client. */
HttpClient.CallTemplate callTemplate = mock(HttpClient.CallTemplate.class);
Expand All @@ -208,6 +211,7 @@ public void get200() throws Exception {
verify(urlConnection).setRequestProperty("Install-ID", installId.toString());
verify(urlConnection, never()).setDoOutput(true);
verify(urlConnection).disconnect();
verify(inputStream).close();
verify(callTemplate).onBeforeCalling(eq(url), any(Map.class));
verify(callTemplate, never()).buildRequestBody();
httpClient.close();
Expand Down Expand Up @@ -324,6 +328,29 @@ public void failedConnection() throws Exception {
verifyZeroInteractions(serviceCallback);
}

@Test
public void failedToReadResponse() throws Exception {
URL url = mock(URL.class);
whenNew(URL.class).withAnyArguments().thenReturn(url);
IOException exception = new IOException("mock");
HttpURLConnection urlConnection = mock(HttpURLConnection.class);
when(url.openConnection()).thenReturn(urlConnection);
when(urlConnection.getResponseCode()).thenReturn(200);
InputStream inputStream = mock(InputStream.class);
when(urlConnection.getInputStream()).thenReturn(inputStream);
InputStreamReader inputStreamReader = mock(InputStreamReader.class);
whenNew(InputStreamReader.class).withAnyArguments().thenReturn(inputStreamReader);
when(inputStreamReader.read(any(char[].class))).thenThrow(exception);
HttpClient.CallTemplate callTemplate = mock(HttpClient.CallTemplate.class);
ServiceCallback serviceCallback = mock(ServiceCallback.class);
DefaultHttpClient httpClient = new DefaultHttpClient();
mockCall();
httpClient.callAsync("", "", new HashMap<String, String>(), callTemplate, serviceCallback);
verify(serviceCallback).onCallFailed(exception);
verifyZeroInteractions(serviceCallback);
verify(inputStream).close();
}

@Test
public void failedSerialization() throws Exception {

Expand Down
4 changes: 2 additions & 2 deletions versions.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Version constants

ext {
versionCode = 18
versionName = '0.8.0'
versionCode = 19
versionName = '0.8.1'
minSdkVersion = 15
targetSdkVersion = 25
compileSdkVersion = 25
Expand Down

0 comments on commit e5defad

Please sign in to comment.