Skip to content

Commit

Permalink
Merge pull request #50 from bangarharshit/inspect-cleanup
Browse files Browse the repository at this point in the history
Various Inspections cleanup from android studio
  • Loading branch information
anirudhramanan authored Oct 16, 2018
2 parents b62e8b0 + 0f6fdd0 commit 9fc5b2f
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 61 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/circle/android/api/OkHttp3Stack.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public OkHttp3Stack(OkHttpClient okHttpClient) {
this.mClient = okHttpClient;
}

private static HttpEntity entityFromOkHttpResponse(Response r) throws IOException {
private static HttpEntity entityFromOkHttpResponse(Response r) {
BasicHttpEntity entity = new BasicHttpEntity();
ResponseBody body = r.body();

Expand All @@ -84,7 +84,7 @@ private static HttpEntity entityFromOkHttpResponse(Response r) throws IOExceptio

@SuppressWarnings("deprecation")
private static void setConnectionParametersForRequest(okhttp3.Request.Builder builder, com.android.volley.Request<?> request)
throws IOException, AuthFailureError {
throws AuthFailureError {
switch (request.getMethod()) {
case Request.Method.DEPRECATED_GET_OR_POST:
// Ensure backwards compatibility. Volley assumes a request with a null body is a GET.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

onResponseReceived = new OnResponseReceived();
Expand All @@ -81,10 +81,10 @@ protected void onCreate(Bundle savedInstanceState) {

okHttp3Stack = new OkHttp3Stack(okHttpClient);

final NetworkImageView networkImageView = (NetworkImageView) findViewById(R.id.img);
final NetworkImageView networkImageView = findViewById(R.id.img);
assert networkImageView != null;

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
FloatingActionButton fab = findViewById(R.id.fab);
assert fab != null;
fab.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class NetworkInterceptor implements Interceptor {

private final NetworkInterpreter mInterpreter;
private final AtomicInteger mNextRequestId = new AtomicInteger(1);
private boolean mEnabled = true;
private final boolean mEnabled;

NetworkInterceptor(Builder builder) {
mEnabled = builder.mEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class ForwardingResponse implements OnResponseListener {

private OnStatusCodeAwareResponseListener mOnStatusCodeAwareResponseListener;
private final OnStatusCodeAwareResponseListener mOnStatusCodeAwareResponseListener;


public ForwardingResponse(OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public class PersistentStatsHandler implements NetworkRequestStatsHandler {
private static final String MOBILE_NETWORK = "mobile";
private static final String UNKNOWN_NETWORK = "unknown";
private final PreferenceManager mPreferenceManager;
Set<OnResponseListener> mOnResponseListeners = new HashSet<>();
final Set<OnResponseListener> mOnResponseListeners = new HashSet<>();
private int mResponseCount = 0;
private int MAX_SIZE;
private WifiManager mWifiManager;
private NetworkStat mNetworkStat;
private float mCurrentAvgSpeed = 0;
private ConnectivityManager mConnectivityManager;
private final WifiManager mWifiManager;
private final NetworkStat mNetworkStat;
private float mCurrentAvgSpeed;
private final ConnectivityManager mConnectivityManager;

public PersistentStatsHandler(Context context) {
this.mPreferenceManager = new PreferenceManager(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
public class DefaultInterpreter implements NetworkInterpreter {
private static final String HOST_NAME = "HOST";
private static final String CONTENT_LENGTH = "Content-Length";
NetworkEventReporter mEventReporter;
final NetworkEventReporter mEventReporter;

public DefaultInterpreter(NetworkEventReporter mEventReporter) {
this.mEventReporter = mEventReporter;
}

@Override
public Response interpretResponseStream(int requestId, NetworkInterceptor.TimeInfo timeInfo, Request request, Response response) throws IOException {
public Response interpretResponseStream(int requestId, NetworkInterceptor.TimeInfo timeInfo, Request request, Response response) {
ResponseBody responseBody = response.body();

final OkHttpInspectorRequest okHttpInspectorRequest = new OkHttpInspectorRequest(requestId, request.url().url(), request.method(), Utils.contentLength(request.headers()), request.url().host(), request.body());
Expand Down Expand Up @@ -162,12 +162,12 @@ public String hostName() {
* Implementation of {@link NetworkEventReporter.InspectorResponse}
*/
static class OkHttpInspectorResponse implements NetworkEventReporter.InspectorResponse {
int mRequestId;
long mStartTime;
long mEndTime;
int mStatusCode;
final int mRequestId;
final long mStartTime;
final long mEndTime;
final int mStatusCode;
long mResponseSize;
@Nullable
@Nullable final
ResponseBody responseBody;

OkHttpInspectorResponse(int requestId, int statusCode, long responseSize, long startTime, long endTime, @Nullable ResponseBody responseBody) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface NetworkInterpreter {
* @return Response
* @throws IOException
*/
Response interpretResponseStream(int requestId, NetworkInterceptor.TimeInfo timeInfo, Request request, Response response) throws IOException;
Response interpretResponseStream(int requestId, NetworkInterceptor.TimeInfo timeInfo, Request request, Response response);

/**
* Interpre the error received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class NetworkEventReporterImpl implements NetworkEventReporter {

private NetworkRequestStatsHandler mNetworkRequestStatsHandler;
private final NetworkRequestStatsHandler mNetworkRequestStatsHandler;

public NetworkEventReporterImpl(NetworkRequestStatsHandler networkRequestStatsHandler) {
this.mNetworkRequestStatsHandler = networkRequestStatsHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private synchronized int checkEOF(int n) {
}

@Override
public int read() throws IOException {
public int read() {
try {
int result = checkEOF(in.read());
if (result != -1) {
Expand All @@ -65,7 +65,7 @@ public int read(@NonNull byte[] b) throws IOException {
}

@Override
public int read(@NonNull byte[] b, int off, int len) throws IOException {
public int read(@NonNull byte[] b, int off, int len) {
try {
int result = checkEOF(in.read(b, off, len));
if (result != -1) {
Expand All @@ -84,7 +84,7 @@ public boolean markSupported() {
}

@Override
public void reset() throws IOException {
public void reset() {
throw new UnsupportedOperationException("Mark not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class NetworkStat {

private static final int MAX_QUEUE_SIZE = 5;
private double mPeakSpeed = 0;
private Queue<RequestStats> mRequestStatQueue;
private final Queue<RequestStats> mRequestStatQueue;
private double mTotalSize = 0;
public double mCurrentAvgSpeed = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ForwardingResponseTest {
* @throws Exception
*/
@Test
public void testOnResponseServerSuccessCalledFor2XX3XX() throws Exception {
public void testOnResponseServerSuccessCalledFor2XX3XX() {
OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener = mock(OnStatusCodeAwareResponseListener.class);
ForwardingResponse forwardingResponse = new ForwardingResponse(onStatusCodeAwareResponseListener);

Expand Down Expand Up @@ -80,7 +80,7 @@ public void testOnResponseServerSuccessCalledFor2XX3XX() throws Exception {
* @throws Exception
*/
@Test
public void testOnResponseServerErrorCalledFor4XX5XX() throws Exception {
public void testOnResponseServerErrorCalledFor4XX5XX() {
OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener = mock(OnStatusCodeAwareResponseListener.class);
ForwardingResponse forwardingResponse = new ForwardingResponse(onStatusCodeAwareResponseListener);

Expand Down Expand Up @@ -134,7 +134,7 @@ public void testOnResponseServerErrorCalledFor4XX5XX() throws Exception {
* @throws Exception
*/
@Test
public void testOnResponseNetworkErrorCalledForNetworkErrors() throws Exception {
public void testOnResponseNetworkErrorCalledForNetworkErrors() {
OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener = mock(OnStatusCodeAwareResponseListener.class);
ForwardingResponse forwardingResponse = new ForwardingResponse(onStatusCodeAwareResponseListener);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.flipkart.okhttpstats.BuildConfig;
import com.flipkart.okhttpstats.model.RequestStats;
import com.flipkart.okhttpstats.toolbox.PreferenceManager;

import java.io.IOException;
import java.net.SocketTimeoutException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,9 +18,6 @@
import org.robolectric.shadows.ShadowConnectivityManager;
import org.robolectric.shadows.ShadowNetworkInfo;

import java.io.IOException;
import java.net.SocketTimeoutException;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyFloat;
import static org.mockito.Matchers.anyString;
Expand All @@ -29,7 +26,6 @@
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* Created by anirudh.r on 13/05/16 at 12:28 AM.
Expand All @@ -45,7 +41,7 @@ public class PersistentStatsHandlerTest {
* @throws Exception
*/
@Test
public void testAddListener() throws Exception {
public void testAddListener() {
ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE);
ShadowConnectivityManager shadowConnectivityManager = (ShadowConnectivityManager) ShadowExtractor.extract(connectivityManager);
ShadowNetworkInfo shadowOfActiveNetworkInfo = (ShadowNetworkInfo) ShadowExtractor.extract(connectivityManager.getActiveNetworkInfo());
Expand All @@ -68,7 +64,7 @@ public void testAddListener() throws Exception {
* @throws Exception
*/
@Test
public void testRemoveListener() throws Exception {
public void testRemoveListener() {
OnResponseListener onResponseListener = mock(OnResponseListener.class);

PersistentStatsHandler persistentStatsHandler = new PersistentStatsHandler(RuntimeEnvironment.application);
Expand All @@ -88,7 +84,7 @@ public void testRemoveListener() throws Exception {
* @throws Exception
*/
@Test
public void testOnResponseReceived() throws Exception {
public void testOnResponseReceived() {
OnResponseListener onResponseListener = mock(OnResponseListener.class);
OnResponseListener onResponseListener1 = mock(OnResponseListener.class);

Expand Down Expand Up @@ -124,7 +120,7 @@ public void testOnResponseReceived() throws Exception {
* @throws Exception
*/
@Test
public void testOnHttpExchangeError() throws Exception {
public void testOnHttpExchangeError() {
OnResponseListener onResponseListener = mock(OnResponseListener.class);
OnResponseListener onResponseListener1 = mock(OnResponseListener.class);

Expand Down Expand Up @@ -158,7 +154,7 @@ public void testOnHttpExchangeError() throws Exception {
* @throws Exception
*/
@Test
public void testOnInputStreamError() throws Exception {
public void testOnInputStreamError() {
OnResponseListener onResponseListener = mock(OnResponseListener.class);
OnResponseListener onResponseListener1 = mock(OnResponseListener.class);

Expand Down Expand Up @@ -187,7 +183,7 @@ public void testOnInputStreamError() throws Exception {
* @throws Exception
*/
@Test
public void testGetWifiSSID() throws Exception {
public void testGetWifiSSID() {
ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE);
ShadowConnectivityManager shadowConnectivityManager = (ShadowConnectivityManager) ShadowExtractor.extract(connectivityManager);
ShadowNetworkInfo shadowOfActiveNetworkInfo = (ShadowNetworkInfo) ShadowExtractor.extract(connectivityManager.getActiveNetworkInfo());
Expand All @@ -205,7 +201,7 @@ public void testGetWifiSSID() throws Exception {
* @throws Exception
*/
@Test
public void testGetNetworkKey() throws Exception {
public void testGetNetworkKey() {
ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE);
ShadowConnectivityManager shadowConnectivityManager = (ShadowConnectivityManager) ShadowExtractor.extract(connectivityManager);
shadowConnectivityManager.setNetworkInfo(ConnectivityManager.TYPE_WIFI, connectivityManager.getActiveNetworkInfo());
Expand All @@ -221,7 +217,7 @@ public void testGetNetworkKey() throws Exception {
* @throws Exception
*/
@Test
public void testSaveToSharedPreferenceCalled() throws Exception {
public void testSaveToSharedPreferenceCalled() {
PreferenceManager preferenceManager = mock(PreferenceManager.class);

PersistentStatsHandler persistentStatsHandler = new PersistentStatsHandler(RuntimeEnvironment.application, preferenceManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PreferenceManagerTest {
* @throws Exception
*/
@Test
public void testSharedPreference() throws Exception {
public void testSharedPreference() {

PreferenceManager preferenceManager = new PreferenceManager(RuntimeEnvironment.application);

Expand All @@ -50,7 +50,7 @@ public void testSharedPreference() throws Exception {
* @throws Exception
*/
@Test
public void testSharedPrefForDiffNetwork() throws Exception {
public void testSharedPrefForDiffNetwork() {
PreferenceManager preferenceManager = new PreferenceManager(RuntimeEnvironment.application);
PersistentStatsHandler persistentStatsHandler = new PersistentStatsHandler(RuntimeEnvironment.application);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testResponseReceivedCalledForEventReporter() throws Exception {
* @throws Exception
*/
@Test
public void testOnHttpExchangeErrorGetsCalled() throws Exception {
public void testOnHttpExchangeErrorGetsCalled() {
NetworkEventReporter networkEventReporter = mock(NetworkEventReporter.class);
DefaultInterpreter defaultInterpreter = new DefaultInterpreter(networkEventReporter);

Expand All @@ -92,7 +92,7 @@ public void testOnHttpExchangeErrorGetsCalled() throws Exception {
* Tests setter and getter of {@link com.flipkart.okhttpstats.interpreter.DefaultInterpreter.OkHttpInspectorRequest}
*/
@Test
public void testOkHttpInspectorRequest() throws Exception {
public void testOkHttpInspectorRequest() {

String requestText = "Test Request";

Expand Down Expand Up @@ -121,7 +121,7 @@ public void testOkHttpInspectorRequest() throws Exception {
* Tests setter and getter of {@link com.flipkart.okhttpstats.interpreter.DefaultInterpreter.OkHttpInspectorResponse}
*/
@Test
public void testOkHttpInspectorResponse() throws Exception {
public void testOkHttpInspectorResponse() {

ResponseBody responseBody = mock(ResponseBody.class);
DefaultInterpreter.OkHttpInspectorResponse okHttpInspectorResponse = new DefaultInterpreter.OkHttpInspectorResponse(1, 200, 20, 2, 3, responseBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static byte[] compress(byte[] data) throws IOException {
* @throws Exception
*/
@Test(expected = IllegalStateException.class)
public void testIfExceptionThrownIfInterpreterNull() throws Exception {
public void testIfExceptionThrownIfInterpreterNull() {
new NetworkInterceptor.Builder()
.setEnabled(true)
.setNetworkInterpreter(null)
Expand Down Expand Up @@ -304,7 +304,7 @@ public void testResponseWithoutContentLength() throws IOException {
* Tests setter and getter of {@link com.flipkart.okhttpstats.interpreter.DefaultInterpreter.OkHttpInspectorRequest}
*/
@Test
public void testOkHttpInspectorRequest() throws Exception {
public void testOkHttpInspectorRequest() {

Uri requestUri = Uri.parse("http://www.flipkart.com");
String requestText = "Test Request";
Expand Down Expand Up @@ -334,7 +334,7 @@ public void testOkHttpInspectorRequest() throws Exception {
* Tests setter and getter of {@link com.flipkart.okhttpstats.interpreter.DefaultInterpreter.OkHttpInspectorResponse}
*/
@Test
public void testOkHttpInspectorResponse() throws Exception {
public void testOkHttpInspectorResponse() {

DefaultInterpreter.OkHttpInspectorResponse okHttpInspectorResponse = new DefaultInterpreter.OkHttpInspectorResponse(1, 200, 20, 2, 3, mock(ResponseBody.class));

Expand Down Expand Up @@ -369,7 +369,7 @@ public Request request() {
}

@Override
public Response proceed(Request request) throws IOException {
public Response proceed(Request request) {
if (mRequest != request) {
throw new IllegalArgumentException(
"Expected " + System.identityHashCode(mRequest) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class RequestStatsTest {
public void testDataIntegrity() throws MalformedURLException {
RequestStats requestStats = new RequestStats(1);

NetworkInfo networkInfo = mock(NetworkInfo.class);

requestStats.url = new URL("http://www.flipkart.com");
requestStats.requestSize = 20;
requestStats.methodType = "POST";
Expand Down
Loading

0 comments on commit 9fc5b2f

Please sign in to comment.