Skip to content

Commit

Permalink
android-interop-test: Enable checkstyle; fix violations
Browse files Browse the repository at this point in the history
  • Loading branch information
ejona86 committed May 16, 2016
1 parent 2825361 commit 5a2e5e1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@

package io.grpc.android.integrationtest;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;

import com.google.protobuf.nano.EmptyProtos;
import com.google.protobuf.nano.MessageNano;

import android.os.AsyncTask;
import android.util.Log;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;

import io.grpc.CallOptions;
import io.grpc.ClientCall;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
import io.grpc.StatusRuntimeException;
import io.grpc.android.integrationtest.nano.Messages;
Expand All @@ -59,8 +58,6 @@
import io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse;
import io.grpc.android.integrationtest.nano.TestServiceGrpc;
import io.grpc.android.integrationtest.nano.UnimplementedServiceGrpc;
import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.okhttp.NegotiationType;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.StreamRecorder;

Expand All @@ -76,9 +73,9 @@
/**
* Implementation of the integration tests, as an AsyncTask.
*/
public final class InteropTester extends AsyncTask<Void, Void, String> {
final static String SUCCESS_MESSAGE = "Succeed!!!";
final static String LOG_TAG = "GrpcTest";
final class InteropTester extends AsyncTask<Void, Void, String> {
static final String SUCCESS_MESSAGE = "Succeed!!!";
static final String LOG_TAG = "GrpcTest";

private ManagedChannel channel;
private TestServiceGrpc.TestServiceBlockingStub blockingStub;
Expand Down Expand Up @@ -696,13 +693,6 @@ public void timeoutOnSleepingServer() throws Exception {
io.grpc.Status.fromThrowable(recorder.getError()));
}

public static void assertMessageEquals(MessageNano expected, MessageNano actual) {
if (!MessageNano.messageNanoEquals(expected, actual)) {
assertEquals(expected.toString(), actual.toString());
fail("Messages not equal, but assertEquals didn't throw");
}
}

public static void assertMessageSizeEquals(MessageNano expected, MessageNano actual) {
assertEquals(expected.getSerializedSize(), actual.getSerializedSize());
}
Expand All @@ -714,6 +704,13 @@ private static void assertSuccess(StreamRecorder<?> recorder) {
}
}

public static void assertMessageEquals(MessageNano expected, MessageNano actual) {
if (!MessageNano.messageNanoEquals(expected, actual)) {
assertEquals(expected.toString(), actual.toString());
fail("Messages not equal, but assertEquals didn't throw");
}
}

public static void assertMessageEquals(List<? extends MessageNano> expected,
List<? extends MessageNano> actual) {
if (expected == null || actual == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ private void startTest(String testCase) {
TesterOkHttpChannelBuilder.build(host, port, "foo.test.google.fr", true,
getResources().openRawResource(R.raw.ca), null),
new InteropTester.TestListener() {
@Override public void onPreTest() {
resultText.setText("Testing...");
}

@Override public void onPostTest(String result) {
resultText.setText(result);
enableButtons(true);
}
}).execute();
@Override public void onPreTest() {
resultText.setText("Testing...");
}

@Override public void onPostTest(String result) {
resultText.setText(result);
enableButtons(true);
}
}).execute();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public void onCreate(Bundle args) {
host = args.getString("server_host");
port = Integer.parseInt(args.getString("server_port"));
serverHostOverride = args.getString("server_host_override");
useTls = args.getString("use_tls") != null ?
Boolean.parseBoolean(args.getString("use_tls")) : true;
useTestCa = args.getString("use_test_ca") != null ?
Boolean.parseBoolean(args.getString("use_test_ca")) : false;
useTls = args.getString("use_tls") != null
? Boolean.parseBoolean(args.getString("use_tls")) : true;
useTestCa = args.getString("use_test_ca") != null
? Boolean.parseBoolean(args.getString("use_test_ca")) : false;
androidSocketFactoryTls = args.getString("android_socket_factory_tls");

InputStream testCa = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@

package io.grpc.android.integrationtest;

import com.google.common.base.Preconditions;

import android.annotation.TargetApi;
import android.net.SSLCertificateSocketFactory;
import android.os.Build;
import android.support.annotation.Nullable;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.okhttp.NegotiationType;
import io.grpc.okhttp.OkHttpChannelBuilder;

import java.io.InputStream;
import java.lang.RuntimeException;
import java.lang.reflect.Method;
import java.security.KeyStore;
import java.security.cert.CertificateFactory;
Expand All @@ -59,8 +56,8 @@
/**
* A helper class to create a OkHttp based channel.
*/
public class TesterOkHttpChannelBuilder {
static public ManagedChannel build(String host, int port, @Nullable String serverHostOverride,
class TesterOkHttpChannelBuilder {
public static ManagedChannel build(String host, int port, @Nullable String serverHostOverride,
boolean useTls, @Nullable InputStream testCa, @Nullable String androidSocketFactoryTls) {
ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forAddress(host, port);
if (serverHostOverride != null) {
Expand All @@ -86,7 +83,8 @@ static public ManagedChannel build(String host, int port, @Nullable String serve
return channelBuilder.build();
}

static private SSLSocketFactory getSslSocketFactory(@Nullable InputStream testCa) throws Exception {
private static SSLSocketFactory getSslSocketFactory(@Nullable InputStream testCa)
throws Exception {
if (testCa == null) {
return (SSLSocketFactory) SSLSocketFactory.getDefault();
}
Expand All @@ -97,7 +95,7 @@ static private SSLSocketFactory getSslSocketFactory(@Nullable InputStream testCa
}

@TargetApi(14)
static private SSLCertificateSocketFactory getSslCertificateSocketFactory(
private static SSLCertificateSocketFactory getSslCertificateSocketFactory(
@Nullable InputStream testCa, String androidSocketFatoryTls) throws Exception {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH /* API level 14 */) {
throw new RuntimeException(
Expand Down Expand Up @@ -127,7 +125,7 @@ static private SSLCertificateSocketFactory getSslCertificateSocketFactory(
return factory;
}

static private TrustManager[] getTrustManagers(InputStream testCa) throws Exception {
private static TrustManager[] getTrustManagers(InputStream testCa) throws Exception {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Expand Down
31 changes: 31 additions & 0 deletions android-interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,34 @@ allprojects {
jcenter()
}
}

subprojects {
apply plugin: "checkstyle"

checkstyle {
configFile = file("$rootDir/../checkstyle.xml")
toolVersion = "6.17"
ignoreFailures = false
if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
}
configProperties["rootDir"] = "$rootDir/../"
}

// Checkstyle doesn't run automatically with android
task checkStyleMain(type: Checkstyle) {
source 'src/main/java'
include '**/*.java'
classpath = files()
}

task checkStyleTest(type: Checkstyle) {
source 'src/test/java'
include '**/*.java'
classpath = files()
}

afterEvaluate { project ->
project.tasks['check'].dependsOn checkStyleMain, checkStyleTest
}
}

0 comments on commit 5a2e5e1

Please sign in to comment.