1818
1919import static org .junit .Assert .assertEquals ;
2020import static org .junit .Assert .assertNotEquals ;
21+ import static org .junit .Assert .assertSame ;
2122import static org .junit .Assert .assertTrue ;
2223import static org .junit .Assert .fail ;
2324
@@ -76,9 +77,11 @@ public class ServiceOptionsTest {
7677 }
7778 private static final HttpTransportFactory MOCK_HTTP_TRANSPORT_FACTORY =
7879 EasyMock .createMock (HttpTransportFactory .class );
80+ private static final Clock TEST_CLOCK = new TestClock ();
7981 private static final TestServiceOptions OPTIONS =
8082 TestServiceOptions .builder ()
8183 .authCredentials (authCredentials )
84+ .clock (TEST_CLOCK )
8285 .connectTimeout (1234 )
8386 .host ("host" )
8487 .httpTransportFactory (MOCK_HTTP_TRANSPORT_FACTORY )
@@ -90,18 +93,25 @@ public class ServiceOptionsTest {
9093 TestServiceOptions .builder ().projectId ("project-id" ).build ();
9194 private static final TestServiceOptions OPTIONS_COPY = OPTIONS .toBuilder ().build ();
9295
93- interface TestService extends Service <TestServiceOptions > {}
96+ private static class TestClock extends Clock {
97+ @ Override
98+ public long millis () {
99+ return 123456789L ;
100+ }
101+ }
94102
95- static class TestServiceImpl
103+ private interface TestService extends Service <TestServiceOptions > {}
104+
105+ private static class TestServiceImpl
96106 extends BaseService <TestServiceOptions > implements TestService {
97- TestServiceImpl (TestServiceOptions options ) {
107+ private TestServiceImpl (TestServiceOptions options ) {
98108 super (options );
99109 }
100110 }
101111
102- interface TestServiceFactory extends ServiceFactory <TestService , TestServiceOptions > {}
112+ private interface TestServiceFactory extends ServiceFactory <TestService , TestServiceOptions > {}
103113
104- static class DefaultTestServiceFactory implements TestServiceFactory {
114+ private static class DefaultTestServiceFactory implements TestServiceFactory {
105115 private static final TestServiceFactory INSTANCE = new DefaultTestServiceFactory ();
106116
107117 @ Override
@@ -110,10 +120,10 @@ public TestService create(TestServiceOptions options) {
110120 }
111121 }
112122
113- interface TestServiceRpcFactory
123+ private interface TestServiceRpcFactory
114124 extends ServiceRpcFactory <TestServiceRpc , TestServiceOptions > {}
115125
116- static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory {
126+ private static class DefaultTestServiceRpcFactory implements TestServiceRpcFactory {
117127 private static final TestServiceRpcFactory INSTANCE = new DefaultTestServiceRpcFactory ();
118128
119129 @ Override
@@ -122,14 +132,15 @@ public TestServiceRpc create(TestServiceOptions options) {
122132 }
123133 }
124134
125- interface TestServiceRpc {}
135+ private interface TestServiceRpc {}
126136
127- static class DefaultTestServiceRpc implements TestServiceRpc {
137+ private static class DefaultTestServiceRpc implements TestServiceRpc {
128138 DefaultTestServiceRpc (TestServiceOptions options ) {}
129139 }
130140
131- static class TestServiceOptions extends ServiceOptions <TestService , TestServiceRpc , TestServiceOptions > {
132- static class Builder
141+ private static class TestServiceOptions
142+ extends ServiceOptions <TestService , TestServiceRpc , TestServiceOptions > {
143+ private static class Builder
133144 extends ServiceOptions .Builder <TestService , TestServiceRpc , TestServiceOptions , Builder > {
134145 private Builder () {}
135146
@@ -143,14 +154,10 @@ protected TestServiceOptions build() {
143154 }
144155 }
145156
146- protected TestServiceOptions (Builder builder ) {
157+ private TestServiceOptions (Builder builder ) {
147158 super (TestServiceFactory .class , TestServiceRpcFactory .class , builder );
148159 }
149160
150- public static TestServiceOptions defaultInstance () {
151- return builder ().build ();
152- }
153-
154161 @ Override
155162 protected TestServiceFactory defaultServiceFactory () {
156163 return DefaultTestServiceFactory .INSTANCE ;
@@ -171,7 +178,7 @@ public Builder toBuilder() {
171178 return new Builder (this );
172179 }
173180
174- public static Builder builder () {
181+ private static Builder builder () {
175182 return new Builder ();
176183 }
177184
@@ -188,21 +195,21 @@ public int hashCode() {
188195
189196 @ Test
190197 public void testBuilder () {
191- assertEquals (authCredentials , OPTIONS .authCredentials ());
192- assertEquals ( Clock . defaultClock () , OPTIONS .clock ());
198+ assertSame (authCredentials , OPTIONS .authCredentials ());
199+ assertSame ( TEST_CLOCK , OPTIONS .clock ());
193200 assertEquals (1234 , OPTIONS .connectTimeout ());
194201 assertEquals ("host" , OPTIONS .host ());
195- assertEquals (MOCK_HTTP_TRANSPORT_FACTORY , OPTIONS .httpTransportFactory ());
202+ assertSame (MOCK_HTTP_TRANSPORT_FACTORY , OPTIONS .httpTransportFactory ());
196203 assertEquals ("project-id" , OPTIONS .projectId ());
197204 assertEquals (5678 , OPTIONS .readTimeout ());
198- assertEquals (RetryParams .noRetries (), OPTIONS .retryParams ());
205+ assertSame (RetryParams .noRetries (), OPTIONS .retryParams ());
199206
200- assertEquals (Clock .defaultClock (), DEFAULT_OPTIONS .clock ());
207+ assertSame (Clock .defaultClock (), DEFAULT_OPTIONS .clock ());
201208 assertEquals (-1 , DEFAULT_OPTIONS .connectTimeout ());
202209 assertEquals ("https://www.googleapis.com" , DEFAULT_OPTIONS .host ());
203210 assertTrue (DEFAULT_OPTIONS .httpTransportFactory () instanceof DefaultHttpTransportFactory );
204211 assertEquals (-1 , DEFAULT_OPTIONS .readTimeout ());
205- assertEquals (RetryParams .defaultInstance (), DEFAULT_OPTIONS .retryParams ());
212+ assertSame (RetryParams .defaultInstance (), DEFAULT_OPTIONS .retryParams ());
206213 }
207214
208215 @ Test
0 commit comments