CpuServiceProxy extends ServiceProxy { @Override public ServerServiceDefinition getServiceDefinition() { Map<MethodDescriptor, ServerCallHandler> overrides = new HashMap<>(); overrides.put(CpuServiceGrpc.METHOD_START_PROFILING_APP, ServerCalls.asyncUnaryCall((request, observer) -> { startProfilingApp((CpuProfilingAppStartRequest)request, (StreamObserver)observer); })); overrides.put(CpuServiceGrpc.METHOD_STOP_PROFILING_APP, ServerCalls.asyncUnaryCall((request, observer) -> { stopProfilingApp((CpuProfilingAppStopRequest)request, (StreamObserver)observer); })); overrides.put(CpuServiceGrpc.METHOD_GET_TRACE_INFO, ServerCalls.asyncUnaryCall((request, observer) -> { getTraceInfo((GetTraceInfoRequest)request, (StreamObserver)observer); })); return generatePassThroughDefinitions(overrides, myServiceStub); } CpuServiceProxy(@NotNull IDevice device,
                         @NotNull ManagedChannel channel,
                         @NotNull LegacyCpuTraceProfiler legacyProfiler); @Override ServerServiceDefinition getServiceDefinition();  }
@Test public void testBindServiceContainsAllMethods() throws Exception { IDevice mockDevice = mock(IDevice.class); when(mockDevice.getSerialNumber()).thenReturn("Serial"); when(mockDevice.getName()).thenReturn("Device"); when(mockDevice.getVersion()).thenReturn(new AndroidVersion(1, "API")); when(mockDevice.isOnline()).thenReturn(true); when(mockDevice.getClients()).thenReturn(new Client[0]); ManagedChannel channel = InProcessChannelBuilder.forName("CpuServiceProxyTest").build(); CpuServiceProxy proxy = new CpuServiceProxy(mockDevice, channel, new FakeLegacyCpuTraceProfiler()); ServerServiceDefinition serverDefinition = proxy.getServiceDefinition(); Collection<MethodDescriptor<?, ?>> allMethods = CpuServiceGrpc.getServiceDescriptor().getMethods(); Set<MethodDescriptor<?, ?>> definedMethods = serverDefinition.getMethods().stream().map(method -> method.getMethodDescriptor()).collect(Collectors.toSet()); assertThat(definedMethods.size()).isEqualTo(allMethods.size()); definedMethods.containsAll(allMethods); }