Unit tests for CallOptions.
| 40 | |
| 41 | /** Unit tests for {@link CallOptions}. */ |
| 42 | @RunWith(JUnit4.class) |
| 43 | public class CallOptionsTest { |
| 44 | private static final CallOptions.Key<String> OPTION_1 |
| 45 | = CallOptions.Key.createWithDefault("option1", "default"); |
| 46 | private static final CallOptions.Key<String> OPTION_2 |
| 47 | = CallOptions.Key.createWithDefault("option2", "default"); |
| 48 | private final String sampleAuthority = "authority"; |
| 49 | private final String sampleCompressor = "compressor"; |
| 50 | private final Deadline.Ticker ticker = new FakeTicker(); |
| 51 | private final Deadline sampleDeadline = Deadline.after(1, NANOSECONDS, ticker); |
| 52 | private final CallCredentials sampleCreds = mock(CallCredentials.class); |
| 53 | private final ClientStreamTracer.Factory tracerFactory1 = new FakeTracerFactory("tracerFactory1"); |
| 54 | private final ClientStreamTracer.Factory tracerFactory2 = new FakeTracerFactory("tracerFactory2"); |
| 55 | private final CallOptions allSet = CallOptions.DEFAULT |
| 56 | .withAuthority(sampleAuthority) |
| 57 | .withDeadline(sampleDeadline) |
| 58 | .withCallCredentials(sampleCreds) |
| 59 | .withCompression(sampleCompressor) |
| 60 | .withWaitForReady() |
| 61 | .withExecutor(directExecutor()) |
| 62 | .withOption(OPTION_1, "value1") |
| 63 | .withStreamTracerFactory(tracerFactory1) |
| 64 | .withOption(OPTION_2, "value2") |
| 65 | .withStreamTracerFactory(tracerFactory2); |
| 66 | |
| 67 | @Test |
| 68 | public void defaultsAreAllNull() { |
| 69 | assertThat(CallOptions.DEFAULT.getDeadline()).isNull(); |
| 70 | assertThat(CallOptions.DEFAULT.getAuthority()).isNull(); |
| 71 | assertThat(CallOptions.DEFAULT.getExecutor()).isNull(); |
| 72 | assertThat(CallOptions.DEFAULT.getCredentials()).isNull(); |
| 73 | assertThat(CallOptions.DEFAULT.getCompressor()).isNull(); |
| 74 | assertThat(CallOptions.DEFAULT.isWaitForReady()).isFalse(); |
| 75 | assertThat(CallOptions.DEFAULT.getStreamTracerFactories()).isEmpty(); |
| 76 | } |
| 77 | |
| 78 | @Test |
| 79 | public void withAndWithoutWaitForReady() { |
| 80 | assertThat(CallOptions.DEFAULT.withWaitForReady().isWaitForReady()).isTrue(); |
| 81 | assertThat(CallOptions.DEFAULT.withWaitForReady().withoutWaitForReady().isWaitForReady()) |
| 82 | .isFalse(); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void withOnReadyThreshold() { |
| 87 | int onReadyThreshold = 1024; |
| 88 | CallOptions callOptions = CallOptions.DEFAULT.withOnReadyThreshold(onReadyThreshold); |
| 89 | callOptions = callOptions.withWaitForReady(); |
| 90 | assertThat(callOptions.getOnReadyThreshold()).isEqualTo(onReadyThreshold); |
| 91 | callOptions = callOptions.clearOnReadyThreshold(); |
| 92 | assertThat(callOptions.getOnReadyThreshold()).isNull(); |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void allWiths() { |
| 97 | assertThat(allSet.getAuthority()).isSameInstanceAs(sampleAuthority); |
| 98 | assertThat(allSet.getDeadline()).isSameInstanceAs(sampleDeadline); |
| 99 | assertThat(allSet.getCredentials()).isSameInstanceAs(sampleCreds); |
nothing calls this directly
no test coverage detected