From 8de2605b4000ec7aff8bfaa0a354f5f9c54b06e1 Mon Sep 17 00:00:00 2001 From: Philipp Kern Date: Wed, 26 Aug 2020 10:15:44 +0200 Subject: [PATCH] Address code review comments --- api/src/main/java/io/grpc/MethodDescriptor.java | 9 ++++----- api/src/test/java/io/grpc/MethodDescriptorTest.java | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/io/grpc/MethodDescriptor.java b/api/src/main/java/io/grpc/MethodDescriptor.java index a1712bbf949..500755de8e4 100644 --- a/api/src/main/java/io/grpc/MethodDescriptor.java +++ b/api/src/main/java/io/grpc/MethodDescriptor.java @@ -42,7 +42,6 @@ public final class MethodDescriptor { private final MethodType type; private final String fullMethodName; @Nullable private final String serviceName; - @Nullable private final String methodName; private final Marshaller requestMarshaller; private final Marshaller responseMarshaller; private final @Nullable Object schemaDescriptor; @@ -226,7 +225,6 @@ private MethodDescriptor( this.type = Preconditions.checkNotNull(type, "type"); this.fullMethodName = Preconditions.checkNotNull(fullMethodName, "fullMethodName"); this.serviceName = extractFullServiceName(fullMethodName); - this.methodName = extractMethodName(fullMethodName); this.requestMarshaller = Preconditions.checkNotNull(requestMarshaller, "requestMarshaller"); this.responseMarshaller = Preconditions.checkNotNull(responseMarshaller, "responseMarshaller"); this.schemaDescriptor = schemaDescriptor; @@ -271,8 +269,8 @@ public String getServiceName() { */ @Nullable @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635") - public String getMethodName() { - return methodName; + public String getBareMethodName() { + return extractBareMethodName(fullMethodName); } /** @@ -418,7 +416,8 @@ public static String extractFullServiceName(String fullMethodName) { * @since 1.32.0 */ @Nullable - public static String extractMethodName(String fullMethodName) { + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635") + public static String extractBareMethodName(String fullMethodName) { int index = checkNotNull(fullMethodName, "fullMethodName").lastIndexOf('/'); if (index == -1) { return null; diff --git a/api/src/test/java/io/grpc/MethodDescriptorTest.java b/api/src/test/java/io/grpc/MethodDescriptorTest.java index 4fdf10778f7..ec89976a016 100644 --- a/api/src/test/java/io/grpc/MethodDescriptorTest.java +++ b/api/src/test/java/io/grpc/MethodDescriptorTest.java @@ -178,36 +178,36 @@ public void getServiceName_returnsNull() { } @Test - public void getMethodName_extractsMethod() { + public void getBareMethodName_extractsMethod() { Marshaller marshaller = TestMethodDescriptors.voidMarshaller(); MethodDescriptor md = MethodDescriptor.newBuilder(marshaller, marshaller) .setType(MethodType.UNARY) .setFullMethodName("foo/bar") .build(); - assertEquals("bar", md.getMethodName()); + assertEquals("bar", md.getBareMethodName()); } @Test - public void getMethodName_returnsNull() { + public void getBareMethodName_returnsNull() { Marshaller marshaller = TestMethodDescriptors.voidMarshaller(); MethodDescriptor md = MethodDescriptor.newBuilder(marshaller, marshaller) .setType(MethodType.UNARY) .setFullMethodName("foo-bar") .build(); - assertNull(md.getMethodName()); + assertNull(md.getBareMethodName()); } @Test - public void getMethodName_returnsEmptyStringWithMethodMissing() { + public void getBareMethodName_returnsEmptyStringWithMethodMissing() { Marshaller marshaller = TestMethodDescriptors.voidMarshaller(); MethodDescriptor md = MethodDescriptor.newBuilder(marshaller, marshaller) .setType(MethodType.UNARY) .setFullMethodName("foo/") .build(); - assertTrue(md.getMethodName().isEmpty()); + assertTrue(md.getBareMethodName().isEmpty()); } @Test