mirror of https://github.com/grpc/grpc-java.git
Cover more low hanging fruit
This commit is contained in:
parent
80eb60080d
commit
ce93051aad
|
|
@ -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<Status> 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 <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
|
||||
MethodDescriptor<ReqT, RespT> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue