OkHttpClient createClient(OkHttpClient client, Session session, HttpLoggingInterceptor loggingInterceptor) { return client.newBuilder() .authenticator(new RefreshAuthenticator(session.getAuthenticator())) .addInterceptor(new ApiInterceptor(session.getAuthenticator())) .addInterceptor(loggingInterceptor) .build(); }
OkHttpClient createClient(OkHttpClient client, Session session, HttpLoggingInterceptor loggingInterceptor) { return client.newBuilder() .authenticator(new RefreshAuthenticator(session.getAuthenticator())) .addInterceptor(new ApiInterceptor(session.getAuthenticator())) .addInterceptor(loggingInterceptor) .build(); }
Retrofit createRetrofit(OkHttpClient client, Session session) { Moshi moshi = new Moshi.Builder().add(new BigDecimalAdapter()).build(); return new Retrofit.Builder() .addConverterFactory(MoshiConverterFactory.create(moshi)) .baseUrl(session.getAuthenticator().getSessionConfiguration().getEndpointHost()) .client(client) .build(); } }
Retrofit createRetrofit(OkHttpClient client, Session session) { Moshi moshi = new Moshi.Builder().add(new BigDecimalAdapter()).build(); return new Retrofit.Builder() .addConverterFactory(MoshiConverterFactory.create(moshi)) .baseUrl(session.getAuthenticator().getSessionConfiguration().getEndpointHost()) .client(client) .build(); } }
@Test public void buildSession_containsMembersFromConstructor() throws Exception { Authenticator authenticator = mock(Authenticator.class); SessionConfiguration configuration = mock(SessionConfiguration.class); Session<Authenticator> session = new Session<Authenticator>(authenticator) { }; assertEquals(authenticator, session.getAuthenticator()); } }
@Before public void setup() { MockitoAnnotations.initMocks(this); when(session.getAuthenticator()).thenReturn(authenticator); when(authenticator.getSessionConfiguration()).thenReturn(config); when(config.getLocale()).thenReturn(Locale.US); when(config.getEndpointHost()).thenReturn("http://api.uber.com"); }