diff --git a/core/src/test/java/io/grpc/ClientInterceptorsTest.java b/core/src/test/java/io/grpc/ClientInterceptorsTest.java index 980aa84949..3ce268b5cf 100644 --- a/core/src/test/java/io/grpc/ClientInterceptorsTest.java +++ b/core/src/test/java/io/grpc/ClientInterceptorsTest.java @@ -32,6 +32,7 @@ package io.grpc; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.mockito.Matchers.any; @@ -351,6 +352,34 @@ public class ClientInterceptorsTest { ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); verify(listener).onClose(captor.capture(), any(Metadata.class)); assertSame(error, captor.getValue().getCause()); + + // Make sure nothing bad happens after the exception. + ClientCall noop = ((CheckedForwardingClientCall)interceptedCall).delegate(); + // Should not throw, even on bad input + noop.cancel(); + noop.start(null, null); + noop.request(-1); + noop.halfClose(); + noop.sendMessage(null); + assertFalse(noop.isReady()); + verifyNoMoreInteractions(call); + } + + @Test + public void authorityIsDelegated() { + ClientInterceptor interceptor = new ClientInterceptor() { + @Override + public ClientCall interceptCall( + MethodDescriptor method, + CallOptions callOptions, + Channel next) { + return next.newCall(method, callOptions); + } + }; + + when(channel.authority()).thenReturn("auth"); + Channel intercepted = ClientInterceptors.intercept(channel, interceptor); + assertEquals("auth", intercepted.authority()); } private static class NoopInterceptor implements ClientInterceptor { @@ -360,5 +389,4 @@ public class ClientInterceptorsTest { return next.newCall(method, callOptions); } } - } diff --git a/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java b/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java index b8013a79da..8eb2964164 100644 --- a/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java +++ b/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java @@ -172,6 +172,11 @@ public class MutableHandlerRegistryImplTest { assertNull(registry.addService(multiServiceDefinition)); } + @Test + public void missingMethodLookupReturnsNull() { + assertNull(registry.lookupMethod("bad")); + } + @Test public void addAfterRemoveReturnsNull() { assertNull(registry.addService(basicServiceDefinition)); diff --git a/core/src/test/java/io/grpc/StatusTest.java b/core/src/test/java/io/grpc/StatusTest.java index 3cd40b5516..7189ced906 100644 --- a/core/src/test/java/io/grpc/StatusTest.java +++ b/core/src/test/java/io/grpc/StatusTest.java @@ -32,6 +32,9 @@ package io.grpc; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import io.grpc.Status.Code; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,4 +52,25 @@ public class StatusTest { assertEquals("CANCELLED: This is a test", Status.CANCELLED.withDescription("This is a test").asException().getMessage()); } + + @Test + public void impossibleCodeValue() { + assertEquals(Code.UNKNOWN, Status.fromCodeValue(-1).getCode()); + } + + @Test + public void sameCauseReturnsSelf() { + assertSame(Status.CANCELLED, Status.CANCELLED.withCause(null)); + } + + @Test + public void sameDescriptionReturnsSelf() { + assertSame(Status.CANCELLED, Status.CANCELLED.withDescription(null)); + assertSame(Status.CANCELLED, Status.CANCELLED.augmentDescription(null)); + } + + @Test + public void useObjectHashCode() { + assertEquals(Status.CANCELLED.hashCode(), System.identityHashCode(Status.CANCELLED)); + } }