mirror of https://github.com/grpc/grpc-java.git
android-interop-test: Enable checkstyle; fix violations
This commit is contained in:
parent
2825361767
commit
5a2e5e16a2
|
|
@ -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;
|
||||
|
|
@ -59,8 +58,6 @@ import io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest;
|
|||
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;
|
||||
|
||||
|
|
@ -76,9 +73,9 @@ import java.util.concurrent.TimeUnit;
|
|||
/**
|
||||
* 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;
|
||||
|
|
@ -696,13 +693,6 @@ public final class InteropTester extends AsyncTask<Void, Void, String> {
|
|||
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());
|
||||
}
|
||||
|
|
@ -714,6 +704,13 @@ public final class InteropTester extends AsyncTask<Void, Void, String> {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -114,15 +114,15 @@ public class TesterActivity extends AppCompatActivity
|
|||
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 onPreTest() {
|
||||
resultText.setText("Testing...");
|
||||
}
|
||||
|
||||
@Override public void onPostTest(String result) {
|
||||
resultText.setText(result);
|
||||
enableButtons(true);
|
||||
}
|
||||
}).execute();
|
||||
@Override public void onPostTest(String result) {
|
||||
resultText.setText(result);
|
||||
enableButtons(true);
|
||||
}
|
||||
}).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ public class TesterInstrumentation extends Instrumentation {
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@
|
|||
|
||||
package io.grpc.android.integrationtest;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.net.SSLCertificateSocketFactory;
|
||||
import android.os.Build;
|
||||
|
|
@ -40,11 +38,10 @@ 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;
|
||||
|
|
@ -59,8 +56,8 @@ import javax.security.auth.x500.X500Principal;
|
|||
/**
|
||||
* 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) {
|
||||
|
|
@ -86,7 +83,8 @@ public class TesterOkHttpChannelBuilder {
|
|||
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();
|
||||
}
|
||||
|
|
@ -97,7 +95,7 @@ public class TesterOkHttpChannelBuilder {
|
|||
}
|
||||
|
||||
@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(
|
||||
|
|
@ -127,7 +125,7 @@ public class TesterOkHttpChannelBuilder {
|
|||
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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue