• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Mockito.mock;
21 
22 import io.grpc.InternalConfigSelector.Result;
23 import io.grpc.Status.Code;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.JUnit4;
27 
28 /** Tests for {@link InternalConfigSelector}. */
29 @RunWith(JUnit4.class)
30 public class InternalConfigSelectorTest {
31   @Test
resultBuilder()32   public void resultBuilder() {
33     Object config = "fake_config";
34     InternalConfigSelector.Result.Builder builder = InternalConfigSelector.Result.newBuilder();
35     ClientInterceptor interceptor = mock(ClientInterceptor.class);
36     InternalConfigSelector.Result result =
37         builder.setConfig(config).setInterceptor(interceptor).build();
38     assertThat(result.getStatus().isOk()).isTrue();
39     assertThat(result.getConfig()).isEqualTo(config);
40     assertThat(result.getInterceptor()).isSameInstanceAs(interceptor);
41   }
42 
43   @Test
errorResult()44   public void errorResult() {
45     Result result = Result.forError(Status.INTERNAL.withDescription("failed"));
46     assertThat(result.getStatus().isOk()).isFalse();
47     assertThat(result.getStatus().getCode()).isEqualTo(Code.INTERNAL);
48     assertThat(result.getStatus().getDescription()).isEqualTo("failed");
49   }
50 }
51