• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc.stub;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import io.grpc.CallOptions;
22 import io.grpc.Channel;
23 import io.grpc.stub.AbstractStub.StubFactory;
24 import io.grpc.stub.AbstractStubTest.NoopStub;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 
29 @RunWith(JUnit4.class)
30 public class AbstractStubTest extends BaseAbstractStubTest<NoopStub> {
31 
32   @Override
create(Channel channel, CallOptions callOptions)33   NoopStub create(Channel channel, CallOptions callOptions) {
34     return new NoopStub(channel, callOptions);
35   }
36 
37   @Test
defaultCallOptions()38   public void defaultCallOptions() {
39     NoopStub stub = NoopStub.newStub(new StubFactory<NoopStub>() {
40       @Override
41       public NoopStub newStub(Channel channel, CallOptions callOptions) {
42         return create(channel, callOptions);
43       }
44     }, channel, CallOptions.DEFAULT);
45 
46     assertThat(stub.getCallOptions().getOption(ClientCalls.STUB_TYPE_OPTION))
47         .isNull();
48   }
49 
50   class NoopStub extends AbstractStub<NoopStub> {
51 
NoopStub(Channel channel, CallOptions options)52     NoopStub(Channel channel, CallOptions options) {
53       super(channel, options);
54     }
55 
56     @Override
build(Channel channel, CallOptions callOptions)57     protected NoopStub build(Channel channel, CallOptions callOptions) {
58       return new NoopStub(channel, callOptions);
59     }
60   }
61 }
62 
63