UberRidesApi { @Nonnull public static Builder with(@Nonnull Session session) { return new Builder(session); } private  UberRidesApi(@Nonnull Retrofit retrofit); @Nonnull static Builder with(@Nonnull Session session); RidesService createService();  }
@Test public void createLoggingInterceptor_containsLogLevel() { HttpLoggingInterceptor loggingInterceptor = UberRidesApi.with(session) .createLoggingInterceptor(HttpLoggingInterceptor.Logger.DEFAULT, HttpLoggingInterceptor.Level.BASIC); assertEquals(HttpLoggingInterceptor.Level.BASIC, loggingInterceptor.getLevel()); assertEquals(HttpLoggingInterceptor.Level.BASIC, loggingInterceptor.getLevel()); }
@Test public void createClient_setsSessionAndLoggingInterceptor() { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); OkHttpClient client = UberRidesApi.with(session) .createClient(new OkHttpClient(), session, loggingInterceptor); assertEquals(authenticator, ((RefreshAuthenticator) client.authenticator()).authenticator); for (Interceptor interceptor : client.interceptors()) { if (interceptor instanceof ApiInterceptor) { assertEquals(authenticator, ((ApiInterceptor)interceptor).authenticator); } else if (interceptor instanceof HttpLoggingInterceptor){ assertEquals(loggingInterceptor, interceptor); } else { fail("Interceptors did not match expected ones"); } } }
@Test public void setOkHttpClient_isSetAndCallsNewBuilderDuringConstruction() throws Exception { OkHttpClient client = mock(OkHttpClient.class); when(client.newBuilder()).thenReturn(new OkHttpClient.Builder()); UberRidesApi.Builder builder = UberRidesApi.with(session).setOkHttpClient(client); builder.build(); verify(client).newBuilder(); assertEquals(client, builder.client); }
@Test public void setOkHttpClient_whenNull_returnsNewClient() { UberRidesApi.Builder builder = UberRidesApi.with(session); builder.build(); assertNotNull(builder.client); }
@Test public void setLogger_isSetAfterBuild() { HttpLoggingInterceptor.Logger logger = HttpLoggingInterceptor.Logger.DEFAULT; UberRidesApi.Builder builder = UberRidesApi.with(session).setLogger(logger); builder.build(); assertEquals(logger, builder.logger); }
@Test public void setLogger_whenNull_returnsDefaultLogger() { UberRidesApi.Builder builder = UberRidesApi.with(session); builder.build(); assertEquals(HttpLoggingInterceptor.Logger.DEFAULT, builder.logger); }
@Test public void setLogLevel_isSetAfterBuild() { HttpLoggingInterceptor.Level level= HttpLoggingInterceptor.Level.BASIC; UberRidesApi.Builder builder = UberRidesApi.with(session).setLogLevel(level); builder.build(); assertEquals(level, builder.logLevel); }
@Test public void setLogLevel_whenNull_returnsNoLogging() { UberRidesApi.Builder builder = UberRidesApi.with(session); builder.build(); assertEquals(HttpLoggingInterceptor.Level.NONE, builder.logLevel); }
@Test public void build_withOnlySession_completesSuccesfully() throws Exception { assertNotNull(UberRidesApi.with(session).build()); }