|
31 | 31 | @RunWith(JUnit4.class) |
32 | 32 | public class GrpcServiceOptionsTest { |
33 | 33 |
|
34 | | - private static final TestGrpcServiceOptions OPTIONS = TestGrpcServiceOptions.builder() |
35 | | - .initialTimeout(1234) |
36 | | - .timeoutMultiplier(1.6) |
37 | | - .maxTimeout(5678) |
38 | | - .build(); |
39 | | - private static final TestGrpcServiceOptions DEFAULT_OPTIONS = |
40 | | - TestGrpcServiceOptions.builder().build(); |
41 | | - private static final TestGrpcServiceOptions OPTIONS_COPY = OPTIONS.toBuilder().build(); |
42 | | - |
43 | 34 | private interface TestService extends Service<TestGrpcServiceOptions> {} |
44 | 35 |
|
45 | 36 | private static class TestServiceImpl |
@@ -137,12 +128,20 @@ public int hashCode() { |
137 | 128 |
|
138 | 129 | @Test |
139 | 130 | public void testBuilder() { |
140 | | - assertEquals(1234, OPTIONS.initialTimeout()); |
141 | | - assertEquals(1.6, OPTIONS.timeoutMultiplier(), 0.0); |
142 | | - assertEquals(5678, OPTIONS.maxTimeout()); |
143 | | - assertEquals(20000, DEFAULT_OPTIONS.initialTimeout()); |
144 | | - assertEquals(1.5, DEFAULT_OPTIONS.timeoutMultiplier(), 0.0); |
145 | | - assertEquals(100000, DEFAULT_OPTIONS.maxTimeout()); |
| 131 | + TestGrpcServiceOptions options = TestGrpcServiceOptions.builder() |
| 132 | + .initialTimeout(1234) |
| 133 | + .timeoutMultiplier(1.6) |
| 134 | + .maxTimeout(5678) |
| 135 | + .build(); |
| 136 | + TestGrpcServiceOptions defaultOptions = |
| 137 | + TestGrpcServiceOptions.builder().build(); |
| 138 | + TestGrpcServiceOptions optionsCopy = options.toBuilder().build(); |
| 139 | + assertEquals(1234, options.initialTimeout()); |
| 140 | + assertEquals(1.6, options.timeoutMultiplier(), 0.0); |
| 141 | + assertEquals(5678, options.maxTimeout()); |
| 142 | + assertEquals(20000, defaultOptions.initialTimeout()); |
| 143 | + assertEquals(1.5, defaultOptions.timeoutMultiplier(), 0.0); |
| 144 | + assertEquals(100000, defaultOptions.maxTimeout()); |
146 | 145 | } |
147 | 146 |
|
148 | 147 | @Test |
@@ -181,13 +180,33 @@ public void testBuilderInvalidMaxTimeout() { |
181 | 180 |
|
182 | 181 | @Test |
183 | 182 | public void testBaseEquals() { |
184 | | - assertEquals(OPTIONS, OPTIONS_COPY); |
185 | | - assertNotEquals(DEFAULT_OPTIONS, OPTIONS); |
| 183 | + try { |
| 184 | + TestGrpcServiceOptions options = TestGrpcServiceOptions.builder() |
| 185 | + .initialTimeout(1234) |
| 186 | + .timeoutMultiplier(1.6) |
| 187 | + .maxTimeout(5678) |
| 188 | + .build(); |
| 189 | + TestGrpcServiceOptions defaultOptions = |
| 190 | + TestGrpcServiceOptions.builder().build(); |
| 191 | + TestGrpcServiceOptions optionsCopy = options.toBuilder().build(); |
| 192 | + assertEquals(options, optionsCopy); |
| 193 | + assertNotEquals(defaultOptions, options); |
| 194 | + } catch (Exception ex) { |
| 195 | + ex.printStackTrace(); |
| 196 | + } |
186 | 197 | } |
187 | 198 |
|
188 | 199 | @Test |
189 | 200 | public void testBaseHashCode() { |
190 | | - assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); |
191 | | - assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); |
| 201 | + TestGrpcServiceOptions options = TestGrpcServiceOptions.builder() |
| 202 | + .initialTimeout(1234) |
| 203 | + .timeoutMultiplier(1.6) |
| 204 | + .maxTimeout(5678) |
| 205 | + .build(); |
| 206 | + TestGrpcServiceOptions defaultOptions = |
| 207 | + TestGrpcServiceOptions.builder().build(); |
| 208 | + TestGrpcServiceOptions optionsCopy = options.toBuilder().build(); |
| 209 | + assertEquals(options.hashCode(), optionsCopy.hashCode()); |
| 210 | + assertNotEquals(defaultOptions.hashCode(), options.hashCode()); |
192 | 211 | } |
193 | 212 | } |
0 commit comments